Hitchhikers Guide To Treasury Deposits.

As we prepare for our launch we could not be more excited. Many months of work culminating into this one event. However before that we need to make sure that everyone is prepared and has a thorough guide so that they feel comfortable coming along on this journey alongside us.

We would first like to give a quick explanation of what it is that we are doing and why we are doing it the way that we are.

To answer the first question we need to look no further than late 2021. Everyone was excited as the times were seemingly good. However underneath all of these things the foundation was shakey. Insolvent CEO’s flaunting on twitter and egos running wild. Very soon after the highs, pieces began to break. Starting with luna and everything that followed that. Mugen was already under development at that time, but these events strengthened our resolve to build out this project even more. Individuals needed a clear and transparent way to access yield. The old opaque ways were simply not good enough. It was also critical that individuals understand how this yield was being generated, and that is was sustainable. Thus Mugen came to life.

Aggregating the best yield across all of defi in a way that was clear, transparent, and easy. Well, some what easy, but we will get to that. Long gone are the days in which you can just throw money at something and hope things work out. Which brings use to the why behind the way that we are doing things.

Individuals have recently become to dependent on centralized entities for control of decisions with their money. We have intentionally made this entire protocol one long process in which individuals will begin to slowly move away from these entities and become fully capable of handling things themselves. Starting with learning basic tools like etherscan, github, and even the basics of solidity. We have no intention of just throwing you to the wolves, but rather slowly working through different aspects of our own protocol in the open with helpful guides anyone can use for a variety of purposes.

The first step starts today. Beginning with how to deposit into our very own treasury. This guide will take you step by step making sure that you know what is going on throughout the entire process. If you already have a pretty good understanding of defi and have used etherscan to write and read contracts feel free to skip this beginning part and go on to the section labeled Deposit into the Treasury.

We have made a few assumptions that if you are reading this you most likely understand how to use basic defi protocols like Uniswap work.

Step 1. Bridging to Arbitrum.

There are several bridges that you can use. We personally recommend either Stargate or Synapse. We have gone ahead and linked them each to their respective names, but we do always recommend verifying yourself from their official twitter pages or other communication outlets.

Once onto these sites you simple need to connect your wallet and head over to their transfer or bridge tabs and select Arbitrum for the receiving chain. We recommend bridging either ETH or USDC over to Arbitrum.

It will probably take a few minutes to go through but shouldn’t be more than 10-15 and can always be tracked on etherscan.

Step 2 Get USDC

Once you have made it to Arbitrum you will need to make sure that you have USDC. This is because on launch USDC will be the only whitelisted protocol available for deposits. However you will need to make sure that you have enough ETH leftover to pay for a few transactions.

Step 3 Approve the Treasury

This is where the fun begins. Now that you are here and have your USDC there is one more thing that needs to be done before you can deposit. You need to approve the treasury address to spend your USDC. The reason behind this will be explained at the end of this post where we walk though step by step what exactly is happening when you start this deposit function, but for now all you need to know is we need to head over to arbiscan.

You can either paste this address into the arbiscan search bar:

0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8

or you can click this link here.

Once there you will need to head over to the “Contract” tab and select “Write as Proxy”. Once there you will see a small box at the top that says “Connect to web3”. Simply click that link and follow the instructions to connect to arbiscan. It should be quite similar to connecting to any other website you have used in web3. The dot will turn green when successful.

Note: If you use Brave you will most likely have to turn off the Brave Wallet and make sure it does not come up as the default.

Now the function that we are interested in this the approve function. It should be the first function.

There are two input fields spender address and amount. In the first field you will place the contract address, which will be given upon launch and in the second address you will place how much you would like to deposit. We recommend slightly more just to make sure. Typically when you approve a function you approve 2**256 -1 so that you do not have to do it again. If you would like to do so you can. However it is unnecessary as we will show later on.

A important thing to not about the uint256 amount field is that you will need to approve however much you want to spend in USD * 10 raised to the 6th (raised to the 6th because USDC has 6 decimals, for tokens with 18 it would be to the 18th).

Am approval of 1 would look like this 1000000, 100 is 100000000, and 1 million is 1000000000000, so on and so on.

Once you have completed this you have just one more thing to do, deposit into the treasury.

Step 4 Deposit into the Treasury

This will operate in a very similar fashion as before with nearly identical inputs. There will be two fields an address field labeled token and an amount field. For the address field you will simply but in the USDC address and for the amount field you will but in the amount (following the same guidelines discussed earlier { amount * 1e6}). And boom that is it you have done it.

Now if you want to stick around and learn a little bit about what is happening feel free. If you just want to learn how to deposit right now that also works. But now we will take a look at the code to see what is happening.

Starting with the parameters. These are the fields that you will see in arbiscan and allow the contract to know which token it is taking in and what amount. There are also several modifiers to protect against reentrancy, make sure the token is whitelisted, the cap is not crossed, and there is no pause against the current contract.

Following checking to make sure the above conditions are met and the amount is greater than 0 we set a memory variable to the decimals of the token, as this would have a big impact on how the accounting works and also how much is transferred to the contract. Caching this variable also helps save gas.

Then we check to see if the token decimals are equal to 18 or not. If it is not we have an addition step we need to take were we do some calculations to set the value so that it will be equivalent to as if it did have 18 decimals. This step is to help with the bonding curve.

The get price function is a function of chainlink data feeds and tells use the current by as well as the decimals of the price feed. Once we have the decimals of the price feed we divide the (amount price) by this to give us its USD value * 1e18.

This value is then feed into the bonding curve which will tell the contract how many tokens to mint the user.

The total supply and value deposited are then updated and we emit an event so that this transactions can be more readable.

Then lastly the deposited tokens are transferred to the necessary contract and Mugen tokens are minted and sent to you!

And boom transaction done. Now you are ready to complete this again in the future or try it out for yourself on a different contract. You have official learned how to complete a transaction just using arbiscan and are one step closer to being less dependent on third parties.

Subscribe to Mugen Finance
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.