Inspiration
People do realize that DeFi(decentralized finance) is the future of blockchain this year, especially after the rapid and bloody collapse of FTX.
As the most important part of DeFi, DEX(decentralized exchange) allows any two parties to trade crypto without relying on a 3rd party. But there is still a question of where the liquidity comes from and why people are willing to provide it.
Many protocols try to solve this problem by giving liquidity providers governance tokens to incentive them. But the continued selling pressure left people no motivation to hold these mined tokens, which brings token price dumping, incentive decline, and finally, liquidity has gone.
To solve this problem, the VE (vote escrowed) token model was created. It allows liquidity providers to lock governance tokens and therefore have the power to vote on which liquidity pool to boost. In this way, people will buy tokens to get a higher return, thus this enhances the robustness of the liquidity of the protocol tokens.
So back to the near ecosystem, Ref finance is the largest dex on NEAR. In Q4, users can lock REF-NEAR LP for up to one year to boost yields and receive corresponding voting powers.
The original ve model does not allow buying or selling locking tokens when you already lock them, Ref finance introduces fungible tokens–refLOVE(received by stake your REF-NEAR LP) to improve capital efficiency, allowing lockers to boost their farming while also having the power to exit liquidity anytime.
However, there are still two questions.
First, the boost effect and voting power from the locked NEAR-REF lp decrease over time, which requires people to repeat stakes to maintain high yields.
And second, this ve mechanism is more favorable to whales than small ones, as they have more LPs to stake to boost.
Perf finance comes out to solve these two problems.
What it does
- It is the first permissionless ve model yield aggregator built on NEAR.
- Providing better accessibility and higher returns compared to locking on the native protocol.
- By allocating all users' deposited NEAR-REF LP and re-locks them perpetually on ref finance.
- Giving back user 1:1 fungible token perREF allow people to exit liquidity at any time.
- Let farmers gain aggregate boost on ref farm.
- REF-NEAR LP staker, PERF (our protocol token) staker, and locker can earn a (different) share of rewards from the ref farm.
- Permissionless DAO tasks allow anyone to harvest from the underlying protocol rewards, transfer rewards to Perf farm, and earn a small portion of the reward from doing this.
- Stake whitelist NFT can boost whitelist farm on top of boost from the aggregator. (smart-contract fully supported, still test in frontend)
Convert REF-NEAR LP and Zap stake transaction example :near explorer
How we built it
Smart Contract
Perf Finance consists of 3 contracts: Perf Proxy, Perf Farm, and Perf Token.
Perf Proxy
The core contract, the proxy between ref-farm, ref-ve, and perf-farm, handles the lock of REF-NEAR LP, the stake of farmable LP, and perREF.
Aggregate lock. Perf proxy contract receives any user deposit ref-near lp and locks them into the ref ve contract with the max time-lock, then stakes the refLOVE token received from the ref ve contract to ref farm contract to gain maximum boost.
- Perf proxy uses chains of cross-contract calls to handle the state of different protocol contracts and users, how to revoke failed cross-contract calls, and the next step of successful cross-contract calls. With near-sdk-rs 4.0.0, it's easy to deal with the cross-contract call, and gas for the cross-contract callback.
Aggregate stake. Perf proxy contract receives any user deposit farmable lp and stakes them into the ref farm contract, mint perTOKEN as proof of user's stake, and stake them into perf farm to gain rewards and max boost based on the refLOVE the proxy contract owned.
- Using storage trackers from burrow, our contract easily handles the check and write of storage cost.
- Implement MFT (multi-fungible-token) inspired by ref-contracts, to create a proof of user stake or lock ref lp.
Dao Task. Any user calls a public function to claim and withdraw rewards belonging to the proxy contract from the ref farm. Proxy contract splits the rewards depending on the preset portion and sends them into perf farm. This increase the robustness and decentralization.
- Using big decimals form burrow, secure the split reward to different farms or multiply for the boost, preventing overflow.
- Using
HashSet< AccountId >to prevent attack from withdrawing the same token at the same time.
Perf Farm
Users can stake perTOKEN to earn rewards and NFT/FT seed to boost yields. Inspired by ref boost farm, we add extra logic on top of it.
Delegate stake. Allowing one account to stake FT/LP for another account, in this case, the user can send ref LP to perf proxy contact and has nothing to do left. The proxy contract sends users' ref LP to ref farm, delegate stake perf MFT to perf farm, and now the user earns rewards automatically. This reduces transaction amount and gas fee for the user.
Reward for multiple farms. By customizing the
ft transfer callmsg, the reward can be sent to different internal farms with a different ratio in one transaction, this is useful when dealing with DAO harvest rewards, the ratio of reward is decided by the smart contract and with one transaction, the harvester can send one token to different internal farms.NFT boost seed. By staking whitelist NFTs, users can gain a boost from whitelist perf farm on the top of global aggregate boost. This is useful if ref fiance creates a boost farm about an NFT project governance token, perf can whitelist the corresponding NFT, and let the NFT holder gain an extra boost in this NFT-related farm.
Perf token
The protocol token. Using NEP-141 with near contract standard 4.0.0.
Challenges we ran into
- Run out of gas (300Tgas).
- Revoke complex cross-contract calls.
- Write full tests in the workspace, and handle execution results.
- Construct a local net.
- Integrate smart contracts with the front-end.
Accomplishments that we're proud of
First permissionless ve model yield aggregator built on NEAR
What we learned
- Develop and publish an app on near-protocol.
- Interact with multiple smart contracts with cross-contract call
- Estimate the gas costs
- Test and find errors in workspaces.
- Some critical concepts about near protocol and sharding.
- Reading transaction process on explorer
- Built on NEAR (with near-sdk-rs) is brain massage.
What's next for Perf finance
- Fix bugs in the front-end
- Implement some cool features:
- Fluent zap, users can provide only one kind of FT to stake in our yield aggregator automatically.
- Dao harvester incentives front-end fully supported
- Bump near-sdk-rs to 4.1.1+, integrate NEAR-ABI
- Using pagoda to analyze smart contracts' activities
- Smart contract audit by the security team
- Launch social media, communicate with the community
- Mainnet publish
Built With
- near
- near-contract-standards
- near-sdk-rs
- react
- rust
- typescript



Log in or sign up for Devpost to join the conversation.