Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added project 2 #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 142 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,145 @@
# Hyper Token Bridge

# The Quest
Hyper Token Bridge is a cross chain bridge that allows to swap native token to wrapped native on the other chain. For eg. I want to swap the native `BNB` token into `WMATIC` (or `ETH` into `WMATIC`) token on the polygon chain so hyper bridge can do that in a very less time.

![42 (1)](https://user-images.githubusercontent.com/128218414/236816131-6743e2b1-8cb8-47ef-b198-e65cd5f773ab.png)
```sh
DEPLOYED ADDRESSES :
--------------------

Join the Quest challenge Exclusive for Polygon Advocates to showcase their skills and win amazing rewards like swags, a demo night with our head of growth, a sponsored trip up to $1000 to Polygon Connect, and a closed session with your chosen co-founder of Polygon Labs



## goku#001 - goku#050 🔥

**How get one of these, What is the possible ways of contribution ?**

Use Polygon solutions like POS, zkEVM, and ID to add a repo to the Advocates GitHub the challenge and submit your code to the repo this could be like Build a smart contract deployment or a basic dApp and show off your expertise to the Web3 community.

**Ways to contribute and collect one of these:**

- Fork this repository and name the file "username_any title you wish to use" eg. johnsoncarl_deploying_your_own_erc20 and start showcasing your expertise by building a simple smart contract or dApp using Polygon solutions like POS, zkEVM, or ID.

- The smart contract could be a basic voting or polling system, crowdfunding platform, or any other contract of your choice.

- You could create a simple login system that uses Polygon's ID.

These are some of the suggestion to what you could do, feel free to add your creative minds here, Also please make sure to submit your code to the Advocates GitHub, If you are having any difficulties creating one please contact Abix tg "**amiabix**".

## naruto#001 - naruto#050 🍥

**How get one of these, What is the possible ways of contribution ?**

To complete this challenge, You are required to host a workshop that focuses on building on the Polygon solutions like POS, zkEVM, and ID. The workshop can be conducted either online or offline, depending on the Advocate's preference and the feasibility of the location.

**Ways to contribute and collect one of these:**

- Facilitate the workshop on Polygon solutions like POS, zkEVM, and ID, providing guidance and support to
participants as needed, and encourage questions and discussion.

## mikasa#001 - mikasa#050 🗡️

**How get one of these, What is the possible ways of contribution ?**

To complete this challenge, You need to explore and experiment with different Polygon network tools and create tutorials and guides for other advocates to follow and something that could be used by others in the community to follow through.

**Ways to contribute and collect one of these:**

- Create tutorials and guides to help others to follow your steps and learn from your
experience. Your tutorials and guides could be in the form of blog, twitter thread
, video tutorials, or GitHub repositories.

## itadori#001 - itadori#050 💪

**How get one of these, What is the possible ways of contribution ?**

Participate in hackathons and events, showcasing your projects and sharing your experience with others, one of the recent hackathons running is [Polygon APAC DevX Tour](https://dorahacks.io/hackathon/polygondevx) feel free to build and showcase your skills and also get some bounties.

## kagome#001 - kagome#200 🏹

**How get one of these, What is the possible ways of contribution ?**

you can contribute in various non-technical ways as well. For instance, you can share your thoughts and ideas about the Polygon ecosystem by writing blog articles or creating visually appealing posters and memes.

**Ways to contribute and collect one of these:**

- You can create Twitter threads and share your experiences with
the community. Additionally, Things like a short videos to showcase
your Advocate journey or to provide insights into the benefits of
using Polygon solutions like POS, zkEVM, and ID.

- There is a lot of flexibility when it comes to this contributions,
and you can explore different mediums to showcase your creativity and
get yourself this.


## What's in for the rewards 🌟

| Collections 🃏 | What it Unlocks 🔓 |
|--|--|
| 3 cards | Polygon Swag pack (ahm, could be anything tee, domains or idk) |
| 5 cards | Demo night for your product or bring in friend product to pitch to Head of Growth, Polygon |
|7 cards | Membership for Dev DAO and other tools like GitHub co-pilot etc.|
| 9 cards | Sponsored trip to Polygon Connect (upto $1000) |
|11 cards | Closed session with your chosen Co-founder of Polygon Labs |

## Wait !! did we mention about Kuraia, the Nine-Tailed Vixen ? ✨ 🦊 ✨


*Consider this as an exclusive card for doning anything out of the box, what could be something out of the box ? It could be anything that blows our heads through the roof with creativity, ***This is the Card eligible for all the rewards mentioned above and much more !!!****

## Submissions and guidelines 🏄‍♂️

1. Submit your work to the designated form [here](https://airtable.com/shrJW5zrv1BnZTxWy), Make sure to include a brief description of your work, your GitHub repository link (if applicable), and any other relevant details.

2. The submission ***deadline for each challenge is May 30th***. Make sure to submit your work before the deadline to be eligible for rewards.

3. All submissions will be reviewed by the Polygon team

***looking to view the collection set ? [Check it out here](https://opensea.io/collection/the-quest-polygon-advocates)***


## Is there a smart way of doing it ? 🧠

Yeah, Absolutely, let me drop you an example that helps you get 3 cards in a single go could be of help:

- Create a repository showcasing your expertise by building a simple smart contract or dApp using Polygon solutions like POS, zkEVM, or ID on the Advocates GitHub, which gets you to complete the goku card.

- Refine the repo with a good formatted # READMEs and publish, This could also include sections like, how people could contribute to it, Possible enhancements etc, which gets you to complete the mikasa card

- Since you already have things in order just tweet about it in a formt of a twitter thread, tagging @0xPolyAdvocates ,Thread could have info about the repo, what one can learn from it or what did you contribute to it etc. which gets you to complete the Kagome card.

***If you round that up you just unlocked the 3 card set for yourself in a single go !*** 🤩 🤩

That being said you could look for possible combinations to unlock others! Once done You could just add the detials for **submission** [**here**](https://airtable.com/shrJW5zrv1BnZTxWy)

ETH GOERLI : 0x13A7413c7A15472460149F55d1f3F1465B1f7108
POLYGON : 0xd2dbB4faB85478aF795c06bd36e5f7ed76D51fFe
```

## How it works ?

<img src="./docs/L0.png"></img>

### Chain 1

- User initiates the `bridgeToken` function.
- Value of the transaction is checked.
- Upon receiving the asset then the message is sent to another chain using `_lzSend()`.

### Chain 2

- Upon receiving the message from the source chain `_nonblockingLzReceive` function is called.
- Now decoding of the bytes is done and the values are stored.
- After that `_performAssetSwapOnReceiving` function is initiated thus swapping the USDC present on the smart contract with the wrapped native and sending it to the recipient.

### Pool Asset Price Calculation

- Here after receiving the asset on the destination chain the calculation of price will be done as :

```js
// 1. Getting the pool for the assets : USDC/<Native Token>
IUniswapV3Pool pool = IUniswapV3Pool(
uniswapV3Factory.getPool(
stableAssetAddressUSDC,
wrappedAssetAddressNative,
POOL_FEE
)
);

// 2. Getting the sqrtPriceX96 price from the pool
(uint160 sqrtPriceX96, , , , , , ) = pool.slot0();

// 3. Getting the amount of the token[0] from the pool
uint256 amount0 = FullMath.mulDiv(
pool.liquidity(),
FixedPoint96.Q96,
sqrtPriceX96
);

// 4. Getting the amount of the token[1] from the pool
uint256 amount1 = FullMath.mulDiv(
pool.liquidity(),
sqrtPriceX96,
FixedPoint96.Q96
);

// 5. Calculating the price for the token in USDC from the pool
uint256 priceFromLiquidityPool = (amount1 *
10 ** ERC20(stableAssetAddressUSDC).decimals()) / amount0;
```

## Tech Used

- Layer Zero
- Uniswap V3 router
- Uniswap V3 Factory
- Hardhat
- Solidity
- TypeScript

## How to contribute ?

- Getting the repository ready

```sh
git clone https://github.com/Arun89-crypto/HyperTokenBridge
cd HyperTokenBridge
```

- Setting up the dependencies (Contract)

```sh
cd crosschaincontracts
yarn
yarn hardhat compile
```

- To deploy on the network

```sh
yarn hardhat run --network <network> scripts/deploy.ts
```

There are several constants for the deployment that can be found here :

```ts
export const CONSTANTS = {
TESTNET: {
ENDPOINTS: {
BNB_TESTNET: "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1",
MUMBAI: "0xf69186dfBa60DdB133E91E9A4B5673624293d8F8",
ETH_GOERLI: "0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23",
},
CHAIN_IDS: {
BNB_TESTNET: "10102",
MUMBAI: "10109",
ETH_GOERLI: "10121",
},
PRICE_FEEDS: {
BNB_USD: "0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526", // Binance Smart Chain
MATIC_USD: "0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada", // Polygon Mumbai
ETH_USD: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e", // Eth Goerli
},
UNISWAP_ROUTER_V3: {
ETH_GOERLI: "0xE592427A0AEce92De3Edee1F18E0157C05861564", // Eth Goerli
MUMBAI: "0xE592427A0AEce92De3Edee1F18E0157C05861564", // Polygon Mumbai
},
UNISWAP_FACTORY_V3: {
ETH_GOERLI: "0x1F98431c8aD98523631AE4a59f267346ea31F984", // Eth Goerli
MUMBAI: "0x1F98431c8aD98523631AE4a59f267346ea31F984", // Polygon Mumbai
},
WRAPPED_ASSET: {
WETH: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", // Eth Goerli
WMATIC: "0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889", // Polygon Mumbai
},
STABLE_ASSET: {
ETH_GOERLI_USDC: "0x07865c6E87B9F70255377e024ace6630C1Eaa37F",
MUMBAI_USDC: "0xe6b8a5CF854791412c1f6EFC7CAf629f5Df1c747",
},
},
};
```

You need to change these constants according to the network in the deploy script.

- To contribute
- Fork the repository
- Create new branch : `git checkout -b <branch_name>`
- Do the changes
- Create PR

## THANK YOU
Binary file added docs/L0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions hyper_token_bridge/assets/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const CONSTANTS = {
TESTNET: {
ENDPOINTS: {
BNB_TESTNET: "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1",
MUMBAI: "0xf69186dfBa60DdB133E91E9A4B5673624293d8F8",
ETH_GOERLI: "0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23",
},
CHAIN_IDS: {
BNB_TESTNET: "10102",
MUMBAI: "10109",
ETH_GOERLI: "10121",
},
PRICE_FEEDS: {
BNB_USD: "0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526", // Binance Smart Chain
MATIC_USD: "0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada", // Polygon Mumbai
ETH_USD: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e", // Eth Goerli
},
UNISWAP_ROUTER_V3: {
ETH_GOERLI: "0xE592427A0AEce92De3Edee1F18E0157C05861564", // Eth Goerli
MUMBAI: "0xE592427A0AEce92De3Edee1F18E0157C05861564", // Polygon Mumbai
},
UNISWAP_FACTORY_V3: {
ETH_GOERLI: "0x1F98431c8aD98523631AE4a59f267346ea31F984", // Eth Goerli
MUMBAI: "0x1F98431c8aD98523631AE4a59f267346ea31F984", // Polygon Mumbai
},
WRAPPED_ASSET: {
WETH: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", // Eth Goerli
WMATIC: "0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889", // Polygon Mumbai
},
STABLE_ASSET: {
ETH_GOERLI_USDC: "0x07865c6E87B9F70255377e024ace6630C1Eaa37F",
MUMBAI_USDC: "0xe6b8a5CF854791412c1f6EFC7CAf629f5Df1c747",
},
},
DEPLOYED_ADDRESSES: {
ETH_GOERLI: "0x13A7413c7A15472460149F55d1f3F1465B1f7108",
POLYGON_MUMBAI: "0xd2dbB4faB85478aF795c06bd36e5f7ed76D51fFe",
},
};
Loading