DEV Community

Neelansh Mathur
Neelansh Mathur

Posted on

Deadman's Switch, Uniswapper - Polygon Week 2

gm

Part of my journey at the Polygon Fellowship 2022.

Blockchain is an interesting piece of technology. The theme for this week was Smart Contracts.

Smart Contracts are the backbone of the Ethereum ecosystem. All the business logic of your application is written in Smart Contracts cannot be modified after being deployed. (Proxies are a small exception).

Let's explore what I built.

Deadman's Switch

The name is very badass 😂. Reminds me of the movie Pirates of the Caribbean: Dead men tell no tales. 🏴‍☠️.

What happens if a smart contract is holding funds, but the owner of the fund dies or is unable to access their wallet for whatever reason?

A deadman's switch requires that the owner calls the still_alive function periodically at a set interval, say every 10 blocks.

If the owner hasn't called still_alive when they should have, then the rescueFunds function can be called that will transfer all the funds in the contract (like Ether) to a preset emergency address.
This ensures that funds are not forever locked in the contract.

You can check out my implementation of the Deadman's Switch at my Github repository: https://github.com/neelansh15/Deadmans-Switch.
It is deployed on Goerli at https://goerli.etherscan.io/address/0x8C51Aec2eAf32852DeD8D89a75Ffd499ed7E7547.

Uniswapper

I wanted to learn more about the DeFi ecosystem, and what better way to start than with Uniswap! The pioneer in this space.
I took ETH & USDC as a good starting pair and was able to do a couple of things:

  1. Get ETH-USDC pair data using UniswapV2Factory and UniswapV2Pair
  2. Swap ETH for USDC using UniswapV2Router
  3. Add Liquidity to ETH-USDC, with a twist. Instead of providing both the tokens, you just have to send ETH and the contract will calculate the required USDC amount from the reserves data, swap ETH for the required USDC and then add liquidity to the Uniswap V2 Pool of ETH-USDC.

More Uniswap functionality can be added and I will redeploy as that happens.
Check out the code that makes it possible: https://github.com/neelansh15/Uniswapper
Deployed at: https://goerli.etherscan.io/address/0xF5ca8778edab3C08897791A37c03AE0ccE525115

Bridging Tokens

You can actually bridge your ERC20 tokens from Goerli to Polygon Testnet or from Polygon Mainnet to Ethereum by using the Polygon PoS bridge!
What it allows you to do is submit your ERC20 token on say Goerli, and it will map it to the Polygon Testnet so that your tokens can be bridged between the two chains!

I created an ERC20 token called HILL and I am waiting for the approval from Polygon. According to their site, it usually takes 3 days to a week to approve it.
Hopefully mine is done soon!

I also learnt about DeFi in a session hosted by the Devfolio and Polygon teams. In fact, that is what the contents of next week is going to be! Very excited to learn more about the DeFi ecosystem and build on top of it.

gn

Top comments (0)