<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: RiccardoBiosas</title>
    <description>The latest articles on DEV Community by RiccardoBiosas (@riccardobiosas).</description>
    <link>https://dev.to/riccardobiosas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F507883%2F69fdfe84-5228-45d2-b27a-f98fde976509.png</url>
      <title>DEV Community: RiccardoBiosas</title>
      <link>https://dev.to/riccardobiosas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/riccardobiosas"/>
    <language>en</language>
    <item>
      <title>Compete in Web3 coding challenges and win a $$$ prize</title>
      <dc:creator>RiccardoBiosas</dc:creator>
      <pubDate>Mon, 01 Apr 2024 08:15:03 +0000</pubDate>
      <link>https://dev.to/agorapp/compete-in-web3-coding-challenges-and-win-a-prize-2pk0</link>
      <guid>https://dev.to/agorapp/compete-in-web3-coding-challenges-and-win-a-prize-2pk0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Your goal in this challenge is to compute the largest prime factor of an arbitrary integer. For instance, the prime factors of 13195 are 5, 7, 13 and 29, and as such, the largest prime factor of 13195 is 29.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some readers might recognize the above coding problem: it's the &lt;a href="https://projecteuler.net/problem=3"&gt;third challenge&lt;/a&gt; on the &lt;a href="https://projecteuler.net/"&gt;Project Euler&lt;/a&gt;. A lot developers are capable of solving it with more or less efficient solutions: but what if you had to use a fairly esoteric programming language - such as &lt;a href="https://agorapp.dev/ide/ethereum/solidity/introduction-to-solidity/01-contract-declaration"&gt;Solidity&lt;/a&gt; - in a far more constrained computational environment - the &lt;a href="https://ethereum.org/en/developers/docs/evm/"&gt;EVM&lt;/a&gt;-?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That's what we do at &lt;a href="https://agorapp.dev/"&gt;Agorapp&lt;/a&gt;&lt;/strong&gt; - and &lt;a href="https://agorapp.dev/ide/ethereum/solidity/largest-prime-factor/challenge"&gt;here's the coding challenge&lt;/a&gt; that requires you to implement prime factorization in Solidity.&lt;/p&gt;

&lt;p&gt;Many users here are probably familiar with Leetcode or Hackerrank: &lt;strong&gt;what if you could test yourself in similar algorithm and security challenges but in the context of smart contract development?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And what if you could &lt;strong&gt;win prizes&lt;/strong&gt; should you rank in the top 3 coders who crafted the most optimal solution?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://agorapp.dev/"&gt;Agorapp&lt;/a&gt; is the leading Web3 interactive coding environment and talent protocol&lt;/strong&gt;. On our platform, users can compete in gas optimization challenges where their only goal is to come up with the most efficient implementation possible. The reward? They win money - currently not a life-changing amount, but there are surprises on the horizon which will make the coding competition challenges far more compelling and &lt;strong&gt;rewarding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the context of the EVM, designing efficient implementations to an engineering problem is not just a whimsical desire - it's a necessity.&lt;br&gt;
Efficient gas usage leads to lower transaction fees, which results in happier users and/or healthier DApps' economies. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb1x97kmbjfpre8y7799.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb1x97kmbjfpre8y7799.png" alt="Agorapp Web3 IDE" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At &lt;a href="https://agorapp.dev/"&gt;Agorapp&lt;/a&gt; we're challenging developers to push the envelope of smart contract efficiency through our &lt;strong&gt;Smart Contract Optimization Challenges&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On our &lt;a href="https://blog.agorapp.dev/blog/"&gt;blog&lt;/a&gt; you can see &lt;a href="https://blog.agorapp.dev/blog/efficient-sorter-competition"&gt;some examples&lt;/a&gt; of the past winning solutions that have been awarded with the monetary pool prize.&lt;/p&gt;

&lt;p&gt;So far, we have only released gas optimization challenges for Solidity/EVM developers. However, we support many more blockchain ecosystems and runtimes and we are about to &lt;strong&gt;launch the first ever smart contract optimization challenges on non-EVM environments&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rmre1cdzlvp3hybbpta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rmre1cdzlvp3hybbpta.png" alt="Agorapp Web3 smart contract challenge's leaderboard" width="800" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job market outside the EVM ecosystem is growing&lt;/strong&gt; and the current demand outmatches the supply of developers: the vast majority of smart contract developer knows only Solidity. &lt;strong&gt;&lt;a href="//agorapp.dev"&gt;Agorapp&lt;/a&gt; aims to be the gateway to learn cross-chain smart contract development&lt;/strong&gt;: Solana, &lt;a href="https://agorapp.dev/course/introduction-to-nearjs"&gt;Near&lt;/a&gt;, the &lt;a href="https://agorapp.dev/tutorial/motoko-tutorial"&gt;Internet Computer Protocol&lt;/a&gt;, TON etc., we plan to provide a smart interactive playground where developers can immediately get onboarded in any Web3 smart contract language or on-chain protocol.&lt;/p&gt;

&lt;p&gt;In the near future, Agorapp will also provide &lt;strong&gt;a talent marketplace where the best developers in our userbase will be matched with jobs, grants and bounties in the Web3 ecosystem&lt;/strong&gt;. Are you interested in working in web3? Then reach out to us on &lt;a href="https://discord.gg/SeXPtxfeha"&gt;Discord&lt;/a&gt; or &lt;a href="https://twitter.com/agorappDAO"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And what if you don't know any smart contract language? No worries, at Agorapp we provide &lt;a href="https://agorapp.dev/catalog"&gt;interactive dev courses on our online Web3 IDE&lt;/a&gt;. &lt;br&gt;
Check out our &lt;a href="https://agorapp.dev/course/introduction-to-nearjs"&gt;Near developer course&lt;/a&gt;, &lt;a href="https://agorapp.dev/tutorial/motoko-tutorial"&gt;Motoko smart contract developer&lt;/a&gt; course and &lt;a href="https://agorapp.dev/course/introduction-to-solidity"&gt;Introduction to Solidity&lt;/a&gt;! And if that's not enough, we have recently started delivering l&lt;a href="https://twitter.com/agorappDAO/status/1767594104081248464"&gt;ive Web3 coding workshops&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the end of your learning journey on Agorapp, you'll be able to compete in smart contract optimization and security challenges - and you might be one of the next winners!&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to be the first to know when our next smart contract challenge will be released? Or when we'll deliver the next workshop? Then follow us!
&lt;/h2&gt;

&lt;p&gt;Join the &lt;a href="https://discord.gg/SeXPtxfeha"&gt;Agorapp Discord&lt;/a&gt; and communicate with the team or follow us on Telegram, &lt;a href="https://twitter.com/agorappDAO"&gt;Twitter&lt;/a&gt; or &lt;a href="https://www.linkedin.com/company/agorappdao/"&gt;Linkedin&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Personal contacts
&lt;/h2&gt;

&lt;p&gt;And feel free to reach out personally to me on &lt;a href="https://t.me/RiccardoBiosas"&gt;Telegram&lt;/a&gt; or &lt;a href="https://twitter.com/rbiosas?lang=en"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>awesome MLSecOps: aka prompt injection is the new SQL injection</title>
      <dc:creator>RiccardoBiosas</dc:creator>
      <pubDate>Sun, 30 Jul 2023 08:05:14 +0000</pubDate>
      <link>https://dev.to/riccardobiosas/awesome-mlsecops-aka-prompt-injection-is-the-new-sql-injection-16nh</link>
      <guid>https://dev.to/riccardobiosas/awesome-mlsecops-aka-prompt-injection-is-the-new-sql-injection-16nh</guid>
      <description>&lt;p&gt;MLSecOps is the cybersecurity field that focuses on exploiting and securing Machine Learning-based models and user-facing applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/RiccardoBiosas/awesome-MLSecOps"&gt;List of Resources&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
The term derives from &lt;strong&gt;MLOps&lt;/strong&gt; - which you can think of as the software engineering field that encompasses the techniques used to put machine learning models in production - from testing and debugging to deploying, monitoring and scaling and anything in between-. MLOps focuses more on the operational aspect of ML rather than, for instance, the development of a ML model, with a specific emphasis on automating some key parts of a ML model lifecycle - some of the automation techniques might sound familiar -such as continuous integration and continuous delivery- whereas others are more specific to the AI/ML field - such as &lt;strong&gt;continuous training&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Roughly speaking, &lt;strong&gt;MLOps is to Machine Learning engineering what DevOps is to software engineering&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Similarly to how the cloud created a whole new security threat landscape, MLOps is also paving the way to a new class of attack vectors.&lt;/p&gt;

&lt;p&gt;Which brings us to the topic of MLSecOps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MLSecOps is to MLOps what DevSecOps is to DevOps.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly to how MLOps occasionally intersects with existing practices, techniques and tooling from the DevOps field, some of the MLSecOps attack vectors also resemble old-fashioned exploits. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt Injection&lt;/strong&gt; is one of the MLSecOps attack vectors that has received &lt;a href="https://www.wired.co.uk/article/chatgpt-prompt-injection-attack-security"&gt;mainstream attention&lt;/a&gt;. According to the OWASP definition in their (very recent) LLM top 10 threat catalog, &lt;a href="https://github.com/OWASP/www-project-top-10-for-large-language-model-applications/blob/700e2f4ae21a0a8d52795bbccb3e76c8671d29fe/1_0_vulns/PromptInjection.md"&gt;prompt injection allows an attacker to manipulate &lt;em&gt;a large language model (LLM) through crafted inputs, causing the LLM to unknowingly execute the attacker's intentions.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, it boils down to taking advantage of a lack of input validation. It is similar to more old-fashioned attack vectors like SQL Injection in that they both involve &lt;strong&gt;injecting malicious queries into an application that is not correctly sanitizing untrusted data&lt;/strong&gt;.&lt;br&gt;
On the other hand, some exploit techniques are more unique to the MLSecOps field - such as &lt;a href="https://github.com/RiccardoBiosas/www-project-machine-learning-security-top-10/blob/f613ffae599cffc52ddb4d760156b6a3270c4661/2023/ML02_2023-Data_Poisoning_Attack.md"&gt;Data Poisoning attacks&lt;/a&gt;, which target the training data of a model and manipulate it in way designed to cause unpredictable/undesirable behaviors.&lt;/p&gt;

&lt;p&gt;As someone who works in InfoSec and occasionally audits applications that deal with some flavor of AI -machine learning, reinforcement learning, LLMs etc.-, lately I have been starting to research the attack vectors to exploit AI models/processes/applications, how to secure them and the AI security tooling ecosystem.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;The result is the &lt;a href="https://github.com/RiccardoBiosas/awesome-MLSecOps"&gt;awesome-MLSecOps Github repository&lt;/a&gt;, where I am keeping track of useful OSS security tools, academic literature &amp;amp; papers and other resources about the field&lt;/strong&gt;&lt;/em&gt;. &lt;a href="https://github.com/RiccardoBiosas/awesome-MLSecOps/issues/1"&gt;If you have any recommendations&lt;/a&gt;, contributions are greatly appreciated.&lt;/p&gt;

&lt;p&gt;And if you are interested in AI security &amp;amp; getting familiar with the field, feel free to reach out on &lt;a href="https://twitter.com/rbiosas"&gt;Twitter&lt;/a&gt; or &lt;a href="https://t.me/RiccardoBiosas"&gt;Telegram&lt;/a&gt;. I am planning to publish more in-depth articles/tutorials on the field as I go.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>llm</category>
      <category>gpt3</category>
    </item>
    <item>
      <title>DeFi derivative development: from zero to hero with Opium v2 pt.1</title>
      <dc:creator>RiccardoBiosas</dc:creator>
      <pubDate>Mon, 24 Jan 2022 19:15:48 +0000</pubDate>
      <link>https://dev.to/riccardobiosas/defi-derivative-development-from-zero-to-hero-with-opium-v2-pt1-2n5e</link>
      <guid>https://dev.to/riccardobiosas/defi-derivative-development-from-zero-to-hero-with-opium-v2-pt1-2n5e</guid>
      <description>&lt;h1&gt;
  
  
  Opium V2: open to all developers and ready for grants!
&lt;/h1&gt;

&lt;p&gt;Programmable money is awesome, but &lt;a href="https://medium.com/opium-network/five-reasons-why-derivatives-are-the-most-promising-opportunity-in-defi-today-b1ba12beab16"&gt;programmable derivatives are the real holy grail of DeFi&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The Opium Protocol was one of the very first DeFi protocols pioneering the options space and, since then, it has provided the foundations to be the settlement layer for many successful financial engineering experiments - including but not limited to &lt;a href="https://medium.com/opium-network/first-decentralised-protection-for-realt-no-occupancy-event-was-launched-on-opium-protocol-9feeedf6b5cd"&gt;realt insurance&lt;/a&gt;, &lt;a href="https://medium.com/opium-network/introducing-opium-bridge-protection-8509ce09fcc7"&gt;bridge insurance&lt;/a&gt;, &lt;a href="https://medium.com/opium-network/first-credit-default-swap-on-aave-credit-delegation-launched-5e3efc961317"&gt;credit default swaps&lt;/a&gt;, &lt;a href="https://medium.com/opium-network/opium-turbo-aave-b69a23ab1048"&gt;turbos&lt;/a&gt;. &lt;br&gt;
With time, however, comes obsolescence. Some of the architectural choices that did indeed make sense at the time Opium v1 was first developed needed to be modernized with more up-to-date design patterns. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2"&gt;Enter Opium Protocol v2! &lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the Mainnet launch of the Opium Protocol v2 nears, the Opium DAO welcomes all developers to experiment with the protocol and apply for grants if they have an interesting use-case. &lt;br&gt;
Feel free to drop you proposal on the &lt;a href="https://forum.opium.network/c/bounties-and-contests/12"&gt;governance forum&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;For this very purpose, the present article is the first of a series of tutorials that will showcase how to develop financial use-cases on top of the Opium Protocol v2.&lt;br&gt;
While the present article aims to be just a quick walk-through of the nuts and bolts of the protocol through a quick mock option contract, future tutorials will be focused on the development of more 'real world' use-cases such as covered call and protective put strategies, more complex financial primitives and an introduction to our upcoming SDK.&lt;/p&gt;

&lt;p&gt;One of the design choices that was scrapped was the usage of Opium’s very own token standard &lt;a href="https://github.com/OpiumProtocol/erc721o"&gt;ERC 721o&lt;/a&gt; - a custom flavor of the more notorious ERC721- whose purpose was to allow for the creation of non-fungible derivative portfolios. &lt;br&gt;
Nowadays a similar rationale has been implemented by the ERC1155 standard, however the degree of interoperability and easy-to-reason-about clean API that the good-old-fashioned ERC20 provides are simply undefeated. &lt;br&gt;
As such, following a long-existing DeFi trend that was first popularized by Uniswap, Opium makes use of a factory pattern that mints ERC20 tokens in a measure proportional to the ownership of LONG/SHORT option positions of their respective owners.&lt;br&gt;
However, as the scope of the article is to give enough of a rundown for a developer to get their feet wet with Opium v2, we will postpone a deep dive into the Opium Protocol architecture to a later date.&lt;br&gt;
If you have any questions, feel free to drop by on the &lt;a href="https://forum.opium.network/"&gt;governance forum&lt;/a&gt;!&lt;/p&gt;
&lt;h2&gt;
  
  
  A quick options recap
&lt;/h2&gt;

&lt;p&gt;First off, what do we mean by ERC20 LONG/SHORT option positions? Here's a very quick and generic refresher on financial options.&lt;br&gt;
An option contract is a financial agreement between two parties, respectively a seller and a buyer, that enables a buyer to execute a trade at a later time if they so desire - which is to say, assuming that the buyer is a rational actor, they will always exercise their option at a profit and they will let it expire unexercised if worthless. &lt;br&gt;
The trade can either consist in the right to acquire a given asset at a previously agreed-upon price or, similarly, in the right to sell a given asset at a previously agreed-upon price. In the first case the option contract is called call option and in the second case it is called put option. Conversely, a seller of an option contract has the obligation to fulfill a trade if the option contract's buyer decides to exercise the option: specifically, when the buyer exercises their option, the seller has the obligation to buy the option contract’s underlying asset in the context of a call option and the obligation to sell the same asset in the case of a put option.&lt;/p&gt;

&lt;p&gt;If you want to learn more about options, check out the following resources:&lt;br&gt;
&lt;a href="https://www.khanacademy.org/economics-finance-domain/core-finance/derivative-securities"&gt;Khan Academy's option course&lt;/a&gt;&lt;br&gt;
&lt;a href="https://opium.finance/academy/"&gt;Opium Finance academy&lt;/a&gt;&lt;br&gt;
&lt;a href="https://insights.deribit.com/options-course/"&gt;Deribit's option course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, where does the Opium Protocol come into play? Think of Opium as a smart financial escrow that allows to encode the logic of complex financial assets - such as option contracts- in a flexible way which ensures that the parties exchanging those financial assets will fulfill their contractual obligations in a trustless fashion.&lt;br&gt;
But enough financial jargon, we are programmers so let’s talk code.&lt;/p&gt;

&lt;p&gt;Now that we know that two of the core properties of an option are &lt;strong&gt;strike price&lt;/strong&gt; and &lt;strong&gt;maturity date&lt;/strong&gt;, how can we describe a financial derivative in Solidity?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Opium derivative structure (ticker) definition
    struct Derivative {
        // Margin parameter for syntheticId
        uint256 margin;
        // Maturity of derivative
        uint256 endTime;
        // Additional parameters for syntheticId
        uint256[] params;
        // oracleId of derivative
        address oracleId;
        // Margin token address of derivative
        address token;
        // syntheticId of derivative
        address syntheticId;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The struct above is the &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/libs/LibDerivative.sol"&gt;schema&lt;/a&gt; that we use in the Opium Protocol. &lt;br&gt;
Let’s quickly walk through it:&lt;br&gt;
&lt;code&gt;uint256 margin&lt;/code&gt;: aka the reference collateral that is (usually) parsed by the IDerivativeLogic SyntheticId &lt;code&gt;getMargin&lt;/code&gt; function to set the collateral requirements of the option contract.&lt;br&gt;
&lt;code&gt;uint256 endTime&lt;/code&gt;: aka the maturity date of the contract. It is the point in time at which the buyers will have the right to exercise their contract.&lt;br&gt;
&lt;code&gt;uint256[] params&lt;/code&gt;: option contracts can differ greatly in the complexity of their financial requirements, as such Opium uses a dynamic array to ensure a high degree of flexibility to the consumers of the protocol, as to enable them to encode arbitrary parameters in their LibDerivative asset definition if needed. One convention to keep in mind is that, however, the first item of the &lt;code&gt;params&lt;/code&gt; array is always expected to be the strike price. The strike price is the value that determines the profitability of an option upon expiry: if the market price is above the strike price in case of a call option or the market price is below the strike price in the context of a put option, the option is said to be ‘in the money’ and the buyer stands to make a profit. Vice-versa, the option is said to be out of the money and the buyer stands to lose the premium or the collateral that they had to exchange for the ownership of the option contract.&lt;br&gt;
&lt;code&gt;oracleId&lt;/code&gt;: oracles are the entities that inform the Opium Protocol about the value of an asset upon its maturity date. The Opium Protocol does not enforce any specification as for what can be used as an oracle, be it on-chain or off-chain.&lt;br&gt;
&lt;code&gt;token&lt;/code&gt;: the address of the ERC20 token to be used as a collateral&lt;br&gt;
&lt;code&gt;syntheticId&lt;/code&gt;: the address of the contract where the financial logic of the derivative is encoded. The Opium Protocol expects the &lt;code&gt;syntheticId&lt;/code&gt; contracts to be compliant with the specifications of the &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/interfaces/IDerivativeLogic.sol"&gt;&lt;code&gt;IDerivativeLogic&lt;/code&gt; interface&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You might have noticed that the underlying asset of the option itself is not explicitly listed as a property of the struct: this is, yet again, to allow as much freedom as possible as to what can be used as an underlying for a contract. Had we done otherwise, the underlying's definition would have to be forcefully narrowed down to a uniform type that all the consumer SyntheticId contracts would have to adhere to. Furthermore, the strike price of an asset - whatever that asset may be- and the maturity of a contract are sufficient to carry on the execution of a derivative as long as the respective &lt;code&gt;oracleId&lt;/code&gt; is aware of which price feed to use to fetch the information about the relevant underlying after expiry.&lt;/p&gt;

&lt;p&gt;Now that we know how to encode the description of a financial asset in the Opium Protocol, the remaining piece of the puzzle is  how it's processed. &lt;br&gt;
As a developer, the two main user-facing contracts that you'll be interacting with are &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/core/Core.sol"&gt;Core&lt;/a&gt; and &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/core/OracleAggregator.sol"&gt;OracleAggregator&lt;/a&gt;.&lt;br&gt;
Each financial instrument on the Opium protocol consists of two main building blocks: the &lt;strong&gt;data layer&lt;/strong&gt; and the &lt;strong&gt;financial layer&lt;/strong&gt;.&lt;br&gt;
The OracleAggregator manages the data layer, which is responsible for informing the Opium Protocol about the pricing data required for the settlement of a &lt;code&gt;syntheticId&lt;/code&gt;. It does so by receiving the required data from a user-defined &lt;code&gt;oracleId&lt;/code&gt;, saving it in its own storage and then providing it on-demand to the Core contract.&lt;br&gt;
The Core contract, instead, manages the financial logic of a &lt;code&gt;syntheticId&lt;/code&gt; - which includes the creation of new syntheticId's LONG/SHORT positions, their execution and the distribution of payouts according to the syntheticId's own logic and the settlement data provided by the OracleAggregator.&lt;/p&gt;

&lt;p&gt;As you can see, each layer consists of a recipe made of a user-defined entity (&lt;code&gt;oracleId&lt;/code&gt;, &lt;code&gt;syntheticId&lt;/code&gt;) and an Opium v2 core contract which processes the related entity. The &lt;code&gt;oracleId&lt;/code&gt; will be processed by the &lt;code&gt;OracleAggregator&lt;/code&gt; and the &lt;code&gt;syntheticId&lt;/code&gt; will be processed by the &lt;code&gt;Core&lt;/code&gt; contract - via the SyntheticAggregator contract which acts as a caching middleware, but as an end developer you don't need to care about the implementation details!).&lt;/p&gt;
&lt;h3&gt;
  
  
  SyntheticId Life-Cycle
&lt;/h3&gt;

&lt;p&gt;In the Opium v2 main repository, we have set up an example of the above &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts"&gt;workflow&lt;/a&gt;.&lt;br&gt;
In order to run the end-to-end tests: &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2#local-development-setup-and-initialization"&gt;you can follow the instructions in the README to run them on an Ethereum Mainnet fork&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fng5i4h3ytbt4gpaow99u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fng5i4h3ytbt4gpaow99u.png" alt="opium-put-option-diagram" width="800" height="434"&gt;&lt;/a&gt;&lt;br&gt;
The e2e workflow example mocks an AAVE/ETH PUT option.&lt;br&gt;
At the time of writing AAVE is 0.06782ETH (currently ~212.90usd) and the strike price is set to 0.06819956ETH (currently ~220USD). &lt;br&gt;
Now, for the purpose of the current example, we are using the ERC20 mock &lt;code&gt;daiCollateralMock&lt;/code&gt; as a collateral, which we will assume, similarly to the original DAI, to be worth roughly 1usd. The &lt;code&gt;daiCollateralMock&lt;/code&gt;amount to purchase one position of our PUT option is set to 14e18. If you are interested in the topic of option pricing, a good benchmark to evaluate the fair value of an option is by using the &lt;a href="https://goodcalculators.com/black-scholes-calculator/"&gt;Black-Scholes formula&lt;/a&gt;.&lt;br&gt;
The e2e workflow comprises of a &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/test/mocks/oracles/ChainlinkOracleSubId.sol"&gt;OracleId&lt;/a&gt;, a &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/test/mocks/synthetics/OptionCallSyntheticIdMock.sol"&gt;SyntheticId&lt;/a&gt; and a &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/test/e2e/OptionController.sol"&gt;mock Controller contract to interact with Core&lt;/a&gt;.&lt;br&gt;
The derivative recipe sets the &lt;code&gt;oracleId&lt;/code&gt; address to a &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L79"&gt;an oracle contract which uses Chainlink&lt;/a&gt; to fetch the AAVE/ETH price-feed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    /// @param _derivativeEndTime uint256 the maturity of the derivative contract that uses ChainlinkOracleSubId as its oracleId
    function triggerCallback(uint256 _derivativeEndTime) external {
        // fetches the data and the timestamp from the Chainlink pricefeed
        (uint256 price, uint256 timestamp) = getLatestPrice();
        // fetches the Opium.OracleAggregator from the Opium.Registry
        IOracleAggregator oracleAggregator = registry.getProtocolAddresses().oracleAggregator;
        // logs the relevant event
        emit LogDataProvision(address(priceFeed), address(oracleAggregator), timestamp, price);
        // pushes the data into the OracleAggregator
        oracleAggregator.__callback(_derivativeEndTime, price);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L143"&gt;test-case shows&lt;/a&gt;, the oracleId's responsibility will be to provide the required data to the OracleAggregator upon maturity date - attempting to do it before will result in an error!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ensures that the oracleId correctly pushes the required pricefeed data into `Opium.OracleAggregator` upon the derivative's maturity&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// timetravel slightly after the maturity of the derivative contract&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;timeTravel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;derivative&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endTime&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// the derivative's oracleId pushes the data required to settle the option contract into the OracleAggregator&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chainlinkOracleSubId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;triggerCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;derivative&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endTime&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;receipt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;oracleSubIdEvent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decodeEvents&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChainlinkOracleSubId&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nx"&gt;chainlinkOracleSubId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;LogDataProvision&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;receipt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;oracleAggregator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chainlinkOracleSubId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;derivative&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endTime&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oracleSubIdEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wrong oracleAggregator data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;be&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;oracleAggregator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chainlinkOracleSubId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;derivative&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endTime&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, the derivative schema also sets the syntheticId field to a contract that implements the &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L77"&gt;IDerivativeLogic interface&lt;/a&gt;.&lt;br&gt;
At the heart of a syntheticId contract there is the &lt;code&gt;getExecutionPayout&lt;/code&gt; function, which is where the custom payout logic is encoded - and can be used to implement all kinds of financial requirements: from vanilla call/put options to more exotic products.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function getExecutionPayout(LibDerivative.Derivative memory _derivative, uint256 _result)
        external
        view
        override
        returns (uint256 buyerPayout, uint256 sellerPayout)
    {
        uint256 strikePrice = _derivative.params[0];
        // uint256 ppt = _derivative.params[1];  // Ignore PPT
        uint256 fixedPremium = _derivative.params[2];
        uint256 nominal = _derivative.margin;
        uint256 sellerMargin = (nominal * part) / BASE_PPT;

        // If result price is lower than strike price, buyer is paid out
        if (_result &amp;lt; strikePrice) {
            // buyer payout = margin * (strike price  - result) / strike price
            buyerPayout = nominal * (strikePrice - _result) / strikePrice;

            if (buyerPayout &amp;gt; sellerMargin) {
                buyerPayout = sellerMargin;
            }

            // seller payout = margin - buyer payout
            sellerPayout = sellerMargin - buyerPayout;
        } else {
            // buyer payout = 0
            buyerPayout = 0;

            // seller payout = margin
            sellerPayout = sellerMargin;
        }

        // Add fixed premium to seller payout
        sellerPayout = sellerPayout + fixedPremium;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The basic life-cycle of the derivative encompasses the following stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/contracts/test/e2e/OptionController.sol#L58"&gt;creation/minting of a derivative recipe's LONG/SHORT positions&lt;/a&gt; and &lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L92-L115"&gt;tests&lt;/a&gt;:&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L139-L154"&gt;data provision&lt;/a&gt; from the OracleId to the OracleAggregator.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/OpiumProtocol/opium-protocol-v2/blob/main/test/unit-tests/e2e/index.ts#L161-L162"&gt;execution&lt;/a&gt; of the derivative positions and the distribution of payouts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have reached this far, congratulations! &lt;br&gt;
You now know enough to start building on top of Opium v2 and be eligible for a developer grant.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Opium
&lt;/h2&gt;

&lt;p&gt;Opium Protocol is a universal and robust DeFi protocol that allows for creating, settling, and trading decentralized derivatives.&lt;br&gt;
&lt;a href="https://docs.opium.network/"&gt;Explore Opium Protocol&lt;/a&gt; or try out &lt;a href="https://opium.finance/"&gt;Opium Finance&lt;/a&gt;.&lt;br&gt;
Stay informed and follow &lt;a href="https://twitter.com/Opium_Network"&gt;Opium.Team on Twitter&lt;/a&gt;.&lt;br&gt;
Did you know that you can subscribe to our &lt;a href="https://t.me/OpiumFinance"&gt;News Channel&lt;/a&gt; to get more exciting news delivered to your morning coffee?&lt;/p&gt;

</description>
      <category>defi</category>
      <category>solidity</category>
      <category>ethereum</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
