0xProtosec

@0xProtosec

Joined on Feb 8, 2022

  • After watching this excellent lesson in Solidity and Inline assembly by the Ethereum Engineering Group, I decided to convert my notes into an article and publish it for posterity. Please DM me to highlight any suggestions or mistakes in the text. Introduction We can write smart contracts in four major ways: Plain Solidity Solidity w/ inline assembly sprinkled in Yul (low level language w/ inline opcodes Bytecode (plain opcodes)
     Like  Bookmark
  • The following notes explain the GMX Protocol's price fetching mechanism. The primary aim to convey a sense of the price fetching mechanism and execution flow as it is used by the GMX protocol. Introduction The Vault is one of the central contracts of the GMX protocol. It allows users to deposit funds into the vault and mints them GLP tokens. In addition to withdrawing their assets from the vault, users can also swap tokens, short and long (bet on asset prices, whether they will fall or rise) using leverage. Users get liquidated if losses of the position reduce the collateral's value to the point where position size / deposited collateral is more than the max allowed leverage. This makes asset price fetching very important. Price fetching done through two contracts: VaultPriceFeed and FastPriceFeed. Price Calculation Overview keeper bots calculate asset prices by averaging the prices of said asset on Binance, Bitfinex and Coinbase. There are two types of keeper bots: PriceFeedKeeper: Submits prices for swaps routinely (every 2 hours) PositionKeeper: Submits prices when a position is being executed.
     Like  Bookmark
  • Overview GMX is a "decentralised spot and perpetuals exchange". Spot means that users are able to execute their trades (exchanging one crypto token for another) at the spot price, which is the price right at the time of order creation and the simultaneous settlement. Perpetuals are a type of Futures contracts. Futures Futures are contracts to trade one currency for another. They are created in the present and are to be settled/ executed at a set date/ time in the future, at the price prevalent at that time. These contracts can them be themselves speculated upon and traded in a secondary market. Naturally, as the settlement date nears, the price of the futures contract starts getting closer to the price of the underlying asset itself, until the data of the settlement finally approaches and the contract is executed. As such, the price of the futures contract remains close to the price of the underlying asset. This also makes futures contract a derivative, i.e., they do not have an intrinsic value, rather they derive the value from the underlying asset that is the subject of the futures contract. Perpetual Futures Perpetual Futures (or perpetuals, or perps) are a type of futures contract. The only difference is that in this case, there is no settlement date and one can hold a futures contract for an indefinite period of time. A problem poses itself, however, what if the perp's price deviates too much from the underlying asset's price? To remedy this, perps have a funding rate. The purpose of a funding rate is to keep the price of the perp as close to the price of the underlying asset as possible.
     Like  Bookmark