<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>aolin</title>
        <link>https://paragraph.com/@aolin</link>
        <description>smart contract &amp; web developer</description>
        <lastBuildDate>Thu, 30 Apr 2026 06:48:12 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>aolin</title>
            <url>https://storage.googleapis.com/papyrus_images/07b79ab2793b315a414a48575e2991d7350a91cf92660e9d5170e244b6c2c8d6.png</url>
            <link>https://paragraph.com/@aolin</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Sparky: Your LLM-Based DEX-Trading Agent]]></title>
            <link>https://paragraph.com/@aolin/sparky-your-llm-based-dex-trading-agent</link>
            <guid>k3nUL02bxS1MukE9lJul</guid>
            <pubDate>Wed, 24 Jan 2024 07:38:36 GMT</pubDate>
            <description><![CDATA[Sparky is a LLM-based swap agent, it is equipped with injective blockchain knowledges and built-in smart wallets to assist users in decision making and DEX trading.Explore Web3 with LLMWe implement a custom LLM with web3 knowledge and teach it how to interact with smart contracts by injecting external dataset, including research papers, crypto metrics and on-chain data, as indexing, retrieval and context injection. The process is also known as RAG (Retrieval Augmentation Generation), which al...]]></description>
            <content:encoded><![CDATA[<blockquote><p><em>Sparky is a LLM-based swap agent, it is equipped with injective blockchain knowledges and built-in smart wallets to assist users in decision making and DEX trading.</em></p></blockquote><h2 id="h-explore-web3-with-llm" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Explore Web3 with LLM</h2><p>We implement a custom LLM with web3 knowledge and teach it how to interact with smart contracts by injecting external dataset, including research papers, crypto metrics and on-chain data, as indexing, retrieval and context injection. The process is also known as RAG (Retrieval Augmentation Generation), which allows Sparky better adapt to decentralized network and assist users in making informed investment decision.</p><p>Sparky classifies user intent into purpose of general queries and contract interaction requests, the former is handled by LLM directly while the latter will trigger actions to form transactions through built-in smart wallets on behalf of clients.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b34e6b175aa9a7df3878d5ea33d218ca9340f4822d8c9d82a296c5b7a4494688.png" alt="Figure 1. Custom LLM with RAG" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 1. Custom LLM with RAG</figcaption></figure><h2 id="h-reset-ux" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Reset UX</strong></h2><p>Sparky innovates the way sending transactions through built-in MPC &amp; AA wallets. Users do not need to care about transactions, gas, protocols and other complex underlying concepts: just tell the agent what they want and the agent will handle the rest.</p><p>There are two types wallets in Sparky: smart contract wallet and multi-party computation wallet. The smart contract wallet is responsible for interacting with external protocols and storing client assets, it is managed by TSS-based signatures from MPC wallet with 2/3 factors strategies which enables self-custody and social login: One factor is hosted in the cloud and can be retrieved through OAuth, while the other two factors are stored on the user&apos;s device (e.g., in browser local storage) and serve as backups, respectively.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/25b8ed53476368a5b3012797e19f1603ca154533433bb0f28db3787c5f31cab2.png" alt="Figure 2. Built-in wallets" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 2. Built-in wallets</figcaption></figure><p>With recognized user intent for interacting with smart contracts, Sparky will generate corresponding UserOperation and request user signature. The bundler will simulate the transaction and call EntryPoint contract to 1) deploy smart account if not yet, 2) validate UserOperation, 3) forward and execute call-data and 4) calculate and charge gas after operation. This is a standard EIP-4337 compatible scheme to benefit users from flexible gas option and customized operations.</p><h2 id="h-boost-transactions" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Boost Transactions</strong></h2><p>To further facilitate user experience with DEX-Trading, Sparky deployed a monitor service for mempool to offer MEV extraction and protection service along with MEV-boost. Users are allowed to choose private mode to prevent exploitation during mempool stage, place on-chain limit order to swap at a fixed-rate, or execute copy-trading and front-running at their targeting address. In all, Sparky integrates bot services and make it a smart and powerful agent for DEX uses.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a019d4af012907266ba4a16bd1e77371d1950291dc44a6be55ec83f1ac086e73.png" alt="Figure 3. Monitor service" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 3. Monitor service</figcaption></figure>]]></content:encoded>
            <author>aolin@newsletter.paragraph.com (aolin)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/4ed0dd9d2aee1bbd2badbfee56c5bd6a03cc0dd38db43b6b3c3fb2632bc2f64c.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Project Wyvern: Everything You Should Know Behind OpenSea]]></title>
            <link>https://paragraph.com/@aolin/project-wyvern-everything-you-should-know-behind-opensea</link>
            <guid>UwHUhrrocTwKDB8Jrdih</guid>
            <pubDate>Mon, 09 May 2022 08:03:44 GMT</pubDate>
            <description><![CDATA[IntroductionWyvern is the name of smart contracts that allows OpenSea and perhaps other Non-fungible-Token marketplaces to trade NFTs in Ethers or ERC20 tokens. The lifecycle of NFT trading is closely associated with orders: they are created, stored and paired within the web server while got verified and executed on the blockchain.Figure 1. NFT-Marketplace Brief StructureAbove shows the brief architecture of a NFT marketplace and here are steps to process a transaction:Create and sign orders ...]]></description>
            <content:encoded><![CDATA[<h2 id="h-introduction" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Introduction</h2><p>Wyvern is the name of smart contracts that allows OpenSea and perhaps other Non-fungible-Token marketplaces to trade NFTs in Ethers or ERC20 tokens. The lifecycle of NFT trading is closely associated with orders: they are created, stored and paired within the web server while got verified and executed on the blockchain.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2a35cd41060a1eb4ae5a7ca707255282db20aa98cc5146602725406571580f5a.jpg" alt="Figure 1. NFT-Marketplace Brief Structure" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 1. NFT-Marketplace Brief Structure</figcaption></figure><p>Above shows the brief architecture of a NFT marketplace and here are steps to process a transaction:</p><ol><li><p>Create and sign orders in website.</p></li><li><p>Pair orders and transact to contract</p></li><li><p>Verify and execute orders</p></li></ol><h2 id="h-order-structure" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Order Structure</h2><p>Order is defined as struct in Solidity, it contains everything that smart contracts need to know to execute the trading. For example, <strong>maker</strong> is address that made the order, to execute an order, this address is required to be recovered using ecrecover in smart contracts (so the off-chain created order becomes tamper-resistant). Fees including <strong>relayerFee</strong> and <strong>protocolFee</strong> describe how royalty and fees are calculated. Sale <strong>side</strong> marks whether this order from a buyer or seller, <strong>saleKind</strong> shows whether the order is a fixed-price type or auction type (their execution logic might be different). <strong>Target</strong>, <strong>howToCall</strong>, <strong>calldata and replacementPattern</strong> record how to make an external call when the payment is done, while <strong>paymentToken</strong> and <strong>basePrice</strong> refer to the token and the price that a buyer or a seller is going to offer or accept. Other values provide additional checks, details can be viewed at <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ProjectWyvern/wyvern-ethereum/blob/master/contracts/exchange/ExchangeCore.sol">github</a>.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/35ca7f9aba04169a9956e853fefe219650281a6cb25ef4f877827be0e30f8560.png" alt="Figure 2. Order struct" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 2. Order struct</figcaption></figure><h2 id="h-create-and-sign-orders-in-web-application" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Create and Sign Orders in Web Application</h2><p>Order is created in front-end as a JavaScript object, to sign it, we need to encode its parameters into a byte array under certain rules defined in smart contract and use wallet to sign its keccak256 hash value by secp256k1.</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://eips.ethereum.org/EIPS/eip-712">EIP712</a> proposes a way to hash and sign typed data to offer a clear view on what data to sign in wallets rather than an unrecognizable hash value. The overall encoding pattern is <code>\x19\x01&lt;DOMAIN_SEPARATOR&gt;&lt;ORDER_HASH&gt;</code></p><p>where <code>DOMAIN_SEPARATOR</code> is the keccak256 hash value of abi.encoding of contractName, contractVersion, chainId and the contract address with a prefix TYPE_HASH (indicating above value type and name).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/019e6ecc26aae55feba288e57b9dedd6db2cb94d3cd6e64e70e68a27333426d9.jpg" alt="Figure 3. Domain separator" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 3. Domain separator</figcaption></figure><p><code>ORDER_HASH</code> is the keccak256 hash value of the abi.encoding of all its parameters with a prefix TYPE_HASH. (in Solidity abi.encoding adds ZEROs to 32 bytes for value type and hashes to 32 bytes for reference type).</p><p>After orders and their signatures are generated, they are stored in database instead of writing to smart contracts. The 65 bytes signature can 1) make sure the order is generated by its encoded order maker 2) guarantee the order not to be overwritten before it is executed in the blockchain. It helps cut significant gas costs for users.</p><p>In addition, cancelling of an order requires users to transact to the blockchain to disable the order status. All orders are by default enabled, simply taking them down from the website cannot guarantee these orders won’t be occasionally executed since all orders are technically public, they can be retrieved, stored and sent to the smart contract without any permissions.</p><h2 id="h-verify-and-execute-orders-in-smart-contract" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Verify and Execute Orders in Smart Contract</h2><p>Wyvern contact takes five parameters to match and execute orders. Orders and signatures are necessary to process the trading, metadata will be emitted in the event to notify the web application.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a2e8b4460b4d1cc35aa398c6d34c47a65a0beb6872e74856b50a1a7cfa164763.png" alt="Figure 4. Transact to contract" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 4. Transact to contract</figcaption></figure><p>There are four steps inside Wyvern to match and execute orders.</p><ol><li><p>Check signatures (by ecrecover)</p></li><li><p>Check whether orders can match</p></li><li><p>Transfer funds from buyer to seller (with royalties and fees)</p></li><li><p>Transfer NFTs from seller to buyer</p></li></ol><p>You might notice in OpenSea and perhaps other platforms, it seems a bit weird that orders can be settled to execute a transfer of an existing token of any given contract address even they apply different standards (either ERC721 or ERC1155), or even a transfer of an un-minted token in their public sale. Indeed, Wyvern exchange supports arbitrary transaction: when the buyer pays the seller some payment tokens, Wyvern contracts will make an external call to target address through seller’s registered proxy contract to settle the transaction. The behavior of this external call is defined in order parameters and encoded in web application outside the contact.</p><p>For example, if a seller want to sell his NFT, part of his order that describes the external call should like this:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e472fe9ef12015b4f76cc38d7fa3506bcb471dac16e7c74d02296b763b88a3d7.jpg" alt="Figure 5. How to describe an external call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 5. How to describe an external call</figcaption></figure><ul><li><p><strong>target</strong> indicates nft token contract address that Wyvern should calls</p></li><li><p><strong>howToCall</strong> is the type of the external call (there are three types of calls in Solidity: call, static call and delegate call)</p></li><li><p><strong>calldata</strong> is the byte array that Wyvern contract uses while calling the target (in the example. this calldata should be the abi.encoding of transferFrom function. The first four bytes is the function signature, with three parameters each occupies 32 bytes)</p></li><li><p><strong>replacePattern</strong> describes which part of byte array (above calldata) could be replaced by another byte array (opposite order’s calldata) and which part should be protected. When seller places a sell order, the buyer address is unpredictable, the byte array in sell order’s calldata that describes buyer address is meaningless and should be replaced by the one in the buy order.</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1fa9c0ec0a4cbd23b2e9dc02751a48424859a586b7bddab089399feb8bd9345d.jpg" alt="Figure 6. Guarded array replacement" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 6. Guarded array replacement</figcaption></figure><p>Above shows how sell_order_calldata is replaced by buy_order_calldata with a bitmask (sell_order_replacePattern). The replacement process is calculated conceptually: <code>array[i] = (!mask[i] &amp;&amp; array[i]) || (mask[i] &amp;&amp; desired[i]).</code> Basically, in each byte if the replacement pattern is 0xff, we replace the original byte with the desired one, if the replacement pattern is 0x00 we keep original byte unchanged. By doing this, we can obtain the integral calldata from paired orders which is exactly the abi.encoding of <code>transferFrom(seller_address, buyer_address, tokenId)</code></p><p>This strategy that uses calldata and replacement pattern derived outside the blockchain enables Wyvern to execute arbitrary transactions (transfer or mint of ERC721 and ERC1155 e.g.), however, it brings a critical issue: Wyvern could not justify the legitimacy of this transaction, in other word, orders could be manipulated to ask Wyvern to transfer a token that does not belong to the seller, that is why we do not approve Wyvern to use our tokens directly but approve an independent proxy contract instead.</p><p>Users are required to deploy a proxy contract from registry contract during their first sale in OpenSea (each address owns one proxy) and approve the proxy contract to use their NFTs. When Wyvern is about to make an external call in a transaction, it will forward the external call to the order seller’s proxy, and ask the proxy contract to execute the final transaction (e.g. transfer of a ERC721 token). Even Wyvern could not resolve and verify the legitimacy of the calldata, an invalid transfer request will be reverted as the proxy contract cannot transfer NFTs that the seller does not own.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a513f7f48f22ad0584277baf15ac20e8b9eea97172b39a6e751eeb14534db281.jpg" alt="Figure 7. Proxy and Registry" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Figure 7. Proxy and Registry</figcaption></figure>]]></content:encoded>
            <author>aolin@newsletter.paragraph.com (aolin)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/d14f05afddedbdde197629e01df9e3694e06e776f8ea7890ce12b6edbeb9bd63.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>