# How Catnip works from A to Z *If you're just looking for a quick tutorial on how to place your first trade check out [this post on our Substack.](https://catnip.substack.com/p/your-first-trade-on-catnip-prediction)* **Catnip is a prediction market UI built on Augur and Balancer. It is fully open-source and decentralized with no custody of user's funds at any step of the way.** There's been a few questions about how the Catnip shares can be redeemable for one DAI at market expiration, where can the solvency be verified, and how the market will resolve correctly. Here's a quick run-down on how Catnip works under the hood. ## 1. Augur Catnip is built on top of Augur. To understand the former fully, we need to go through the latter first. Augur is a decentralized predictions market platform. Its smart contracts provide methods to create markets and settle them (an oracle). On each market, anyone can mint a "complete set of shares". For a YES/NO market, 1 DAI = 1 YES share + 1 NO share + 1 INVALID share. Shares are standard ERC-1155 tokens. The DAI is held in escrow and these shares are freely tradable by users. When the market resolves to an outcome, all of the corresponding outcome shares become redeemable for 1 DAI each (taken from the escrow contract). The resolution is made by holders of REP (Augur's native token) with a decentralized reporting and dispute system that is designed to be secure against rational attacks or censorship. For more about the core Augur design and the game theory, see the [whitepaper](https://www.augur.net/whitepaper.pdf). For a list of all Augur contracts with their verified source code on Etherscan, see the [v2 announcement blog post](https://www.augur.net/blog/augur-v2-launch). ## 2. Balancer Balancer is an automated market making protocol that allows users to swap any ERC-20 token against another in liquidity pools. This concept replaces the traditonal order book with an algorithm that automatically calculates the price of a trade against a pre-determined formula. For a brief description of automated market makers, see this [Binance Academy post](https://academy.binance.com/en/articles/what-is-an-automated-market-maker-amm). For a more theoretical foray, see [this](https://medium.com/bollinger-investment-group/constant-function-market-makers-defis-zero-to-one-innovation-968f77022159) blog post about AMMs. Simple automated market makers like Balancer make it computationally much cheaper to trade than complex orderbook matching engines. The idea with Catnip is to use this to allow users to trade Augur outcome shares for DAI at a lower cost than on the default Augur UI. Briefly, Balancer allows liquidity providers to put in YES shares, NO shares and DAI in a liquidity pool and then users can trade against that pool. This is separate from the contract escrowing the DAI that was used to mint the shares. If you're a trader, you don't have to worry about the liquidity provider experience, but they're taking risk when providing liquidity because they are adding their own DAI and minted shares to the pool to let users trade against it. Unforunately, Balancer only takes ERC-20 tokens. Which leads us to the Foundry (next paragraph). For more details about Balancer, see their [website](https://balancer.finance/). For a list of all Balancer core contracts and code, see this [Balancer launch announcement blog post](https://medium.com/balancer-protocol/balancer-is-live-4ba2f474131b). ## 3. Foundry As mentioned above, Balancer only works with ERC-20 tokens currently, and Augur shares are natively ERC-1155. The Foundry is a wrapper that takes ERC-1155 tokens, puts them in escrow, and mints corresponding ERC-20 tokens in return. To see the contract with verified code on Etherscan, go [here](https://etherscan.io/address/0x87876f172087e2fb5838e655dc6a929dc2dcf85c#code). ## 4. Putting it all together: Catnip Catnip is an interface which uses a Balancer pool containing wrapped outcome shares and DAI and allows users to swap any of the three tokens against each other. The price is automatically determined by the Balancer pool contract. Owners of wrapped shares can transfer them freely and unwrap them at any time. The Augur market for Catnip's election outcome is visible in the default Augur UI [here](https://bafybeiemgafgf7cutvlxpjs5umt7ysjwrd6sdmmoj3jq7g3tnjmkz3v2cq.ipfs.dweb.link/#!/market?id=0x1EBb89156091EB0d59603C18379C03A5c84D7355). The market settles after January 22nd once the Electoral College has voted to ensure a safe resolution. Winning share holders may sell shares earlier, as soon as the outcome is known, for slightly less than one DAI per share. Or they can wait to settle 1:1 for DAI after the market resolves. The contract for this market is [here](https://etherscan.io/address/0x49244bd018ca9fd1f06ecc07b9e9de773246e5aa#code), and one can verify it indeded holds enough DAI in escrow for users to redeem their winnings. When the market is resolved, a "Redeem winnings" button will appear on the Catnip interface to make it easy for users to claim their DAI. This is also available via [Augur Foundry.](https://foundry.finance/) If Catnip or the Foundry frontend were to go offline for some reason, redemption would still be possible at the contract level and another UI would likely be quickly spun up by a community member to assist non tech-savvy users: **there is no custody of funds at any step of the Catnip experience.** The code for the Catnip UI + integration with Balancer is available [here](https://github.com/aug-dao/catnip). The underlying Balancer pool can be found [here](https://etherscan.io/address/0x6b74fb4e4b3b177b8e95ba9fa4c3a3121d22fbfb) on Etherscan. And the ERC20 token contracts for the election market: [yTrump (yes)](https://etherscan.io/address/0x3af375d9f77ddd4f16f86a5d51a9386b7b4493fa) [nTrump (no)](https://etherscan.io/address/0x44ea84a85616f8e9cd719fc843de31d852ad7240) [iTrump (invalid)](https://etherscan.io/address/0x0d0bd297350b49ee96d5d4e15a12001928fddb1e) To verify ERC-1155 balances of the wrapper contracts: 1) Go to the ERC20 token contract on Etherscan (see above links) 2) Under “Read Contract” copy `tokenID` (you can also see all the tokenIDs [here](https://github.com/aug-dao/augur_foundry/blob/master/client/src/configs/markets/markets-mainnet.json#L13-L15)) 3) Go to Augur’s `shareToken` contract [here](https://etherscan.io/address/0x9e4799ff2023819b1272eee430eadf510edf85f0#readContract) 4) Under `balanceOf`, enter the ERC20 token address and `tokenID` to query the balance