defo-contract

所属分类:区块链开发
开发工具:Solidity
文件大小:5472KB
下载次数:0
上传日期:2023-04-04 02:53:17
上 传 者sh-1993
说明:  德福智能合约
(DeFo Smart Contract)

文件列表:
.commitlintrc.yml (47, 2023-04-04)
.czrc (42, 2023-04-04)
.deps (0, 2023-04-04)
.deps\remix-tests (0, 2023-04-04)
.deps\remix-tests\remix_accounts.sol (1253, 2023-04-04)
.deps\remix-tests\remix_tests.sol (7667, 2023-04-04)
.editorconfig (254, 2023-04-04)
.env.example (2865, 2023-04-04)
.eslintignore (261, 2023-04-04)
.eslintrc.yml (601, 2023-04-04)
.husky (0, 2023-04-04)
.husky\commit-msg (72, 2023-04-04)
.husky\pre-commit (63, 2023-04-04)
.lintstagedrc (96, 2023-04-04)
.prettierignore (262, 2023-04-04)
.prettierrc.yml (333, 2023-04-04)
.solcover.js (139, 2023-04-04)
.solhint.json (515, 2023-04-04)
.solhintignore (43, 2023-04-04)
.yarnrc.yml (25, 2023-04-04)
LICENSE (35141, 2023-04-04)
abi (0, 2023-04-04)
abi\dai-abi.json (6433, 2023-04-04)
abi\defo-abi.json (8442, 2023-04-04)
abi\erc20-abi.json (6371, 2023-04-04)
abi\joe-factory.json (3894, 2023-04-04)
abi\joe-pair.json (12104, 2023-04-04)
abi\joe-router.json (19626, 2023-04-04)
config (0, 2023-04-04)
config\contracts.config.ts (6287, 2023-04-04)
constants (0, 2023-04-04)
constants\addresses.ts (3300, 2023-04-04)
constants\constants.ts (94, 2023-04-04)
... ...

[![Compile & Test Pass](https://github.com/defoundationxyz/defo-contract/actions/workflows/test.yml/badge.svg)](https://github.com/defoundationxyz/defo-contract/actions/workflows/test.yml) # DEFO smart contracts [DEFO](https://docs.defo.app/) is a DeFi protocol on AVAX. If you buy a Yield Gem NFT with our DEFO token, you get DEFO rewards every week. ## Preparation Copy `.env.example` to `.env`. ```shell $ yarn install ``` ## Testing To run unit & integration tests: ```shell $ yarn test ``` To run the coverage: ```shell $ yarn coverage ``` Note to compile the contracts and build the types with `yarn typechain` prior to that if you're running coverage as the first command after installation. ## Deployment We use [Hardhat](https://hardhat.dev) and [hardhat-deploy](https://github.com/wighawag/hardhat-deploy). In one terminal window build the contracts, spin-up a HardHat EVM forking the Avalanche mainnet, and deploy the contracts to it: ```shell yarn start-fork ``` Deployment (or upgrading) the contracts are done with ```shell yarn deploy NETWORK #NETWORK is localhost, fuji or mainnet ``` Scripts in [/deploy](./deploy) as well as the handy scripts below work with any network managed by the hardhat and hardhat-deploy. ## E2E Scenario While your HardHat EVM is running, in other terminal window permit DAI and DEFO, mint a gem, wait some time to generate yield, and put the generated yield into the vault with: ```shell yarn dev ``` ## Contracts The contract is built as an EIP-2535 Diamond, implementing ERC-721 functionality covering Yield Gem NFTs. DEFO Token is a separate ERC-20 token. ### Addresses #### Avalanche Mainnet | Contract | Address | |------------------------------------------------|----------------------------------------------| | DEFO Token ERC-20 | [0xbb6ffeCE837a525A2eAE033ff0161a7CDC60B693](https://snowtrace.io/address/0xbb6ffeCE837a525A2eAE033ff0161a7CDC60B693) | | DEFO Protocol Main Contract ERC-721 compatible | [0xa47f856CD11513DB4E723c03990292f6c2FAC6b7](https://snowtrace.io/address/0xa47f856CD11513DB4E723c03990292f6c2FAC6b7) | #### Avalanche Fuji Testnet | Contract | Address | |------------------------------------------------|----------------------------------------------| | DEFO Token ERC-20 | [0xA9D3adb2B5c7d89c56d74584E***ABcea1E4e6a4D](https://testnet.snowtrace.io/address/0xA9D3adb2B5c7d89c56d74584E***ABcea1E4e6a4D) | | DEFO Protocol Main Contract ERC-721 compatible | [0xf0d26dD82f6beE7***cB677ee17E5466d009193Eb](https://testnet.snowtrace.io/address/0xf0d26dD82f6beE7***cB677ee17E5466d009193Eb) | DAI for fuji is a customly deployed contract from the real Dai code but mintable by anyone for test purposes. the address is [0x3362FE2f7E17A5a9F90DaBE12E4A6E16E146F19a](https://testnet.snowtrace.io/address/0x3362FE2f7E17A5a9F90DaBE12E4A6E16E146F19a#writeContract) add it to the injected wallet along with the DEFO Token to test with the DApp. To get some DAI just select *Write Contract* tab, connect your wallet to the snowtrace, and fill in section *4.mint* with your address and amount (remember to add 18 zeroes), then press Write, voil! DEX router address is [0xd7f655E3376cE2D7A2b08fF01Eb3B1023191A901](https://testnet.snowtrace.io/address/0xd7f655E3376cE2D7A2b08fF01Eb3B1023191A901#writeContract) .
DAI-DEFO liquidity pair is created at [0x27aa1a537313396ACc8b3c594a8441ae073d8750](https://testnet.snowtrace.io/address/0x27aa1a537313396ACc8b3c594a8441ae073d8750) ### Testing on Avalanche FUJI #### Configuration The configuration on Fuji is different from those on mainnet. Here are the main differences: - Reward period is one hour (vs one week). - Maintenance period is two days (vs one month). - Mint limit window is 10 minutes (vs 12 hours). - Tax scale change speed is 2 days (vs one week). - Tax rates table is 30% (for the first 2 days), then 20%, 15%, 10%, 0%. ## Handy Hardhat Tasks To play around with the smart contracts, there is a bunch of handy scripts. They cover complete protocol functionality from the command line. To use them on the local network run `yarn start-fork` in a separate terminal at first. Running these tasks on live networks is also possible. These tasks rely on `hardhat deploy`, so the deployment to the desired network is necessary to interact with the contracts from the command line. The scripts support live deployments which are part of the './deployments` folder. Most of the scripts require network name. If `NETWORK` is specified, it's mandatory and should be substitued by `localhost`, `fuji` or `mainnet`. Also be sure to set `LIVENET_MNEMONIC` in the `.env` file for fuji or mainnet is he account executing the below tasks. E.g. `yarn accounts fuji` displays contract wallets on fuji. `--help` shows parameters. Parameters (including `--help`) should be specified after the network, e.g. `yarn gems fuji --type 1` ### Deployments Deployments which are the prerequisite to use all the below tasks. ```shell yarn deployments NETWORK #display deployments with addresses ``` ### Accounts View function, doesn't change the state. ```shell yarn accounts NETWORK # AVAX, DAI, DEFO balances of all the named accounts, and liquidity pair info ``` ### Config View or change configuration function (if authorized). ```shell yarn conf NETWORK # view config, if parameters specified changes it if authorized OPTIONS: --maintenance-period maintenance period in a human-readable format without spaces: '1w', '1day', '20h', etc. --reward-period reward period in a human-readable format without spaces: '1w', '1day', '20h', etc. --tax-scale-period taxScale update since last claim period in a human-readable format without spaces: '1w', '1day', '20h', etc. --vault-withdrawal-tax vault withdrawal tax rate multiplied by 100, e.g. 1000 for 10% --wallets set all protocol wallets, note, all 6 should be provided comma separated with no spaces, e.g. 0x001,0x002,0x003,0x004,0x005,0x006 ``` ### Liquidity Without params provides info on the configured DEX liquidity pair, if parameters are specified funds the pair from the default wallet which is `LIVENET_MNEMONIC` in the `.env` file, or `deployer` for localhost: ```shell yarn liquidity NETWORK # funds DAI-DEFO liquidity pair OPTIONS: --dai DAI to add to the pool --defo DEFO to add to the pool ``` ### Swap Swaps DAI - DEFO with the DEX liquidity pair. ```shell yarn swap NETWORK OPTIONS OPTIONS: --dai DAI amount to swap to DEFO --defo DEFO amount to swap to DAI swap: swaps DAI to DEFO and vice versa, specify FROM token only ``` ### Gems View function, doesn't change the state. Basically the most important view function providing core protocol gems state information and user information. ```shell yarn gems NETWORK # gems configuration, and balances of the NFTs for the deployer OPTIONS: --type 0 - sapphire, 1 - ruby, 2 - diamond, empty (-1) - get info for all three (default: -1) ``` ### Test funding with ERC-20 DEFO and DAI Obviously doesn't work for the mainnet. Suitable for `localhost` and `fuji` only. ```shell yarn get-some-dai NETWORK # optional with account and amount, e.g. --account all --amount 10000 yarn get-some-defo NETWORK # mints DEFO ERC20 token, optional with account and amount, e.g. --account all --amount 10000 OPTIONS FOR BOTH COMMANDS: --account The account name to get DAI, e.g. 'treasury', 'vault', or 'all' (default: "deployer") --amount The amount to transfer to the deployer (default: 100000) ``` ### Permit ```shell yarn permit NETWORK #Permits spending DAI and DEFO on behalf of the contract. ``` ### Mint Gems Don't forget to get DAI, DEFO, and give `permit` before minting. ```shell yarn get-some-gems NETWORK # mints all 3 gems, optional with gem type (0,1,2), e.g. --type 0 OPTIONS: --amount number of gems to be minted (default: 1) --type 0 - sapphire, 1 - ruby, 2 - diamond, empty (-1) - mint all three (default: -1) ``` ### Claim Claim the earned reward in DEFO to the wallet. ```shell yarn claim NETWORK # claim all claimable gems rewards, optional with gem id --id OPTIONS: --id gem id to claim rewards for a specific gemId (default: -1) --type claim for all gems of given type 0 - sapphire, 1 - ruby, 2 - diamond, all gems if empty (default: -1) ``` ### Vault Views vault state if no params, or stakes/unstakes. ```shell yarn vault NETWORK # showing vault stats without changes, puts to vault with params --id --amount OPTIONS: --amount amount of pending unclaimed rewards to stake or the amount currently in the vault to unstake --id gem id to stake or unstake --op operation: 'view', 'stake' or 'unstake' (default: "view") ``` ### Jump in Time This works only for testing on `localhost` hardhat network, just gives an opportunity to move back and forth in time to check reward generation, maintenance fee accrual, and other time-dependand functionality. ```shell yarn jump-in-time # optional with human-readable time without spaces, e.g. --time 7d ``` ### Query This is used to get the list of the protocol users with vault contents ```shell yarn query NETWORK ``` Check out [package.json](./package.json) and [./tasks](./tasks) for more. ## Cash flow ```mermaid graph TD; L((Liquidity Pair)) --Buy
DEFO --> User(User) User -- Sell
DAI --> L User -- Mint
25% DAI --> L User -- Mint
75% DAI --> T((Treasury)) User -- Mint
25% DEFO --> L User -- Mint
75% DEFO --> R((Rewards Pool)) R -- Claim
DEFO Reward - charity - tax --> User R -- Claim
DEFO charity --> C((Charity)) R -- Claim
DEFO tax --> R R -- Stake
DEFO Amount - charity --> V((Vault)) R -- Stake
DEFO charity --> C V -- Unstake
DEFO staked - vault tax --> R ``` ## Links - Checkout DeFo website: [https://defo.app/](https://defo.app/) - The Whitepaper: [https://defo.app/whitepaper.pdf](https://defo.app/whitepaper.pdf) - Feel free to join [Discord](discord.gg/defo).

近期下载者

相关文件


收藏者