Inspired by GSN, which enables one to pay for another's transactions, we decided to generalize the concept of mutually beneficial transactions further. The impetus behind this is two-fold: 1. Requiring people to either be online or run bots in order to manage their blockchain accounts poses a major barrier to adoption. And 2. Remaining silo'd within our own accounts leaves a tremendous amount of value on the table that we could otherwise all benefit from.
What it does
ASC Protocol = Active Smart Contract/Active State Change (for Cosmos) Protocol. At a high level, ASC allows you to specify conditions under which transactions can be made on your behalf, and economically incentivizes others to fund these transactions when these conditions are met. This opens up a new paradigm of possibility within blockchains. With it, in a decentralized and 100% trustless way, you can do things like:
- Run scheduled subscription payments that just work
- Stop monitoring DeFi products for changes in rates. Specify your criteria and leave the rest to the bots.
- Regain the power to use stop-limit/stop-loss orders. There's no reason these financial instruments should be relegated to the world of centralized exchanges.
- Cause autonomous DAO payments, either to users such as in the case of insurance or UBI, or to oracles and other necessary public goods. We have implemented/designed this functionality in 3 ways: A1) Used ASC Protocol to add stop loss functionality to the new Cosmos DEX (link for the PR is below). A2) Aside: We have also added 2 PRs to Cosmos that should hopefully resurrect their fallen tutorials (links also below). B) Created a ManagedLendingService ASC for AAVE that removes the pressure from users to keep an eye on lending rates. C) Used ASC Protocol to design stop loss functionality for the Waves DEX ## How we built it #A1) We used the Cosmos SDK and golang to create a module that allows an application to use a new stop loss order type. We also created a nice UI to show how a user would get their transaction to a relayer (described below). Transaction flow:
- The user finds a relayer, ideally through a web-market of relayers that have each publicly stated they are willing to hold onto transactions for competing fee rates, such as a stop loss, and watch the relevant price data until they are able to fulfill the condition of the trade
- The user signs a Stop transaction but does not broadcast it to the wider network
- The user privately sends the signed transaction in raw hex format to the chosen relayer through their chosen channel, who then stores the tx locally
- The relayer watches the relevant price
- When the market price goes above or below the stop price (depending on initPrice), the transaction is able to be executed, so the relayer broadcasts the tx to the wider network
- The tx is executed successfully. The user has bought or sold around their desired price. Cancer is cured. There is peace in the Middle East. World hunger is no more.
We created solidity smart contracts that wrap the AAVE money markets to provide a ManagedLendingService. One of the problems with money markets is that they contain technical, economic, and security risk. People are interested in the high yields offered by stablecoins, but don't want to spend their days monitoring the markets for changes. The ManagedLendingService allows you to specify conditions under which your token balance can be deposited or withdrawn from the AAVE money markets, and provides an economic incentive to relayers who cause these state transitions to occur. This results in a specialization of labor that is to the benefit of everyone. More technical users are happy to build bots to watch the blockchain for profit, while more lay users benefit from the ease of use and profit margins that come from automation, causing gains in efficiency and creating value that would otherwise be lost.
In addition to the deployed smart contracts, we created a nice UI that we modeled after the current AAVE UI, but with extra fields for specifying the risk tolerance of the user. We then hooked up that UI to the Kovan Ethereum testnet and integrated with MetaMask and the deployed smart contracts. It's an actual working product, end-to-end!
We applied the ASC Protocol to Waves to design a stop loss mechanism for their DEX, similar to Cosmos above. More advanced functionalities can also be discussed.
## Challenges we ran into
- Using the web3.js library to hook up MetaMask was a challenge as it was highly finnicky. Bad practices abound on stack overflow for web3.js, such as inlining private keys in code and re-inventing the wheel for signing.
- Understanding Cosmos well enough to start writing code and know how it would fit into the overall architecture of a real application such as the Cosmos DEX was difficult. The tutorials for doing so had many bugs which made it take much longer than it should've, which is why we decided to submit a PR (which has been already merged!) to help others in the future. ## Accomplishments that we're proud of Mainly extending a promising protocol that unlocks functionality within the blockchain space and reduces friction, but also:
- Understanding Cosmos...kind of....lol
- Becoming an official Cosmos contributor by getting a PR merged
- Getting MetaMask to successfully work
- Creating a really clean git repo for a hackathon :) ## What we learned The architecture of Cosmos, how to build modules, and how those modules fit together More detailed Web3.js How AAVE works internally ## What's next for ASC Protocol Depends if we have the funds to continue ;)