1:HL["/_next/static/media/2d141e1a38819612-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 2:HL["/_next/static/css/b5cc68180eb3d7c9.css","style"] 0:["H9QFxhU8v5-ruYvcNfUKt",[[["",{"children":["blog",{"children":[["slug","zephyr-pre-alpha-preview","c"],{"children":["__PAGE__?{\"slug\":[\"zephyr-pre-alpha-preview\"]}",{}]}]}]},"$undefined","$undefined",true],"$L3",[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/b5cc68180eb3d7c9.css","precedence":"next"}]],"$L4"]]]] 5:HL["/_next/static/css/dfa98ec29d4bb4d3.css","style"] 6:I{"id":7516,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"ThemeProviders","async":false} 7:I{"id":4244,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"","async":false} 8:I{"id":8251,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"KBarSearchProvider","async":false} 9:I{"id":4724,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","964:static/chunks/964-256e2702ddb0b4bf.js","797:static/chunks/app/blog/[...slug]/page-6aeac4f36de46831.js"],"name":"","async":false} a:I{"id":7005,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"KBarButton","async":false} b:I{"id":7074,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"","async":false} c:I{"id":7365,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","998:static/chunks/998-271f973ed8f19b4a.js","185:static/chunks/app/layout-0d5bd8edaec8d1ef.js"],"name":"","async":false} d:I{"id":1443,"chunks":["272:static/chunks/webpack-099e1b11ae967685.js","971:static/chunks/fd9d1056-80ea045f608d9add.js","864:static/chunks/864-65256e9be0d5c062.js"],"name":"","async":false} e:I{"id":8639,"chunks":["272:static/chunks/webpack-099e1b11ae967685.js","971:static/chunks/fd9d1056-80ea045f608d9add.js","864:static/chunks/864-65256e9be0d5c062.js"],"name":"","async":false} 4:[["$","meta","0",{"charSet":"utf-8"}],["$","title","1",{"children":"Writing the First Zephyr Program: Zephyr VM + Mercury Integration Preview. | xyclooLabs Blog"}],["$","meta","2",{"name":"description","content":"Testing out the first working version of the Zephyr VM + Mercury integration."}],["$","meta","3",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","4",{"name":"robots","content":"index, follow"}],["$","meta","5",{"name":"googlebot","content":"index, follow, max-video-preview:-1, max-image-preview:large, max-snippet:-1"}],["$","link","6",{"rel":"canonical","href":"https://blog.xycloo.com/blog/zephyr-pre-alpha-preview"}],["$","link","7",{"rel":"alternate","type":"application/rss+xml","href":"https://blog.xycloo.com/feed.xml"}],["$","meta","8",{"property":"og:title","content":"Writing the First Zephyr Program: Zephyr VM + Mercury Integration Preview."}],["$","meta","9",{"property":"og:description","content":"Testing out the first working version of the Zephyr VM + Mercury integration."}],["$","meta","10",{"property":"og:url","content":"https://blog.xycloo.com/blog/zephyr-pre-alpha-preview"}],["$","meta","11",{"property":"og:site_name","content":"xyclooLabs Blog"}],["$","meta","12",{"property":"og:locale","content":"en_US"}],["$","meta","13",{"property":"og:image","content":"https://blog.xycloo.com/static/images/twitter-card.png"}],["$","meta","14",{"property":"og:type","content":"article"}],["$","meta","15",{"property":"article:published_time","content":"2023-10-19T00:00:00.000Z"}],["$","meta","16",{"property":"article:modified_time","content":"2023-10-18T22:00:00.000Z"}],["$","meta","17",{"property":"article:author","content":"Tommaso"}],["$","meta","18",{"name":"twitter:card","content":"summary_large_image"}],["$","meta","19",{"name":"twitter:title","content":"Writing the First Zephyr Program: Zephyr VM + Mercury Integration Preview."}],["$","meta","20",{"name":"twitter:description","content":"Testing out the first working version of the Zephyr VM + Mercury integration."}],["$","meta","21",{"name":"twitter:image","content":"https://blog.xycloo.com/static/images/twitter-card.png"}],["$","meta","22",{"name":"next-size-adjust"}]] 3:[null,["$","html",null,{"lang":"en-us","className":"__variable_587f35 scroll-smooth","suppressHydrationWarning":true,"children":[["$","link",null,{"rel":"apple-touch-icon","sizes":"76x76","href":"/static/favicons/apple-touch-icon.png"}],["$","link",null,{"rel":"icon","type":"image/png","sizes":"32x32","href":"/static/images/logo.png"}],["$","link",null,{"rel":"icon","type":"image/png","sizes":"16x16","href":"/static/favicons/logo.png"}],["$","link",null,{"rel":"manifest","href":"/static/favicons/site.webmanifest"}],["$","link",null,{"rel":"mask-icon","href":"/static/favicons/safari-pinned-tab.svg","color":"#5bbad5"}],["$","meta",null,{"name":"msapplication-TileColor","content":"#000000"}],["$","meta",null,{"name":"theme-color","media":"(prefers-color-scheme: light)","content":"#fff"}],["$","meta",null,{"name":"theme-color","media":"(prefers-color-scheme: dark)","content":"#000"}],["$","link",null,{"rel":"alternate","type":"application/rss+xml","href":"/feed.xml"}],["$","body",null,{"className":"bg-white text-black antialiased dark:bg-gray-950 dark:text-white","children":["$","$L6",null,{"children":[["$undefined","$undefined","$undefined",["$","$L7",null,{"async":true,"defer":true,"data-website-id":"$undefined","src":"https://analytics.umami.is/script.js"}],"$undefined"],["$","section",null,{"className":"mx-auto max-w-3xl px-4 sm:px-6 xl:max-w-5xl xl:px-0","children":["$","div",null,{"className":"flex h-screen flex-col justify-between font-sans","children":[["$","$L8",null,{"kbarConfig":{"searchDocumentsPath":"search.json"},"children":[["$","header",null,{"className":"flex items-center justify-between py-10","children":[["$","div",null,{"children":["$","$L9",null,{"href":"/","aria-label":"xyclooLabs Blog","children":["$","div",null,{"className":"flex items-center justify-between","children":[["$","div",null,{"className":"mr-3","children":["$","img",null,{"className":"w-10","src":"../../static/images/logo.png"}]}],["$","div",null,{"className":"hidden h-6 text-2xl font-semibold sm:block","children":"xyclooLabs Blog"}]]}]}]}],["$","div",null,{"className":"flex items-center leading-5 space-x-4 sm:space-x-6","children":[[["$","$L9",null,{"href":"/blog","className":"hidden sm:block font-medium text-gray-900 dark:text-gray-100","children":"All Posts"}],["$","a",null,{"target":"_blank","rel":"noopener noreferrer","href":"https://xycloo.com","className":"hidden sm:block font-medium text-gray-900 dark:text-gray-100","children":"About"}]],["$","$La",null,{"aria-label":"Search","children":["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","fill":"none","viewBox":"0 0 24 24","strokeWidth":1.5,"stroke":"currentColor","className":"text-gray-900 dark:text-gray-100 h-6 w-6","children":["$","path",null,{"strokeLinecap":"round","strokeLinejoin":"round","d":"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"}]}]}],["$","$Lb",null,{}],["$","$Lc",null,{}]]}]]}],["$","main",null,{"className":"mb-auto","children":["$","$Ld",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$Le",null,{}],"templateStyles":"$undefined","notFound":["$","div",null,{"className":"flex flex-col items-start justify-start md:mt-24 md:flex-row md:items-center md:justify-center md:space-x-6","children":[["$","div",null,{"className":"space-x-2 pb-8 pt-6 md:space-y-5","children":["$","h1",null,{"className":"text-6xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 md:border-r-2 md:px-6 md:text-8xl md:leading-14","children":"404"}]}],["$","div",null,{"className":"max-w-md","children":[["$","p",null,{"className":"mb-4 text-xl font-bold leading-normal md:text-2xl","children":"Sorry we couldn't find this page."}],["$","p",null,{"className":"mb-8","children":"But dont worry, you can find plenty of other things on our homepage."}],["$","$L9",null,{"href":"/","className":"focus:shadow-outline-blue inline rounded-lg border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium leading-5 text-white shadow transition-colors duration-150 hover:bg-blue-700 focus:outline-none dark:hover:bg-blue-500","children":"Back to homepage"}]]}]]}],"notFoundStyles":[],"childProp":{"current":["$","$Ld",null,{"parallelRouterKey":"children","segmentPath":["children","blog","children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$Le",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$","$Ld",null,{"parallelRouterKey":"children","segmentPath":["children","blog","children",["slug","zephyr-pre-alpha-preview","c"],"children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$Le",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$Lf","$L10",null],"segment":"__PAGE__?{\"slug\":[\"zephyr-pre-alpha-preview\"]}"},"styles":[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/dfa98ec29d4bb4d3.css","precedence":"next"}]]}],"segment":["slug","zephyr-pre-alpha-preview","c"]},"styles":[]}],"segment":"blog"},"styles":[]}]}]]}],["$","footer",null,{"children":["$","div",null,{"className":"mt-16 flex flex-col items-center","children":[["$","div",null,{"className":"mb-3 flex space-x-4","children":[["$","a",null,{"className":"text-sm text-gray-500 transition hover:text-gray-600","target":"_blank","rel":"noopener noreferrer","href":"mailto:hello@xycloo.com","children":[["$","span",null,{"className":"sr-only","children":"mail"}],["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","viewBox":"0 0 20 20","className":"fill-current text-gray-700 hover:text-primary-500 dark:text-gray-200 dark:hover:text-primary-400 h-6 w-6","children":[["$","path",null,{"d":"M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z"}],["$","path",null,{"d":"M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z"}]]}]]}],["$","a",null,{"className":"text-sm text-gray-500 transition hover:text-gray-600","target":"_blank","rel":"noopener noreferrer","href":"https://github.com/xycloo","children":[["$","span",null,{"className":"sr-only","children":"github"}],["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","viewBox":"0 0 24 24","className":"fill-current text-gray-700 hover:text-primary-500 dark:text-gray-200 dark:hover:text-primary-400 h-6 w-6","children":["$","path",null,{"d":"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"}]}]]}],null,null,null,["$","a",null,{"className":"text-sm text-gray-500 transition hover:text-gray-600","target":"_blank","rel":"noopener noreferrer","href":"https://twitter.com/xycloolabs","children":[["$","span",null,{"className":"sr-only","children":"twitter"}],["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","viewBox":"0 0 24 24","className":"fill-current text-gray-700 hover:text-primary-500 dark:text-gray-200 dark:hover:text-primary-400 h-6 w-6","children":["$","path",null,{"d":"M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"}]}]]}]]}],["$","div",null,{"className":"mb-2 flex space-x-2 text-sm text-gray-500 dark:text-gray-400","children":[["$","div",null,{"children":"xyclooLabs team"}],["$","div",null,{"children":" • "}],["$","div",null,{"children":"© 2024"}],["$","div",null,{"children":" • "}],["$","$L9",null,{"href":"/","children":"xyclooLabs Blog"}]]}]]}]}]]}]}]]}]}]]}],null] 11:I{"id":9315,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","964:static/chunks/964-256e2702ddb0b4bf.js","797:static/chunks/app/blog/[...slug]/page-6aeac4f36de46831.js"],"name":"","async":false} 12:I{"id":2529,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","964:static/chunks/964-256e2702ddb0b4bf.js","797:static/chunks/app/blog/[...slug]/page-6aeac4f36de46831.js"],"name":"","async":false} 13:I{"id":5397,"chunks":["724:static/chunks/724-ae4ae561ef8e5138.js","964:static/chunks/964-256e2702ddb0b4bf.js","797:static/chunks/app/blog/[...slug]/page-6aeac4f36de46831.js"],"name":"","async":false} 10:[["$","script",null,{"type":"application/ld+json","dangerouslySetInnerHTML":{"__html":"{\"@context\":\"https://schema.org\",\"@type\":\"BlogPosting\",\"headline\":\"Writing the First Zephyr Program: Zephyr VM + Mercury Integration Preview.\",\"datePublished\":\"2023-10-19T00:00:00.000Z\",\"dateModified\":\"2023-10-18T22:00:00.000Z\",\"description\":\"Testing out the first working version of the Zephyr VM + Mercury integration.\",\"image\":\"/static/images/twitter-card.png\",\"url\":\"https://blog.xycloo.com/blog/zephyr-pre-alpha-preview\",\"author\":[{\"@type\":\"Person\",\"name\":\"Tommaso\"}]}"}}],["$","section",null,{"className":"mx-auto max-w-3xl px-4 sm:px-6 xl:max-w-5xl xl:px-0","children":[["$","$L11",null,{}],["$","article",null,{"children":["$","div",null,{"className":"xl:divide-y xl:divide-gray-200 xl:dark:divide-gray-700","children":[["$","header",null,{"className":"pt-6 xl:pb-6","children":["$","div",null,{"className":"space-y-1 text-center","children":[["$","dl",null,{"className":"space-y-10","children":["$","div",null,{"children":[["$","dt",null,{"className":"sr-only","children":"Published on"}],["$","dd",null,{"className":"text-base font-medium leading-6 text-gray-500 dark:text-gray-400","children":["$","time",null,{"dateTime":"2023-10-19T00:00:00.000Z","children":"Thursday, October 19, 2023"}]}]]}]}],["$","div",null,{"children":["$","h1",null,{"className":"text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-5xl md:leading-14","children":"Writing the First Zephyr Program: Zephyr VM + Mercury Integration Preview."}]}]]}]}],["$","div",null,{"className":"grid-rows-[auto_1fr] divide-y divide-gray-200 pb-8 dark:divide-gray-700 xl:grid xl:grid-cols-4 xl:gap-x-6 xl:divide-y-0","children":[["$","dl",null,{"className":"pb-10 pt-6 xl:border-b xl:border-gray-200 xl:pt-11 xl:dark:border-gray-700","children":[["$","dt",null,{"className":"sr-only","children":"Authors"}],["$","dd",null,{"children":["$","ul",null,{"className":"flex flex-wrap justify-center gap-4 sm:space-x-12 xl:block xl:space-x-0 xl:space-y-8","children":[["$","li","Tommaso",{"className":"flex items-center space-x-2","children":["$undefined",["$","dl",null,{"className":"whitespace-nowrap text-sm font-medium leading-5","children":[["$","dt",null,{"className":"sr-only","children":"Name"}],["$","dd",null,{"className":"text-gray-900 dark:text-gray-100","children":"Tommaso"}],["$","dt",null,{"className":"sr-only","children":"Twitter"}],["$","dd",null,{"children":["$","a",null,{"target":"_blank","rel":"noopener noreferrer","href":"https://twitter.com/heytdep","className":"text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":"@heytdep"}]}]]}]]}]]}]}]]}],["$","div",null,{"className":"divide-y divide-gray-200 dark:divide-gray-700 xl:col-span-3 xl:row-span-2 xl:pb-0","children":[["$","div",null,{"className":"prose max-w-none pb-8 pt-10 dark:prose-invert","children":[["$","img",null,{"src":"../static/images/zephyr_lp.png"}],["$","h1",null,{"id":"introduction","children":[["$","a",null,{"href":"#introduction","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Introduction"]}],["$","p",null,{"children":["We ",["$","$L9",null,{"href":"/blog/introducing-zephyr","children":"announced the Zephyr VM"}]," about a couple of weeks ago. If you haven't already, we recommend giving a quick read at the Zephyr announcement before reading this blog post."]}],["$","p",null,{"children":"Today, we have no announcements, just a preview of what we have developed so far: we will write, compile and deploy to Mercury the first public Zephyr application!"}],["$","blockquote",null,{"children":["$","p",null,{"children":"The contents of this article are written based on code, SDKs and functionalities that are not public yet, thus you won't be able to emulate what I'm doing here. This post serves the purpose of introducing interested users and developers to the anatomy of a Zephyr program and what the current progress is."}]}],["$","p",null,{"children":"Also, stay tuned on X as we will publish a video walkthrough of what's going on here where I'll be explaining some stuff about Zephyr and try out live the deployment and result of this Zephyr program."}],["$","p",null,{"children":"We are also thinking of making live stream challenges for writing Zephyr programs"}],["$","h1",null,{"id":"creating-the-application","children":[["$","a",null,{"href":"#creating-the-application","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Creating the Application"]}],["$","p",null,{"children":["We want to write a Zephyr program that is simple for demonstrative purposes, but that also showcases one of the use cases of Zephyr: ",["$","strong",null,{"children":"custom data manipulation"}],"."]}],["$","h2",null,{"id":"idea","children":[["$","a",null,{"href":"#idea","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Idea"]}],["$","p",null,{"children":"Imagine for a minute that we are a liquidity pools protocol; we would like a way of querying prices for every ledger (assuming that they changed) and also the volume of our pools. This requires us to put our hands on the data (i.e manipulate) before it gets saved on the database as we need to calculate prices and volume. That is because we want to get prices and volume directly, so we don't want to subscribe to instance, query and decode it, map the keys and perform the calculations client side."}],["$","p",null,{"children":"Additionally, we want to be able to form queries along the lines of:"}],["$","$L12",null,{"className":"language-graphql","children":["$","code",null,{"className":"code-highlight language-graphql","children":[["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"query"}]," ",["$","span",null,{"className":"token function definition-query","children":"Prices"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token object","children":"allPrices"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token object","children":"nodes"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"a"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"b"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"volume"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"ledger"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}]]}]}],["$","p",null,{"children":["Where ",["$","code",null,{"children":"a"}]," and ",["$","code",null,{"children":"b"}]," is the price of the respective token. This would allow us to have a convenient query that is consistent across all clients. We can easily achieve this behaviour by writing a Zephyr program and deploying it on Mercury."]}],["$","blockquote",null,{"children":["$","p",null,{"children":"Note that this is a very simple application of Zephyr, which also doesn't use all the fuctionalities that this experimental version provides such as reading from the database for multi-step workflows."}]}],["$","h2",null,{"id":"theory","children":[["$","a",null,{"href":"#theory","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Theory"]}],["$","p",null,{"children":"We know what we want, and that's great! Now it's time to understand how to go about it in our Zephyr application."}],["$","p",null,{"children":["First, we need to understand what data we want. To calculate prices and the volume we can easily rely on the two reserves (a, b) of a ",["$","a",null,{"target":"_blank","rel":"noopener noreferrer","href":"https://github.com/stellar/soroban-examples/tree/main/liquidity_pool","children":"Soroban liquidity pool"}],":"]}],["$","ul",null,{"children":[["$","li",null,{"children":["price of a is ",["$","span",null,{"className":"math math-inline","children":["$","span",null,{"className":"katex","children":[["$","span",null,{"className":"katex-mathml","children":["$","math",null,{"xmlns":"http://www.w3.org/1998/Math/MathML","children":["$","semantics",null,{"children":[["$","mrow",null,{"children":["$","mfrac",null,{"children":[["$","mi",null,{"children":"b"}],["$","mi",null,{"children":"a"}]]}]}],["$","annotation",null,{"encoding":"application/x-tex","children":"\\frac{b}{a}"}]]}]}]}],["$","span",null,{"className":"katex-html","aria-hidden":"true","children":["$","span",null,{"className":"base","children":[["$","span",null,{"className":"strut","style":{"height":"1.2251em","verticalAlign":"-.345em"}}],["$","span",null,{"className":"mord","children":[["$","span",null,{"className":"nulldelimiter mopen"}],["$","span",null,{"className":"mfrac","children":["$","span",null,{"className":"vlist-t vlist-t2","children":[["$","span",null,{"className":"vlist-r","children":[["$","span",null,{"className":"vlist","style":{"height":".8801em"},"children":[["$","span",null,{"style":{"top":"-2.655em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"mtight reset-size6 size3 sizing","children":["$","span",null,{"className":"mtight mord","children":["$","span",null,{"className":"mtight mord mathnormal","children":"a"}]}]}]]}],["$","span",null,{"style":{"top":"-3.23em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"frac-line","style":{"borderBottomWidth":".04em"}}]]}],["$","span",null,{"style":{"top":"-3.394em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"mtight reset-size6 size3 sizing","children":["$","span",null,{"className":"mtight mord","children":["$","span",null,{"className":"mtight mord mathnormal","children":"b"}]}]}]]}]]}],["$","span",null,{"className":"vlist-s","children":"​"}]]}],["$","span",null,{"className":"vlist-r","children":["$","span",null,{"className":"vlist","style":{"height":".345em"},"children":["$","span",null,{}]}]}]]}]}],["$","span",null,{"className":"nulldelimiter mclose"}]]}]]}]}]]}]}]]}],["$","li",null,{"children":["price of b is ",["$","span",null,{"className":"math math-inline","children":["$","span",null,{"className":"katex","children":[["$","span",null,{"className":"katex-mathml","children":["$","math",null,{"xmlns":"http://www.w3.org/1998/Math/MathML","children":["$","semantics",null,{"children":[["$","mrow",null,{"children":["$","mfrac",null,{"children":[["$","mi",null,{"children":"a"}],["$","mi",null,{"children":"b"}]]}]}],["$","annotation",null,{"encoding":"application/x-tex","children":"\\frac{a}{b}"}]]}]}]}],["$","span",null,{"className":"katex-html","aria-hidden":"true","children":["$","span",null,{"className":"base","children":[["$","span",null,{"className":"strut","style":{"height":"1.0404em","verticalAlign":"-.345em"}}],["$","span",null,{"className":"mord","children":[["$","span",null,{"className":"nulldelimiter mopen"}],["$","span",null,{"className":"mfrac","children":["$","span",null,{"className":"vlist-t vlist-t2","children":[["$","span",null,{"className":"vlist-r","children":[["$","span",null,{"className":"vlist","style":{"height":".6954em"},"children":[["$","span",null,{"style":{"top":"-2.655em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"mtight reset-size6 size3 sizing","children":["$","span",null,{"className":"mtight mord","children":["$","span",null,{"className":"mtight mord mathnormal","children":"b"}]}]}]]}],["$","span",null,{"style":{"top":"-3.23em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"frac-line","style":{"borderBottomWidth":".04em"}}]]}],["$","span",null,{"style":{"top":"-3.394em"},"children":[["$","span",null,{"className":"pstrut","style":{"height":"3em"}}],["$","span",null,{"className":"mtight reset-size6 size3 sizing","children":["$","span",null,{"className":"mtight mord","children":["$","span",null,{"className":"mtight mord mathnormal","children":"a"}]}]}]]}]]}],["$","span",null,{"className":"vlist-s","children":"​"}]]}],["$","span",null,{"className":"vlist-r","children":["$","span",null,{"className":"vlist","style":{"height":".345em"},"children":["$","span",null,{}]}]}]]}]}],["$","span",null,{"className":"nulldelimiter mclose"}]]}]]}]}]]}]}]]}],["$","li",null,{"children":"volume is a + b"}]]}],["$","p",null,{"children":["Okay so we know that when a ",["$","code",null,{"children":"swap"}],", ",["$","code",null,{"children":"deposit"}]," or ",["$","code",null,{"children":"withdrawal"}]," occurs we want to capture the new reserves for a and b, calculate prices and volume, and then finally store them in the database."]}],["$","p",null,{"children":["Additionally, by looking at the ",["$","a",null,{"target":"_blank","rel":"noopener noreferrer","href":"https://github.com/stellar/soroban-examples/blob/main/liquidity_pool/src/lib.rs#L49","children":"liquidity pool code"}],", we know that reserve is stored on contract instance."]}],["$","p",null,{"children":"This leaves us with three main questions:"}],["$","ul",null,{"children":[["$","li",null,{"children":"how do we obtain changes in the contract instance from a ledger close?"}],["$","li",null,{"children":"how do we obtain changes to the new reserves from the instance?"}],["$","li",null,{"children":"how do we store data on the database?"}]]}],["$","h3",null,{"id":"contract-instance-updates-given-a-ledger-close","children":[["$","a",null,{"href":"#contract-instance-updates-given-a-ledger-close","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Contract instance updates given a ledger close."]}],["$","p",null,{"children":"Ledger close metas contain all the information regarding what happened in the network within the ledger, so it will surely contain the updates that happened to a certain entry."}],["$","p",null,{"children":["Changes to ledger entries are structured in a ledger close meta as an array of ",["$","code",null,{"children":"LedgerEntryChange"}],":"]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"pub"}]," ",["$","span",null,{"className":"token keyword","children":"enum"}]," ",["$","span",null,{"className":"token class-name type-definition","children":"LedgerEntryChange"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"Created"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"Updated"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"Removed"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"LedgerKey"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"State"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","p",null,{"children":["For our liquidity pool, we want to monitor for updates, so we need to pay attention to ",["$","code",null,{"children":"LedgerEntryChange::Updated"}],". Luckily, the ",["$","code",null,{"children":"rs-zephyr-sdk"}]," contains some helpers for dealing with ledger close meta, more specifically the SDK exports a ",["$","code",null,{"children":"MetaReader"}]," object."]}],["$","p",null,{"children":["For example, given a certain ",["$","code",null,{"children":"meta"}],", we could get updates in that ledger as follows:"]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"let"}]," reader ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"MetaReader"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"new"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token operator","children":"&"}],"meta",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"EntryChanges"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}]," updated",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token punctuation","children":".."}]," ",["$","span",null,{"className":"token punctuation","children":"}"}]," ",["$","span",null,{"className":"token operator","children":"="}]," reader",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"v2_ledger_entries"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}]]}]}],["$","p",null,{"children":"To conclude this small paragraph, knowing where the data you need lies is crucial in a Zephyr application. The SDK can help in the retrieval, but you need to know what is the data you need and where it's located."}],["$","h3",null,{"id":"from-instance-storage-to-reserves","children":[["$","a",null,{"href":"#from-instance-storage-to-reserves","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"From instance storage to reserves"]}],["$","p",null,{"children":"Instance storage is shared state of a contract, and it's an \"all-in-one\" package, meaning that it contains all entries associated with the instance as a map. In order to retrieve the reserve from the instance, we should iterate over each element of the instance map, and if the key of the element matches the key of the reserves, then we know that the value of the element will the reserve."}],["$","p",null,{"children":["And how do we get the keys for reserve a and reserve b? We just look at the ",["$","a",null,{"target":"_blank","rel":"noopener noreferrer","href":"https://github.com/stellar/soroban-examples/blob/main/liquidity_pool/src/lib.rs#L20","children":"code"}],":"]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token attr-name attribute","children":"#[derive(Clone, Copy)]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token attr-name attribute","children":"#[repr(u32)]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"pub"}]," ",["$","span",null,{"className":"token keyword","children":"enum"}]," ",["$","span",null,{"className":"token class-name type-definition","children":"DataKey"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"TokenA"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"0"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"TokenB"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"1"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"TokenShare"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"2"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"TotalShares"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"3"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"ReserveA"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"4"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"ReserveB"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"5"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","p",null,{"children":["So, they key for reserve a will be a ",["$","code",null,{"children":"U32(4)"}]," and the key for reserve b will be a ",["$","code",null,{"children":"U32(5)"}],"."]}],["$","h3",null,{"id":"storing-into-the-database","children":[["$","a",null,{"href":"#storing-into-the-database","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Storing into the database"]}],["$","p",null,{"children":"In our situation we want to store:"}],["$","ul",null,{"children":[["$","li",null,{"children":"the ledger in which the change occurred"}],["$","li",null,{"children":"the price of token a"}],["$","li",null,{"children":"the price of token b"}],["$","li",null,{"children":"the volume of the pool"}]]}],["$","p",null,{"children":["The zephyr SDK provides a clean way of storing stuff in the database under the table name ",["$","code",null,{"children":"\"prices\""}],":"]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token class-name","children":"Database"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"write_table"}],["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t",["$","span",null,{"className":"token string","children":"\"prices\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"ledger\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"a\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"b\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"volume\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t\t",["$","span",null,{"className":"token operator","children":"&"}],"sequence",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t a_on_b_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t b_on_a_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t volume",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":["\t",["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}],["$","blockquote",null,{"children":["$","p",null,{"children":"Note: as you can see, we are converting the numbers to byte arrays to load them into the database. That is because in this experimental version of Mercury + Zephyr only byte arrays are allowed for Mercury DB & Zephyr interoperability. This will change in the future where there will be some basic types (like integers) besides byte arrays."}]}],["$","h2",null,{"id":"practice","children":[["$","a",null,{"href":"#practice","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Practice"]}],["$","p",null,{"children":"To sum up what we said in theory, here is the workflow of our program:"}],["$","ol",null,{"children":[["$","li",null,{"children":"get the ledger metadata."}],["$","li",null,{"children":"get ledger entry from the meta."}],["$","li",null,{"children":"get updated entries from the meta."}],["$","li",null,{"children":["iterate over updated entries:",["$","ul",null,{"children":["$","li",null,{"children":["check that the updated entry is from our liquidity pool contract + that the updated entry is the contract instance.",["$","ul",null,{"children":[["$","li",null,{"children":"get reserves by iterating on the instance map."}],["$","li",null,{"children":"calculate prices, volume and store on the database."}]]}]]}]}]]}]]}],["$","h3",null,{"id":"imports","children":[["$","a",null,{"href":"#imports","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Imports"]}],["$","p",null,{"children":"Before starting, let's import the needed modules and structures from the SDK:"}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"use"}]," ",["$","span",null,{"className":"token namespace","children":["rs_zephyr_sdk",["$","span",null,{"className":"token punctuation","children":"::"}],"stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token keyword","children":"self"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntryData"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"use"}]," ",["$","span",null,{"className":"token namespace","children":["rs_zephyr_sdk",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token punctuation","children":"{"}],"scval_utils",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Database"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"EntryChanges"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"EnvClient"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"MetaReader"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}]]}]}],["$","h3",null,{"id":"entry-point","children":[["$","a",null,{"href":"#entry-point","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Entry point"]}],["$","p",null,{"children":["We start by defining our entry point function: ",["$","code",null,{"children":"on_close()"}],". This function will have to adhere to C calling conventions."]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token attr-name attribute","children":"#[no_mangle]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"pub"}]," ",["$","span",null,{"className":"token keyword","children":"extern"}]," ",["$","span",null,{"className":"token string","children":"\"C\""}]," ",["$","span",null,{"className":"token keyword","children":"fn"}]," ",["$","span",null,{"className":"token function function-definition","children":"on_close"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," meta ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"EnvClient"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"get_last_ledger_meta"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reader ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"MetaReader"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"new"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token operator","children":"&"}],"meta",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," sequence ",["$","span",null,{"className":"token operator","children":"="}]," reader",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"ledger_sequence"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"EntryChanges"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}]," updated",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token punctuation","children":".."}]," ",["$","span",null,{"className":"token punctuation","children":"}"}]," ",["$","span",null,{"className":"token operator","children":"="}]," reader",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"v2_ledger_entries"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"for"}]," updated_entry ",["$","span",null,{"className":"token keyword","children":"in"}]," updated ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"a",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"b",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token function","children":"reserves"}],["$","span",null,{"className":"token punctuation","children":"("}],"updated_entry",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," volume ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token operator","children":"+"}]," b",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," a ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"f64"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," b ",["$","span",null,{"className":"token operator","children":"="}]," b ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"f64"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," a_on_b_price ",["$","span",null,{"className":"token operator","children":"="}]," b ",["$","span",null,{"className":"token operator","children":"/"}]," a",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," b_on_a_price ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token operator","children":"/"}]," b",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"Database"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"write_table"}],["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"prices\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"ledger\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"a\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"b\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"volume\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],"sequence",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" a_on_b_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" b_on_a_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" volume",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}]]}]}],["$","p",null,{"children":["Here we are getting the ledger sequence and updated entries. Then we iterator over the entries, and if a certain function ",["$","code",null,{"children":"reserves(updated_entry: LedgerEntry) -> (Option, Option)"}]," (which we still have to define) returns us with ",["$","code",null,{"children":"(Some(a), Some(b))"}]," (reserve a and b), then we calculate prices and volume and finally write a new row to the prices table."]}],["$","h3",null,{"id":"the-reserves-function","children":[["$","a",null,{"href":"#the-reserves-function","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"The reserves function"]}],["$","p",null,{"children":["The function ",["$","code",null,{"children":"reserves()"}]," takes an entry and returns ",["$","code",null,{"children":"(Some(reserve_a), Some(reserve_b))"}]," if the entry is the liquidity pool's instance. To enforce this check we first hardcode the id of the liquidity pool in our program:"]}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"const"}]," ",["$","span",null,{"className":"token constant","children":"LP_CONTRACT"}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token keyword","children":"u8"}],["$","span",null,{"className":"token punctuation","children":";"}]," ",["$","span",null,{"className":"token number","children":"32"}],["$","span",null,{"className":"token punctuation","children":"]"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token number","children":"113"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"57"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"185"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"164"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"248"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"21"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"164"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"17"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"241"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"133"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"16"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"240"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"36"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"190"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"54"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"250"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"162"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"120"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"240"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"16"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token number","children":"55"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"18"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"230"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"202"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"63"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"15"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"152"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"25"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"21"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"128"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"27"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"70"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}]]}]}],["$","blockquote",null,{"children":["$","p",null,{"children":"Note: in this example we need to hardcode this value. However, we plan on Zephyr applications to have some (small) store attached to the binary itself. This store will support being dynamically changed and will be a better fit for values like contract addresses to monitor."}]}],["$","p",null,{"children":"next, we proceed with matching the contract address and the keys:"}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"fn"}]," ",["$","span",null,{"className":"token function function-definition","children":"reserves"}],["$","span",null,{"className":"token punctuation","children":"("}],"updated_entry",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"->"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"Option"}],["$","span",null,{"className":"token operator","children":"<"}],["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token operator","children":">"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Option"}],["$","span",null,{"className":"token operator","children":"<"}],["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token operator","children":">"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve_a_key ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"to_datakey_u32"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token number","children":"4"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve_b_key ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"to_datakey_u32"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token number","children":"5"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token keyword","children":"mut"}]," reserve_a ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"None"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token keyword","children":"mut"}]," reserve_b ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"None"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntryData"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"ContractData"}],["$","span",null,{"className":"token punctuation","children":"("}],"data",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"updated_entry",["$","span",null,{"className":"token punctuation","children":"."}],"data ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," contract ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token keyword","children":"match"}]," ",["$","span",null,{"className":"token operator","children":"&"}],"data",["$","span",null,{"className":"token punctuation","children":"."}],"contract ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token namespace","children":["stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token class-name","children":"ScAddress"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"Contract"}],["$","span",null,{"className":"token punctuation","children":"("}],"id",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"=>"}]," id",["$","span",null,{"className":"token number","children":".0"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token namespace","children":["stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token class-name","children":"ScAddress"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"Account"}],["$","span",null,{"className":"token punctuation","children":"("}],"_",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"=>"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property macro","children":"unreachable!"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," contract ",["$","span",null,{"className":"token operator","children":"=="}]," ",["$","span",null,{"className":"token constant","children":"LP_CONTRACT"}]," ",["$","span",null,{"className":"token operator","children":"&&"}]," data",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"LedgerKeyContractInstance"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," val ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"data",["$","span",null,{"className":"token punctuation","children":"."}],"val",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"entries",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"instance_entries"}],["$","span",null,{"className":"token punctuation","children":"("}],"val",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"for"}]," entry ",["$","span",null,{"className":"token keyword","children":"in"}]," entries ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token constant","children":"I128"}],["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"entry",["$","span",null,{"className":"token punctuation","children":"."}],"val ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":"."}],"hi ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"<<"}]," ",["$","span",null,{"className":"token number","children":"64"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"|"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":"."}],"lo ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," entry",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," reserve_a_key ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" reserve_a ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"reserve",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}]," ",["$","span",null,{"className":"token keyword","children":"else"}]," ",["$","span",null,{"className":"token keyword","children":"if"}]," entry",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," reserve_b_key ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" reserve_b ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"reserve",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"("}],"reserve_a",["$","span",null,{"className":"token punctuation","children":","}]," reserve_b",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","h3",null,{"id":"wrapping-it-up","children":[["$","a",null,{"href":"#wrapping-it-up","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Wrapping it up"]}],["$","p",null,{"children":"This is the final code for our Zephyr program:"}],["$","$L12",null,{"className":"language-rust","children":["$","code",null,{"className":"language-rust code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"use"}]," ",["$","span",null,{"className":"token namespace","children":["rs_zephyr_sdk",["$","span",null,{"className":"token punctuation","children":"::"}],"stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token keyword","children":"self"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntryData"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"use"}]," ",["$","span",null,{"className":"token namespace","children":["rs_zephyr_sdk",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token punctuation","children":"{"}],"scval_utils",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Database"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"EntryChanges"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"EnvClient"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"MetaReader"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"const"}]," ",["$","span",null,{"className":"token constant","children":"LP_CONTRACT"}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token keyword","children":"u8"}],["$","span",null,{"className":"token punctuation","children":";"}]," ",["$","span",null,{"className":"token number","children":"32"}],["$","span",null,{"className":"token punctuation","children":"]"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token number","children":"113"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"57"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"185"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"164"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"248"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"21"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"164"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"17"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"241"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"133"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"16"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"240"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"36"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"190"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"54"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"250"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"162"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"120"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"240"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"16"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token number","children":"55"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"18"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"230"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"202"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"63"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"15"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"152"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"25"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"21"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"128"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"27"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"70"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"fn"}]," ",["$","span",null,{"className":"token function function-definition","children":"reserves"}],["$","span",null,{"className":"token punctuation","children":"("}],"updated_entry",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntry"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"->"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"Option"}],["$","span",null,{"className":"token operator","children":"<"}],["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token operator","children":">"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Option"}],["$","span",null,{"className":"token operator","children":"<"}],["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token operator","children":">"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve_a_key ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"to_datakey_u32"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token number","children":"4"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve_b_key ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"to_datakey_u32"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token number","children":"5"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token keyword","children":"mut"}]," reserve_a ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"None"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token keyword","children":"mut"}]," reserve_b ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"None"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"LedgerEntryData"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"ContractData"}],["$","span",null,{"className":"token punctuation","children":"("}],"data",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"updated_entry",["$","span",null,{"className":"token punctuation","children":"."}],"data ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," contract ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token keyword","children":"match"}]," ",["$","span",null,{"className":"token operator","children":"&"}],"data",["$","span",null,{"className":"token punctuation","children":"."}],"contract ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token namespace","children":["stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token class-name","children":"ScAddress"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"Contract"}],["$","span",null,{"className":"token punctuation","children":"("}],"id",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"=>"}]," id",["$","span",null,{"className":"token number","children":".0"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token namespace","children":["stellar_xdr",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token class-name","children":"ScAddress"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"Account"}],["$","span",null,{"className":"token punctuation","children":"("}],"_",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"=>"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property macro","children":"unreachable!"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," contract ",["$","span",null,{"className":"token operator","children":"=="}]," ",["$","span",null,{"className":"token constant","children":"LP_CONTRACT"}]," ",["$","span",null,{"className":"token operator","children":"&&"}]," data",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token class-name","children":"LedgerKeyContractInstance"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," val ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"data",["$","span",null,{"className":"token punctuation","children":"."}],"val",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"entries",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token namespace","children":["scval_utils",["$","span",null,{"className":"token punctuation","children":"::"}]]}],["$","span",null,{"className":"token function","children":"instance_entries"}],["$","span",null,{"className":"token punctuation","children":"("}],"val",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"for"}]," entry ",["$","span",null,{"className":"token keyword","children":"in"}]," entries ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"ScVal"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token constant","children":"I128"}],["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token operator","children":"&"}],"entry",["$","span",null,{"className":"token punctuation","children":"."}],"val ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reserve ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":"."}],"hi ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"<<"}]," ",["$","span",null,{"className":"token number","children":"64"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"|"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],"parts",["$","span",null,{"className":"token punctuation","children":"."}],"lo ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"i128"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," entry",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," reserve_a_key ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" reserve_a ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"reserve",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}]," ",["$","span",null,{"className":"token keyword","children":"else"}]," ",["$","span",null,{"className":"token keyword","children":"if"}]," entry",["$","span",null,{"className":"token punctuation","children":"."}],"key ",["$","span",null,{"className":"token operator","children":"=="}]," reserve_b_key ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" reserve_b ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"reserve",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"("}],"reserve_a",["$","span",null,{"className":"token punctuation","children":","}]," reserve_b",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token attr-name attribute","children":"#[no_mangle]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"pub"}]," ",["$","span",null,{"className":"token keyword","children":"extern"}]," ",["$","span",null,{"className":"token string","children":"\"C\""}]," ",["$","span",null,{"className":"token keyword","children":"fn"}]," ",["$","span",null,{"className":"token function function-definition","children":"on_close"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," meta ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"EnvClient"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"get_last_ledger_meta"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," reader ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token class-name","children":"MetaReader"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"new"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token operator","children":"&"}],"meta",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," sequence ",["$","span",null,{"className":"token operator","children":"="}]," reader",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"ledger_sequence"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token class-name","children":"EntryChanges"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}]," updated",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token punctuation","children":".."}]," ",["$","span",null,{"className":"token punctuation","children":"}"}]," ",["$","span",null,{"className":"token operator","children":"="}]," reader",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"v2_ledger_entries"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"for"}]," updated_entry ",["$","span",null,{"className":"token keyword","children":"in"}]," updated ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"let"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"a",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token class-name","children":"Some"}],["$","span",null,{"className":"token punctuation","children":"("}],"b",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token function","children":"reserves"}],["$","span",null,{"className":"token punctuation","children":"("}],"updated_entry",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," volume ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token operator","children":"+"}]," b",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," a ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"f64"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," b ",["$","span",null,{"className":"token operator","children":"="}]," b ",["$","span",null,{"className":"token keyword","children":"as"}]," ",["$","span",null,{"className":"token keyword","children":"f64"}],["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," a_on_b_price ",["$","span",null,{"className":"token operator","children":"="}]," b ",["$","span",null,{"className":"token operator","children":"/"}]," a",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"let"}]," b_on_a_price ",["$","span",null,{"className":"token operator","children":"="}]," a ",["$","span",null,{"className":"token operator","children":"/"}]," b",["$","span",null,{"className":"token punctuation","children":";"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token class-name","children":"Database"}],["$","span",null,{"className":"token punctuation","children":"::"}],["$","span",null,{"className":"token function","children":"write_table"}],["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"prices\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"ledger\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"a\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"b\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"volume\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token operator","children":"&"}],"sequence",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" a_on_b_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" b_on_a_price",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" volume",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"to_be_bytes"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token function","children":"as_slice"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","h1",null,{"id":"deployment","children":[["$","a",null,{"href":"#deployment","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Deployment"]}],["$","p",null,{"children":"We now have our program and are only three steps away from having this code run along with the Stellar Testnet, manipulating and storing our customized data:"}],["$","ul",null,{"children":[["$","li",null,{"children":"compilation"}],["$","li",null,{"children":["declaring the ",["$","code",null,{"children":"\"prices\""}]," table through the CLI."]}],["$","li",null,{"children":"deploying the zephyr application through the CLI."}]]}],["$","h2",null,{"id":"compilation","children":[["$","a",null,{"href":"#compilation","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Compilation"]}],["$","p",null,{"children":["We must compile our library to WebAssembly using some special ",["$","code",null,{"children":"RUSTFLAGS"}],", specifically we are enabling WASM's multivalue post-MVP feature:"]}],["$","$L12",null,{"className":"language-js","children":["$","code",null,{"className":"code-highlight language-js","children":["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token constant","children":"RUSTFLAGS"}],["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"-Ctarget-feature=+multivalue -Cpanic=abort\""}]," cargo ",["$","span",null,{"className":"token operator","children":"+"}],"nightly build ",["$","span",null,{"className":"token operator","children":"--"}],"target wasm32",["$","span",null,{"className":"token operator","children":"-"}],"unknown",["$","span",null,{"className":"token operator","children":"-"}],"unknown ",["$","span",null,{"className":"token operator","children":"--"}],"release ",["$","span",null,{"className":"token operator","children":"-"}],["$","span",null,{"className":"token maybe-class-name","children":"Zbuild"}],["$","span",null,{"className":"token operator","children":"-"}],"std",["$","span",null,{"className":"token operator","children":"="}],"panic_abort",["$","span",null,{"className":"token punctuation","children":","}],"std\n"]}]}]}],["$","h2",null,{"id":"declaring-the-prices-table","children":[["$","a",null,{"href":"#declaring-the-prices-table","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Declaring the prices table"]}],["$","p",null,{"children":["Our program writes to the ",["$","code",null,{"children":"\"prices\""}]," table, however there is no such thing in Mercury (and even if there was, the guest environment woulnd't be authorized to write to it)."]}],["$","p",null,{"children":"This means that we need to create (or declare) our table. Our current Zephyr-CLI implementation currently allows to declare table as follows:"}],["$","$L12",null,{"className":"language-js","children":["$","code",null,{"className":"code-highlight language-js","children":["$","span",null,{"className":"code-line","children":["zephyr ",["$","span",null,{"className":"token operator","children":"--"}],"jwt $",["$","span",null,{"className":"token constant","children":"MY_MERCURY_JWT"}]," ",["$","span",null,{"className":"token keyword","children":"new"}],["$","span",null,{"className":"token operator","children":"-"}],"table ",["$","span",null,{"className":"token operator","children":"--"}],"name ",["$","span",null,{"className":"token string","children":"\"prices\""}]," ",["$","span",null,{"className":"token operator","children":"--"}],"columns ",["$","span",null,{"className":"token string","children":"'ledger'"}]," ",["$","span",null,{"className":"token string","children":"'a'"}]," ",["$","span",null,{"className":"token string","children":"'b'"}]," ",["$","span",null,{"className":"token string","children":"'volume'"}],"\n"]}]}]}],["$","p",null,{"children":"Which yields:"}],["$","$L12",null,{"className":"language-js","children":["$","code",null,{"className":"code-highlight language-js","children":["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token operator","children":"+"}],["$","span",null,{"className":"token punctuation","children":"]"}]," ",["$","span",null,{"className":"token maybe-class-name","children":"Table"}]," ",["$","span",null,{"className":"token string","children":"\"zephyr_f358aba3fc0d866e252ddd29541e55f2s\""}]," created successfully \n"]}]}]}],["$","p",null,{"children":["This means that we have created table ",["$","code",null,{"children":"f358aba3fc0d866e252ddd29541e55f2s"}]," in the database, which is the MD5 hash for the table name and the user id associated with the Mercury JWT. In fact, zephyr-created tables are user-specific and can only be modified and written by the user owning the table."]}],["$","h2",null,{"id":"deploying","children":[["$","a",null,{"href":"#deploying","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Deploying"]}],["$","p",null,{"children":"We can finally deploy our WASM binary using:"}],["$","$L12",null,{"className":"language-js","children":["$","code",null,{"className":"code-highlight language-js","children":["$","span",null,{"className":"code-line","children":["zephyr ",["$","span",null,{"className":"token operator","children":"--"}],"jwt $",["$","span",null,{"className":"token constant","children":"MY_MERCURY_JWT"}]," deploy ",["$","span",null,{"className":"token operator","children":"--"}],"wasm ",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token operator","children":"/"}],"target",["$","span",null,{"className":"token operator","children":"/"}],"wasm32",["$","span",null,{"className":"token operator","children":"-"}],"unknown",["$","span",null,{"className":"token operator","children":"-"}],"unknown",["$","span",null,{"className":"token operator","children":"/"}],"release",["$","span",null,{"className":"token operator","children":"/"}],"zephyr_lp",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token property-access","children":"wasm"}]," \n"]}]}]}],["$","p",null,{"children":"Our Zephyr program is now alredy operational on Mercury (actually, on my development branch of Mercury)!"}],["$","h1",null,{"id":"results","children":[["$","a",null,{"href":"#results","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}]}],"Results"]}],["$","p",null,{"children":"If we now try to invoke swaps or deposits for the pool, we can see in real time our Zephyr program writing prices to the database. For instance, I've tried doing a swap, a deposit and then a swap again and this is what we get on the Mercury API:"}],["$","$L12",null,{"className":"language-graphql","children":["$","code",null,{"className":"code-highlight language-graphql","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"query"}]," ",["$","span",null,{"className":"token function definition-query","children":"Prices"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token object","children":"allZephyrF358Aba3Fc0D866E252Ddd29541E55F2S"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token object","children":"nodes"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"a"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"b"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"volume"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"ledger"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","$L12",null,{"className":"language-json","children":["$","code",null,{"className":"code-highlight language-json","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"data\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"allZephyrF358Aba3Fc0D866E252Ddd29541E55F2S\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"nodes\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"a\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x400060b6ec610606\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"b\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x3fdf430865468abf\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"volume\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x0000000000000000000000000001d95e\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"ledger\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x001fe44c\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"a\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x400060be02fcad54\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"b\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x3fdf42fadd956752\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"volume\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x00000000000000000000000000024da7\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"ledger\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x001fe454\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"a\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x400071c1cefb6d74\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"b\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x3fdf22a24184e1d7\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"volume\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x00000000000000000000000000024e11\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token property","children":"\"ledger\""}],["$","span",null,{"className":"token operator","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\\\x001fe457\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}],["$","br",null,{}],["$","blockquote",null,{"children":["$","p",null,{"children":"Note: the above results are byte arrays represented as strings as in this experimental preview of the Zephyr + Mercury integration only byte arrays are supported for the Zephyr-DB interaction. This is likely going to change in the future as we will allow types like integers to also be interchangeable."}]}],["$","p",null,{"children":"Zephyr is still very early, but its fundamentals are already working and development is going fast. Soon you'll also be able to start playing with it."}],["$","p",null,{"children":"I hope this was a nice read and that you are excited about trying Zephyr yourself!"}]]}],["$","div",null,{"className":"pb-6 pt-6 text-center text-gray-700 dark:text-gray-300","id":"comment","children":["$","$L13",null,{"slug":"zephyr-pre-alpha-preview"}]}]]}],["$","footer",null,{"children":[["$","div",null,{"className":"divide-gray-200 text-sm font-medium leading-5 dark:divide-gray-700 xl:col-start-1 xl:row-start-2 xl:divide-y","children":[["$","div",null,{"className":"py-4 xl:py-8","children":[["$","h2",null,{"className":"text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400","children":"Tags"}],["$","div",null,{"className":"flex flex-wrap","children":[["$","$L9",null,{"href":"/tags/mercury","className":"mr-3 text-sm font-medium uppercase text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":"Mercury"}],["$","$L9",null,{"href":"/tags/zephyr","className":"mr-3 text-sm font-medium uppercase text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":"Zephyr"}],["$","$L9",null,{"href":"/tags/webassembly","className":"mr-3 text-sm font-medium uppercase text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":"WebAssembly"}],["$","$L9",null,{"href":"/tags/soroban","className":"mr-3 text-sm font-medium uppercase text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":"Soroban"}]]}]]}],["$","div",null,{"className":"flex justify-between py-4 xl:block xl:space-y-8 xl:py-8","children":[["$","div",null,{"children":[["$","h2",null,{"className":"text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400","children":"Previous Article"}],["$","div",null,{"className":"text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":["$","$L9",null,{"href":"/blog/introducing-zephyr","children":"The Zephyr VM: core of the Mercury code execution environment."}]}]]}],["$","div",null,{"children":[["$","h2",null,{"className":"text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400","children":"Next Article"}],["$","div",null,{"className":"text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","children":["$","$L9",null,{"href":"/blog/mercury-beta-release","children":"Announcing The Mercury BETA Release."}]}]]}]]}]]}],["$","div",null,{"className":"pt-4 xl:pt-8","children":["$","$L9",null,{"href":"/blog","className":"text-primary-500 hover:text-primary-600 dark:hover:text-primary-400","aria-label":"Back to the blog","children":"← Back to the blog"}]}]]}]]}]]}]}]]}]] f:null