(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1585],{40157:function(e,s,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/store/encoding",function(){return t(24905)}])},48986:function(e,s,t){"use strict";t.d(s,{C:function(){return l}});var n=t(7505),i=t(7765),r=t(24737),d=t.n(r);function l(e){let{children:s}=e,t=(0,i.useRef)(null),[r,l]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{if(!t.current)return;let e=Array.from(t.current.querySelectorAll(".line")),s=[];e.forEach((e,t)=>{e.matches(".highlighted")&&s.push(t),/^\s+$/g.test(e.innerHTML)&&e.setAttribute("data-empty","")}),s.length&&e.forEach((e,t)=>{let n=s.reduce((e,s)=>Math.min(e,Math.abs(s-t)),1/0);e.setAttribute("data-highlight-distance",Math.min(n,4).toString())})},[r]),(0,n.jsx)("div",{ref:t,style:{marginTop:"1.5rem"},className:r?d().collapsed:d().expanded,onClick:e=>{e.target instanceof Element&&e.target.closest(".line")&&l(!r)},children:s})}},73307:function(e,s,t){"use strict";t.d(s,{Z:function(){return d}});var n=t(7505),i=t(11689);let r={logo:function(){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.25em",fontSize:"32px",fontFamily:"PP Supply Mono",textTransform:"uppercase"},children:[(0,n.jsx)("img",{src:"/images/logos/mud-white.svg",style:{height:"calc(var(--nextra-navbar-height) - 35px)"},alt:"MUD logo"}),"MUD"]})},useNextSeoProps(){let{asPath:e}=(0,i.useRouter)();return{titleTemplate:"/"===e?"MUD – a framework for ambitious Ethereum applications":"%s – MUD"}},project:{link:"https://github.com/latticexyz/mud"},docsRepositoryBase:"https://github.com/latticexyz/mud/tree/main/docs",head:(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("meta",{property:"title",content:"MUD documentation"})}),darkMode:!1,nextThemes:{defaultTheme:"dark"},footer:{text:"MIT 2023 \xa9 MUD"},primaryHue:28,sidebar:{defaultMenuCollapseLevel:1}};var d=r},24905:function(e,s,t){"use strict";t.r(s);var n=t(7505),i=t(42585),r=t(38288),d=t(73307);t(54693);var l=t(26736);t(98823),t(48986);let c={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}=Object.assign({},(0,l.ah)(),e.components);return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(a,{...e})}):a(e)},pageOpts:{filePath:"pages/store/encoding.mdx",route:"/store/encoding",headings:[{depth:1,value:"Encoding",id:"encoding"},{depth:2,value:"Schema",id:"schema"},{depth:2,value:"Events",id:"events"},{depth:3,value:"Store_SetRecord",id:"store_setrecord"},{depth:3,value:"Store_SpliceStaticData",id:"store_splicestaticdata"},{depth:3,value:"Store_SpliceDynamicData",id:"store_splicedynamicdata"},{depth:3,value:"Store_DeleteRecord",id:"store_deleterecord"},{depth:2,value:"Onchain storage layout",id:"onchain-storage-layout"}],pageMap:[{kind:"Meta",data:{introduction:{title:"What is MUD?",theme:{breadcrumb:!1}},quickstart:{title:"Get started",theme:{breadcrumb:!1}},protocol:{title:"Protocol",type:"separator"},store:"Store",world:"World",framework:{title:"Framework",type:"separator"},config:"Config",cli:"CLI","state-query":"State Query",services:"Services","---":{title:"",type:"separator"},guides:"Guides",templates:"Templates",contribute:{title:"Contribute",theme:{breadcrumb:!1}},changelog:"Changelog",retrospectives:"Retrospectives",audits:"Audits",version:{title:"2.1.1",type:"menu",items:{changelog:{title:"Changelog",href:"/changelog"},contribute:{title:"Contribute",href:"/contribute"}}},status:{title:"Status",type:"page",href:"https://status.mud.dev",newWindow:!0},community:{title:"Community",type:"page",href:"https://community.mud.dev",newWindow:!0},twitter:{title:"Twitter",type:"page",href:"https://twitter.com/latticexyz",newWindow:!0},discord:{title:"Discord",type:"page",href:"https://lattice.xyz/discord",newWindow:!0}}},{kind:"Folder",name:"audits",route:"/audits",children:[{kind:"MdxPage",name:"2024-02-11-open-zeppelin",route:"/audits/2024-02-11-open-zeppelin"},{kind:"Meta",data:{"2024-02-11-open-zeppelin":"2024-02-11 OpenZeppelin",pdf:{display:"hidden"},icons:{display:"hidden"}}}]},{kind:"MdxPage",name:"changelog",route:"/changelog"},{kind:"Folder",name:"cli",route:"/cli",children:[{kind:"Meta",data:{tablegen:"mud tablegen",worldgen:"mud worldgen",test:"mud test",deploy:"mud deploy",verify:"mud verify","dev-contracts":"mud dev-contracts","abi-ts":"mud abi-ts","set-version":"mud set-version"}},{kind:"MdxPage",name:"abi-ts",route:"/cli/abi-ts"},{kind:"MdxPage",name:"deploy",route:"/cli/deploy"},{kind:"MdxPage",name:"dev-contracts",route:"/cli/dev-contracts"},{kind:"MdxPage",name:"set-version",route:"/cli/set-version"},{kind:"MdxPage",name:"tablegen",route:"/cli/tablegen"},{kind:"MdxPage",name:"test",route:"/cli/test"},{kind:"MdxPage",name:"verify",route:"/cli/verify"},{kind:"MdxPage",name:"worldgen",route:"/cli/worldgen"}]},{kind:"Folder",name:"config",route:"/config",children:[{kind:"MdxPage",name:"reference",route:"/config/reference"},{kind:"Meta",data:{reference:"Reference"}}]},{kind:"MdxPage",name:"config",route:"/config"},{kind:"MdxPage",name:"contribute",route:"/contribute"},{kind:"Folder",name:"guides",route:"/guides",children:[{kind:"Meta",data:{"replicating-onchain-state":"Replicating onchain state","hello-world":"Hello World","extending-a-world":"Extending a World","adding-delegation":"Adding Delegation",modules:"Writing MUD Modules",emojimon:"Emojimon",testing:"Testing","best-practices":"Best Practices"}},{kind:"MdxPage",name:"adding-delegation",route:"/guides/adding-delegation"},{kind:"Folder",name:"best-practices",route:"/guides/best-practices",children:[{kind:"Meta",data:{"dividing-into-systems":"Dividing Code into Systems","system-best-practices":"System Best Practices","deployment-settings":"Recommended Deployment Settings",kms:"Deploy production worlds using AWS KMS"}},{kind:"MdxPage",name:"deployment-settings",route:"/guides/best-practices/deployment-settings"},{kind:"MdxPage",name:"dividing-into-systems",route:"/guides/best-practices/dividing-into-systems"},{kind:"MdxPage",name:"kms",route:"/guides/best-practices/kms"},{kind:"MdxPage",name:"system-best-practices",route:"/guides/best-practices/system-best-practices"}]},{kind:"Folder",name:"emojimon",route:"/guides/emojimon",children:[{kind:"MdxPage",name:"1-preface-the-ecs-model",route:"/guides/emojimon/1-preface-the-ecs-model"},{kind:"MdxPage",name:"2-getting-started",route:"/guides/emojimon/2-getting-started"},{kind:"MdxPage",name:"3-players-and-movement",route:"/guides/emojimon/3-players-and-movement"},{kind:"MdxPage",name:"4-map-and-terrain",route:"/guides/emojimon/4-map-and-terrain"},{kind:"MdxPage",name:"5-a-wild-emojimon-appears",route:"/guides/emojimon/5-a-wild-emojimon-appears"},{kind:"MdxPage",name:"6-advanced",route:"/guides/emojimon/6-advanced"},{kind:"Meta",data:{"1-preface-the-ecs-model":"Preface: the ECS model","2-getting-started":"Getting started","3-players-and-movement":"Players and movement","4-map-and-terrain":"Map and terrain","5-a-wild-emojimon-appears":"A wild Emojimon appears","6-advanced":"Advanced features"}}]},{kind:"MdxPage",name:"emojimon",route:"/guides/emojimon"},{kind:"Folder",name:"extending-a-world",route:"/guides/extending-a-world",children:[{kind:"Meta",data:{index:"Extending a World Permissionlessly"}},{kind:"MdxPage",name:"index",route:"/guides/extending-a-world"}]},{kind:"Folder",name:"hello-world",route:"/guides/hello-world",children:[{kind:"Meta",data:{"add-table":"Add a table","filter-sync":"Filter data synchronization","add-system":"Add a system",deploy:{title:"Deploy to a blockchain",href:"/cli/deploy"},"add-chain-client":"Add chains to the client"}},{kind:"MdxPage",name:"add-chain-client",route:"/guides/hello-world/add-chain-client"},{kind:"MdxPage",name:"add-system",route:"/guides/hello-world/add-system"},{kind:"MdxPage",name:"add-table",route:"/guides/hello-world/add-table"},{kind:"MdxPage",name:"filter-sync",route:"/guides/hello-world/filter-sync"}]},{kind:"MdxPage",name:"hello-world",route:"/guides/hello-world"},{kind:"MdxPage",name:"modules",route:"/guides/modules"},{kind:"MdxPage",name:"replicating-onchain-state",route:"/guides/replicating-onchain-state"},{kind:"MdxPage",name:"testing",route:"/guides/testing"}]},{kind:"MdxPage",name:"introduction",route:"/introduction"},{kind:"MdxPage",name:"quickstart",route:"/quickstart"},{kind:"Folder",name:"retrospectives",route:"/retrospectives",children:[{kind:"MdxPage",name:"2023-09-12-register-system-vulnerability",route:"/retrospectives/2023-09-12-register-system-vulnerability"},{kind:"MdxPage",name:"2024-04-17-storeread-getdynamicfieldlength-bug",route:"/retrospectives/2024-04-17-storeread-getdynamicfieldlength-bug"},{kind:"Meta",data:{"2024-04-17-storeread-getdynamicfieldlength-bug":"2024-04-17 StoreRead.getDynamicFieldLength bug","2023-09-12-register-system-vulnerability":"2023-09-12 registerSystem vulnerability"}}]},{kind:"Folder",name:"services",route:"/services",children:[{kind:"Meta",data:{indexer:"Indexer",faucet:"Faucet"}},{kind:"MdxPage",name:"faucet",route:"/services/faucet"},{kind:"Folder",name:"indexer",route:"/services/indexer",children:[{kind:"Meta",data:{"using-indexer":"Using the Indexer","sqlite-indexer":"SQLite Indexer","postgres-event-only":"PostgreSQL for events","postgres-decoded":"PostgreSQL for data (and events)"}},{kind:"MdxPage",name:"postgres-decoded",route:"/services/indexer/postgres-decoded"},{kind:"MdxPage",name:"postgres-event-only",route:"/services/indexer/postgres-event-only"},{kind:"MdxPage",name:"sqlite-indexer",route:"/services/indexer/sqlite-indexer"},{kind:"MdxPage",name:"using-indexer",route:"/services/indexer/using-indexer"}]},{kind:"MdxPage",name:"indexer",route:"/services/indexer"}]},{kind:"Folder",name:"state-query",route:"/state-query",children:[{kind:"Meta",data:{typescript:"TypeScript"}},{kind:"Folder",name:"typescript",route:"/state-query/typescript",children:[{kind:"Meta",data:{recs:"RECS",zustand:"Zustand"}},{kind:"MdxPage",name:"recs",route:"/state-query/typescript/recs"},{kind:"MdxPage",name:"zustand",route:"/state-query/typescript/zustand"}]}]},{kind:"Folder",name:"store",route:"/store",children:[{kind:"Meta",data:{introduction:"Introduction","data-model":"Data model",tables:"Tables","table-libraries":"Table libraries",encoding:"Encoding","store-hooks":"Store hooks",reference:"Reference"}},{kind:"MdxPage",name:"data-model",route:"/store/data-model"},{kind:"MdxPage",name:"encoding",route:"/store/encoding"},{kind:"MdxPage",name:"introduction",route:"/store/introduction"},{kind:"Folder",name:"reference",route:"/store/reference",children:[{kind:"Meta",data:{"store-core":"StoreCore (internal)",store:"IStore (external)","store-hook":"StoreHook",misc:"Miscellaneous"}},{kind:"MdxPage",name:"misc",route:"/store/reference/misc"},{kind:"MdxPage",name:"store-core",route:"/store/reference/store-core"},{kind:"MdxPage",name:"store-hook",route:"/store/reference/store-hook"},{kind:"MdxPage",name:"store",route:"/store/reference/store"}]},{kind:"MdxPage",name:"store-hooks",route:"/store/store-hooks"},{kind:"MdxPage",name:"table-libraries",route:"/store/table-libraries"},{kind:"MdxPage",name:"tables",route:"/store/tables"}]},{kind:"Folder",name:"templates",route:"/templates",children:[{kind:"Meta",data:{typescript:"TypeScript",godot:"Godot",pwa:"Progressive Web App (for mobile)",swift:"Swift",svelte:"Svelte",unity:"Unity",nethereum:"Nethereum"}},{kind:"MdxPage",name:"godot",route:"/templates/godot"},{kind:"MdxPage",name:"nethereum",route:"/templates/nethereum"},{kind:"MdxPage",name:"pwa",route:"/templates/pwa"},{kind:"MdxPage",name:"svelte",route:"/templates/svelte"},{kind:"MdxPage",name:"swift",route:"/templates/swift"},{kind:"Folder",name:"typescript",route:"/templates/typescript",children:[{kind:"Meta",data:{contracts:"Contracts",vanilla:"Vanilla","react-ecs":"React-ECS",threejs:"Three.js",vue:"Vue"}},{kind:"MdxPage",name:"contracts",route:"/templates/typescript/contracts"},{kind:"MdxPage",name:"react-ecs",route:"/templates/typescript/react-ecs"},{kind:"MdxPage",name:"threejs",route:"/templates/typescript/threejs"},{kind:"MdxPage",name:"vanilla",route:"/templates/typescript/vanilla"},{kind:"MdxPage",name:"vue",route:"/templates/typescript/vue"}]},{kind:"MdxPage",name:"unity",route:"/templates/unity"}]},{kind:"Folder",name:"world",route:"/world",children:[{kind:"Meta",data:{introduction:"Introduction","resource-ids":"Resource Identifiers","namespaces-access-control":"Namespaces & Access Control",tables:"Tables",systems:"Systems","system-hooks":"System Hooks","function-selectors":"Function Selectors",balance:"Balance","account-delegation":"Account Delegation","batch-calls":"Batch Calls",upgrades:"Upgrading",modules:"Modules",reference:"Reference"}},{kind:"MdxPage",name:"account-delegation",route:"/world/account-delegation"},{kind:"MdxPage",name:"balance",route:"/world/balance"},{kind:"MdxPage",name:"batch-calls",route:"/world/batch-calls"},{kind:"MdxPage",name:"function-selectors",route:"/world/function-selectors"},{kind:"MdxPage",name:"introduction",route:"/world/introduction"},{kind:"Folder",name:"modules",route:"/world/modules",children:[{kind:"Meta",data:{keyswithvalue:"Keys with Value",erc721:"ERC-721 (NFT)"}},{kind:"MdxPage",name:"erc721",route:"/world/modules/erc721"},{kind:"MdxPage",name:"keyswithvalue",route:"/world/modules/keyswithvalue"}]},{kind:"MdxPage",name:"modules",route:"/world/modules"},{kind:"MdxPage",name:"namespaces-access-control",route:"/world/namespaces-access-control"},{kind:"Folder",name:"reference",route:"/world/reference",children:[{kind:"Meta",data:{"delegation-external":"Delegation (interface)",module:"Modules","module-external":"Modules (interface)",system:"Systems","system-external":"Systems (interface)",world:"World","world-external":"World (interfaces)","world-context":"World context","world-context-external":"World context (interface)","resource-ids":"Resource IDs",misc:"Miscellaneous",internal:"Internals"}},{kind:"MdxPage",name:"delegation-external",route:"/world/reference/delegation-external"},{kind:"Folder",name:"internal",route:"/world/reference/internal",children:[{kind:"Meta",data:{"access-control":"Access Control",create:"Create2",delegation:"Delegation",erc165:"ERC165","erc165-external":"ERC165 (interface)","init-module":"Init Module","init-module-implementation":"Init Module Implementation",systemcall:"SystemCall"}},{kind:"MdxPage",name:"access-control",route:"/world/reference/internal/access-control"},{kind:"MdxPage",name:"create",route:"/world/reference/internal/create"},{kind:"MdxPage",name:"delegation",route:"/world/reference/internal/delegation"},{kind:"MdxPage",name:"erc165-external",route:"/world/reference/internal/erc165-external"},{kind:"MdxPage",name:"erc165",route:"/world/reference/internal/erc165"},{kind:"MdxPage",name:"init-module-implementation",route:"/world/reference/internal/init-module-implementation"},{kind:"MdxPage",name:"init-module",route:"/world/reference/internal/init-module"},{kind:"MdxPage",name:"systemcall",route:"/world/reference/internal/systemcall"}]},{kind:"MdxPage",name:"misc",route:"/world/reference/misc"},{kind:"MdxPage",name:"module-external",route:"/world/reference/module-external"},{kind:"MdxPage",name:"module",route:"/world/reference/module"},{kind:"MdxPage",name:"resource-ids",route:"/world/reference/resource-ids"},{kind:"MdxPage",name:"system-external",route:"/world/reference/system-external"},{kind:"MdxPage",name:"system",route:"/world/reference/system"},{kind:"MdxPage",name:"world-context-external",route:"/world/reference/world-context-external"},{kind:"MdxPage",name:"world-context",route:"/world/reference/world-context"},{kind:"MdxPage",name:"world-external",route:"/world/reference/world-external"},{kind:"MdxPage",name:"world",route:"/world/reference/world"}]},{kind:"MdxPage",name:"resource-ids",route:"/world/resource-ids"},{kind:"MdxPage",name:"system-hooks",route:"/world/system-hooks"},{kind:"MdxPage",name:"systems",route:"/world/systems"},{kind:"MdxPage",name:"tables",route:"/world/tables"},{kind:"MdxPage",name:"upgrades",route:"/world/upgrades"}]}],flexsearch:{codeblocks:!0},title:"Encoding"},pageNextRoute:"/store/encoding",nextraLayout:r.ZP,themeConfig:d.Z};function a(e){let s=Object.assign({h1:"h1",p:"p",code:"code",ul:"ul",li:"li",strong:"strong",h2:"h2",table:"table",thead:"thead",tr:"tr",th:"th",tbody:"tbody",td:"td",a:"a",details:"details",summary:"summary",em:"em",ol:"ol",h3:"h3",pre:"pre",span:"span"},(0,l.ah)(),e.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h1,{children:"Encoding"}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"Store"})," uses a custom encoding scheme to store data more compactly than Solidity.\nIt is comparable to ",(0,n.jsx)(s.code,{children:"abi.encodePacked"}),", but with some notable differences:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"Array elements are tightly packed"}),", without any padding.\nThis might cause some elements to wrap around two storage slots, but saves a lot of space.\nFor example, an ",(0,n.jsx)(s.code,{children:"address[3]"})," array will only use 2 storage slots in MUD instead of 3 in Solidity, leading to a 33% reduction in storage costs."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"Array lengths are packed into a single slot"}),".\nTables are limited to up to 5 dynamic fields, and the length of each field is limited to 2",(0,n.jsx)("sup",{children:"40"})," (over a million millions), we can pack the lengths of all dynamic length fields of a table into a single storage slot.\nCompared to Solidity, this saves 1 storage slot per dynamic length element except for the first one."]}),"\n"]}),"\n",(0,n.jsxs)(s.p,{children:["This encoding scheme greatly reduces gas for storage operations on dynamic length fields and for emitting events.\n",(0,n.jsx)(s.strong,{children:"For events it reduces the payload size by over 80%"})," compared to the Solidity default of ",(0,n.jsx)(s.code,{children:"abi.encode"})," (depending on the table schema).\nNote that since the encoding happens at runtime and does not have access to compiler internals, there is some overhead for encoding and decoding that is not present in vanilla Solidity."]}),"\n",(0,n.jsx)(s.h2,{id:"schema",children:"Schema"}),"\n",(0,n.jsx)(s.p,{children:"The schema defines the data type of every field in the record, whether it is part of the key used to look the record up, or the value that the table provides."}),"\n",(0,n.jsxs)(s.p,{children:["To save gas, onchain the schema definition is divided between the key schema and the value schema.\nBoth definitions use the same data structure, a ",(0,n.jsx)(s.code,{children:"bytes32"})," value that encodes the total byte length of all static length fields, the number of static-length fields, the number of dynamic-length fields, and up to 28 column types."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Byte(s)"}),(0,n.jsx)(s.th,{children:"Value"}),(0,n.jsx)(s.th,{children:"Type"}),(0,n.jsx)(s.th,{children:"Constraint"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0-1"}),(0,n.jsx)(s.td,{children:"Total length of static fields"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint16"})}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:"Number of static length fields"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint8"})}),(0,n.jsx)(s.td,{children:"≤ (28 - number of dynamic length fields)"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:"Number of dynamic length fields"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint8"})}),(0,n.jsxs)(s.td,{children:["For the key schema, 0 ",(0,n.jsx)("br",{})," For the value schema, ≤5"]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:"Type of first column"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SchemaType"})}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:"Type of second column"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SchemaType"})}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"."}),(0,n.jsx)(s.td,{}),(0,n.jsx)(s.td,{}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"n"}),(0,n.jsx)(s.td,{children:"Type of (n-3)'th column"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SchemaType"})}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"."}),(0,n.jsx)(s.td,{}),(0,n.jsx)(s.td,{}),(0,n.jsx)(s.td,{})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"31"}),(0,n.jsx)(s.td,{children:"Type of 28th column"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SchemaType"})}),(0,n.jsx)(s.td,{})]})]})]}),"\n",(0,n.jsxs)(s.p,{children:["Types are represented via the ",(0,n.jsx)(s.code,{children:"SchemaType"})," enum and encoded as one byte per type.\nThe encoding is specified in ",(0,n.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/schema-type/src/solidity/SchemaType.sol",children:(0,n.jsx)(s.code,{children:"SchemaType.sol"})})]}),"\n",(0,n.jsxs)(s.details,{children:[(0,n.jsx)(s.summary,{children:"Schema types"}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Value (hex)"}),(0,n.jsx)(s.th,{align:"right",children:"Value (dec)"}),(0,n.jsx)(s.th,{children:"Type"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x00≤n≤0x1F"}),(0,n.jsx)(s.td,{align:"right",children:"0≤n≤31"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint<8(n+1)>"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x20≤n≤0x3F"}),(0,n.jsx)(s.td,{align:"right",children:"32≤n≤63"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"int<8(n-31)>"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x40≤n≤0x5F"}),(0,n.jsx)(s.td,{align:"right",children:"64≤n≤95"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes<n-63>"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x60"}),(0,n.jsx)(s.td,{align:"right",children:"96"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bool"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x61"}),(0,n.jsx)(s.td,{align:"right",children:"97"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"address"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x62≤n≤0x81"}),(0,n.jsx)(s.td,{align:"right",children:"98≤n≤129"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint<8(n-97)>[]"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0x82≤n≤0xA1"}),(0,n.jsx)(s.td,{align:"right",children:"130≤n≤161"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"int<8(n-129)>[]"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0xA2≤n≤0xC1"}),(0,n.jsx)(s.td,{align:"right",children:"162≤n≤193"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes<8(n-161)>[]"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0xC2"}),(0,n.jsx)(s.td,{align:"right",children:"194"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bool[]"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0xC3"}),(0,n.jsx)(s.td,{align:"right",children:"195"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"address[]"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0xC4"}),(0,n.jsx)(s.td,{align:"right",children:"196"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0xC5"}),(0,n.jsx)(s.td,{align:"right",children:"197"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"string"})})]})]})]})]}),"\n",(0,n.jsxs)(s.p,{children:["Note that the dynamic-length types ",(0,n.jsx)(s.em,{children:"must"})," come after all the static-length types."]}),"\n",(0,n.jsxs)(s.p,{children:["For example, let's interpret the schema ",(0,n.jsx)(s.code,{children:"0x001c0303180001c5c48300000000000000000000000000000000000000000000"}),"."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Byte number"}),(0,n.jsx)(s.th,{children:"0-1"}),(0,n.jsx)(s.th,{children:"2"}),(0,n.jsx)(s.th,{children:"3"}),(0,n.jsx)(s.th,{children:"4"}),(0,n.jsx)(s.th,{children:"5"}),(0,n.jsx)(s.th,{children:"6"}),(0,n.jsx)(s.th,{children:"7"}),(0,n.jsx)(s.th,{children:"8"}),(0,n.jsx)(s.th,{children:"9"}),(0,n.jsx)(s.th,{children:"10-31"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:"Schema data"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x001c"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"03"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"03"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"18"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"00"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"01"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"c5"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"c4"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"83"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0...0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:"Meaning"}),(0,n.jsx)(s.td,{children:"28 bytes of static data"}),(0,n.jsx)(s.td,{children:"three static length fields"}),(0,n.jsx)(s.td,{children:"three dynamic length fields"}),(0,n.jsxs)(s.td,{children:["1st field - ",(0,n.jsx)(s.code,{children:"18"})," (",(0,n.jsx)(s.code,{children:"uint200"}),")"]}),(0,n.jsxs)(s.td,{children:["2nd field - ",(0,n.jsx)(s.code,{children:"00"})," (",(0,n.jsx)(s.code,{children:"uint8"}),")"]}),(0,n.jsxs)(s.td,{children:["3rd field - ",(0,n.jsx)(s.code,{children:"01"})," (",(0,n.jsx)(s.code,{children:"uin16"}),")"]}),(0,n.jsxs)(s.td,{children:["4th field - ",(0,n.jsx)(s.code,{children:"c5"})," (",(0,n.jsx)(s.code,{children:"string"}),")"]}),(0,n.jsxs)(s.td,{children:["5th field - ",(0,n.jsx)(s.code,{children:"c4"})," (",(0,n.jsx)(s.code,{children:"bytes"}),")"]}),(0,n.jsxs)(s.td,{children:["6th field - ",(0,n.jsx)(s.code,{children:"83"})," (",(0,n.jsx)(s.code,{children:"int16[]"}),")"]}),(0,n.jsx)(s.td,{children:"No other fields"})]})]})]}),"\n",(0,n.jsx)(s.h2,{id:"events",children:"Events"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"Store_"})," events have two topics:"]}),"\n",(0,n.jsxs)(s.ol,{start:"0",children:["\n",(0,n.jsxs)(s.li,{children:["The event signature","\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsx)(s.li,{children:(0,n.jsxs)(s.a,{href:"https://www.4byte.directory/event-signatures/?bytes_signature=0x8dbb3a9672eebfd3773e72dd9c102393436816d832c7ba9e1e1ac8fcadcac7a9",children:[(0,n.jsx)(s.code,{children:"0x8dbb3a9672eebfd3773e72dd9c102393436816d832c7ba9e1e1ac8fcadcac7a9"})," for ",(0,n.jsx)(s.code,{children:"Store_SetRecord"})]})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsxs)(s.a,{href:"https://www.4byte.directory/event-signatures/?bytes_signature=0x8c0b5119d4cec7b284c6b1b39252a03d1e2f2d7451a5895562524c113bb952be",children:[(0,n.jsx)(s.code,{children:"0x8c0b5119d4cec7b284c6b1b39252a03d1e2f2d7451a5895562524c113bb952be"})," for ",(0,n.jsx)(s.code,{children:"Store_SpliceStaticData"})]})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsxs)(s.a,{href:"https://www.4byte.directory/event-signatures/?bytes_signature=0xfe158a7adba34e256807c8a149028d3162918713c3838afc643ce9f96716ebfd",children:[(0,n.jsx)(s.code,{children:"0xfe158a7adba34e256807c8a149028d3162918713c3838afc643ce9f96716ebfd"})," for ",(0,n.jsx)(s.code,{children:"Store_SpliceDynamicData"})]})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsxs)(s.a,{href:"https://www.4byte.directory/event-signatures/?bytes_signature=0x0e1f72f429eb97e64878619984a91e687ae91610348b9ff4216782cc96e49d07",children:[(0,n.jsx)(s.code,{children:"0x0e1f72f429eb97e64878619984a91e687ae91610348b9ff4216782cc96e49d07"})," for ",(0,n.jsx)(s.code,{children:"Store_DeleteRecord"})]})}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(s.li,{children:"The ResourceId for the table being modified."}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"store_setrecord",children:(0,n.jsx)(s.code,{children:"Store_SetRecord"})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreEvents.sol#L18-L32",children:"This event"})," is emitted when a new record is created with all the data fields."]}),"\n",(0,n.jsxs)(s.p,{children:["The fields are in the event definition.\nIn Solidity, unindexed event fields are ",(0,n.jsx)(s.a,{href:"https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-of-the-encoding",children:"ABI encoded"}),"."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Field"}),(0,n.jsx)(s.th,{children:"Encoding"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:"Standard ABI encoding (32-byte fields)"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes staticData"})}),(0,n.jsx)(s.td,{children:"Packed ABI encoding of a tuple with the value's static fields"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})}),(0,n.jsx)(s.td,{children:"See below."})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes dynamicData"})}),(0,n.jsxs)(s.td,{children:["Modified packed ABI encoding of data, use ",(0,n.jsx)(s.code,{children:"encodedLengths"})," for length delimiters"]})]})]})]}),"\n",(0,n.jsx)("a",{id:"encoded-lengths"}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"encodedLengths"})," is a 32-byte value that contains the length in bytes of all the dynamic data fields:"]}),"\n",(0,n.jsx)(s.pre,{"data-language":"text","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"text","data-theme":"default",children:[(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"EncodedLengths = bytes[32] where:"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"}})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[0:6]   = len of all dynamic data"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[6:11]  = len of 1st dynamic field"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[11:16] = len of 2nd dynamic field"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[16:21] = len of 3rd dynamic field"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[21:26] = len of 4th dynamic field"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"bytes[26:31] = len of 5th dynamic field"})})]})}),"\n",(0,n.jsxs)(s.details,{children:[(0,n.jsx)(s.summary,{children:"Example"}),(0,n.jsx)(s.p,{children:"For example, we have a table with this definition:"}),(0,n.jsx)(s.pre,{"data-language":"typescript","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"typescript","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    Complicated"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"       schema"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         key1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint200"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         key2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint8"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint200"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint8"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint16"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"string"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"bytes"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"int16[]"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"       }"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"       key"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ["}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"key1"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"key2"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"]"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    }"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]})]})}),(0,n.jsx)(s.p,{children:"And we want to understand this data:"}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000080"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000000e0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000060000000005000000000500000000000010"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000120"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000060a7"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x000000000000000000000000000000000000000000000000000000000000001c"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"8"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000bad04600d00000000"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"9"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000010"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"10"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x68656c6c6f776f726c6400010002000300000000000000000000000000000000"})})]})]})]}),(0,n.jsx)(s.p,{children:"The first four 256-bit words correspond to the four unindexed event fields."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Event field"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0...080"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes staticData"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0...0e0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000060000000005000000000500000000000010"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes dynamicData"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0...0120"})})]})]})]}),(0,n.jsx)(s.p,{children:"ABI encoding starts with one 32-byte word per field.\nIf the field is static, the word contains that value.\nIf the field is dynamic, the word contains an offset into where the field data starts."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Event field"}),(0,n.jsx)(s.th,{align:"right",children:"Starting byte"}),(0,n.jsx)(s.th,{align:"right",children:"Words in the data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{align:"right",children:"0x80 = 128 = 4*32"}),(0,n.jsx)(s.td,{align:"right",children:"4-6"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes staticData"})}),(0,n.jsx)(s.td,{align:"right",children:"0xE0 = 224 = 7*32"}),(0,n.jsx)(s.td,{align:"right",children:"7-8"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes dynamicData"})}),(0,n.jsx)(s.td,{align:"right",children:"0x120 = 288 = 9*32"}),(0,n.jsx)(s.td,{align:"right",children:"9-10"})]})]})]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})})}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{align:"right",children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x0......02"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x0...060a7"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x0......02"})})]})]})]}),(0,n.jsx)(s.p,{children:"This is a variable-length array.\nThe first word is the array length, followed by the values.\nThe key fields are treated internally as 32-byte values, so every value takes 32 bytes.\nThis gives us"}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Record field"}),(0,n.jsx)(s.th,{align:"right",children:"Value"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"key1"})}),(0,n.jsx)(s.td,{align:"right",children:"0x60A7"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"key2"})}),(0,n.jsx)(s.td,{align:"right",children:"2"})]})]})]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"bytes staticData"})})}),(0,n.jsx)(s.p,{children:"This is the static data (the static fields that are not in the key)."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0...01c"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"8"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000bad 04 600d 00000000"})})]})]})]}),(0,n.jsxs)(s.p,{children:["Because the type is an unspecified number of bytes, the first 32-byte word is the length.\nIn this case, the length is ",(0,n.jsx)(s.code,{children:"0x1C=28"}),".\nThis means that only the first (most significant) 28 bytes of word 8 are meaningful.\nThe other four are zero."]}),(0,n.jsx)(s.p,{children:"Going back to the schema, we see that there are three static data fields:"}),(0,n.jsx)(s.pre,{"data-language":"typescript","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"typescript","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint200"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint8"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint16"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]})]})}),(0,n.jsxs)(s.p,{children:["The first one is ",(0,n.jsx)(s.code,{children:"200 bits = 25 bytes"}),", the second one is ",(0,n.jsx)(s.code,{children:"8 bits = 1 byte"}),", and the third is ",(0,n.jsx)(s.code,{children:"16 bits = 2 bytes"}),".\nThey are written consecutively, so"]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Record field"}),(0,n.jsx)(s.th,{align:"right",children:"Value"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"val1"})}),(0,n.jsx)(s.td,{align:"right",children:"0xBAD"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"val2"})}),(0,n.jsx)(s.td,{align:"right",children:"4"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"val3"})}),(0,n.jsx)(s.td,{align:"right",children:"0x600D"})]})]})]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})})}),(0,n.jsxs)(s.p,{children:[(0,n.jsxs)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/EncodedLengths.sol",children:["This is the definition of the ",(0,n.jsx)(s.code,{children:"EncodedLengths"})," type"]}),"."]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Bytes"}),(0,n.jsx)(s.th,{children:"0x1F-0x1B"}),(0,n.jsx)(s.th,{children:"0x1A-0x16"}),(0,n.jsx)(s.th,{children:"0x15-0x11"}),(0,n.jsx)(s.th,{children:"0x10-0x0C"}),(0,n.jsx)(s.th,{children:"0x0B-0x07"}),(0,n.jsx)(s.th,{children:"0x06-0x00"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:"Value"}),(0,n.jsx)(s.td,{children:"0x0...0"}),(0,n.jsx)(s.td,{children:"0x0...0"}),(0,n.jsx)(s.td,{children:"0x0...06"}),(0,n.jsx)(s.td,{children:"0x0...05"}),(0,n.jsx)(s.td,{children:"0x0...05"}),(0,n.jsx)(s.td,{children:"0x0...010"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:"Length (in bytes) of"}),(0,n.jsx)(s.td,{children:"5th dynamic field"}),(0,n.jsx)(s.td,{children:"4th dynamic field"}),(0,n.jsx)(s.td,{children:"3rd dynamic field"}),(0,n.jsx)(s.td,{children:"2nd dynamic field"}),(0,n.jsx)(s.td,{children:"1st dynamic field"}),(0,n.jsx)(s.td,{children:"all dynamic fields together"})]})]})]}),(0,n.jsx)(s.p,{children:"This is the dynamic field part of the schema:"}),(0,n.jsx)(s.pre,{"data-language":"typescript","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"typescript","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"string"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"bytes"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"int16[]"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]})]})}),(0,n.jsxs)(s.p,{children:["Here we see that the first five bytes of the dynamic data are going to be ",(0,n.jsx)(s.code,{children:"dyn1"}),", the next five ",(0,n.jsx)(s.code,{children:"dyn2"}),", and the final six ",(0,n.jsx)(s.code,{children:"dyn3"}),".\nThe total length is ",(0,n.jsx)(s.code,{children:"0x10 = 16"}),"."]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"bytes dynamicData"})})}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"9"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000010"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"10"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x68656c6c6f 776f726c64 000100020003 00000000000000000000000000000000"})})]})]})]}),(0,n.jsxs)(s.p,{children:["This value is also ",(0,n.jsx)(s.code,{children:"bytes"}),", so the first word is the length of the data, in this case ",(0,n.jsx)(s.code,{children:"0x10=16"}),".\nCombining this with the encoded lengths information, we get these values:"]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Record field"}),(0,n.jsx)(s.th,{align:"right",children:"Value"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn1"})}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x68656c6c6f"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn2"})}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x776f726c64"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn3"})}),(0,n.jsx)(s.td,{align:"right",children:(0,n.jsx)(s.code,{children:"0x00100020003"})})]})]})]}),(0,n.jsx)(s.p,{children:"To interpret the values we need to get the types from the schema."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Record field"}),(0,n.jsx)(s.th,{children:"Field type"}),(0,n.jsx)(s.th,{children:"Value"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn1"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"string"})}),(0,n.jsx)(s.td,{children:"hello"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn2"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes"})}),(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"0x776f726c64"})," (= world)"]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"dyn3"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"int16[]"})}),(0,n.jsx)(s.td,{children:"[1,2,3]"})]})]})]})]}),"\n",(0,n.jsx)(s.h3,{id:"store_splicestaticdata",children:(0,n.jsx)(s.code,{children:"Store_SpliceStaticData"})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreEvents.sol#L34-L43",children:"This event"})," is emitted when a record's static fields are modified.\nNote that this event is also emitted if the record did not exist previously.\nSolidity does not distinguish between a record not existing, and a record existing with all the values set to zero."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Field"}),(0,n.jsx)(s.th,{children:"Encoding"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:"Standard ABI encoding (32-byte fields)"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint48 start"})}),(0,n.jsx)(s.td,{children:"The starting byte of the segment of static data to change"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes data"})}),(0,n.jsx)(s.td,{children:"Packed ABI encoding of a tuple with the value's static fields"})]})]})]}),"\n",(0,n.jsxs)(s.details,{children:[(0,n.jsx)(s.summary,{children:"Example"}),(0,n.jsxs)(s.p,{children:["Using the same table definition as with ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),", we want to understand this data:"]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000060"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000019"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000000c0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000060a7"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000003"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000001"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0xff00000000000000000000000000000000000000000000000000000000000000"})})]})]})]}),(0,n.jsx)(s.p,{children:"The first three 256-bit words correspond to the three unindexed event fields."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Event field"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...60"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint48 start"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...19"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes data"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...C0"})})]})]})]}),(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"keyTuple"})," is interpreted the same way it is in ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),"."]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"uint48 start"})})}),(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"start"})," is ",(0,n.jsx)(s.code,{children:"0x19 = 25"}),"."]}),(0,n.jsx)(s.p,{children:"Going back to the schema, we see that there are three static data fields:"}),(0,n.jsx)(s.pre,{"data-language":"typescript","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"typescript","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint200"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val2"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint8"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         val3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"uint16"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]})]})}),(0,n.jsxs)(s.p,{children:["Starting from zero, this means that ",(0,n.jsx)(s.code,{children:"val1"})," is bytes 0-24, ",(0,n.jsx)(s.code,{children:"val2"})," is byte 25, and ",(0,n.jsx)(s.code,{children:"val3"})," is bytes 26-27.\nWe are changing from byte 25, so ",(0,n.jsx)(s.code,{children:"val1"}),"'s value stays the same."]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"bytes data"})})}),(0,n.jsxs)(s.p,{children:["This data starts at word six (byte ",(0,n.jsx)(s.code,{children:"0xC0 = 192 = 32*6"}),")."]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0...01"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0xff 0...0"})})]})]})]}),(0,n.jsxs)(s.p,{children:["The first word of this field, word 6, tells us that we are only changing one byte of the data, so we aren't changing ",(0,n.jsx)(s.code,{children:"val3"})," either.\nThe first byte of word 7, the only one that matters, is ",(0,n.jsx)(s.code,{children:"0xFF"}),".\nThis is the new value of ",(0,n.jsx)(s.code,{children:"val2"}),"."]})]}),"\n",(0,n.jsx)(s.h3,{id:"store_splicedynamicdata",children:(0,n.jsx)(s.code,{children:"Store_SpliceDynamicData"})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreEvents.sol#L45-L64",children:"This event"})," is emitted when a record's dynamic fields are modified.\nNote that this event is also emitted if the record did not exist previously.\nSolidity does not distinguish between a record not existing, and a record existing with all the values set to zero."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Field"}),(0,n.jsx)(s.th,{children:"Encoding"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:"Standard ABI encoding (32-byte fields)"})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint8 dynamicFieldIndex"})}),(0,n.jsxs)(s.td,{children:["The sequential number (counting from zero) of the dynamic field to change. 0 ≤ ",(0,n.jsx)(s.code,{children:"dynamicFieldIndex"})," ≤ 4"]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint48 start"})}),(0,n.jsxs)(s.td,{children:["The starting byte of the segment of the ",(0,n.jsx)(s.code,{children:"dynamicFieldIndex"}),"'th dynamic field to change"]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint40 deleteCount"})}),(0,n.jsxs)(s.td,{children:["The number of bytes to delete from the ",(0,n.jsx)(s.code,{children:"dynamicFieldIndex"}),"'th dynamic field."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})}),(0,n.jsxs)(s.td,{children:["Similar to ",(0,n.jsx)(s.code,{children:"encodedLengths"})," in ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),", except that only the size of the ",(0,n.jsx)(s.code,{children:"dynamicFieldIndex"}),"'th field is included"]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes data"})}),(0,n.jsxs)(s.td,{children:["Bytes to add/change in the ",(0,n.jsx)(s.code,{children:"dynamicFieldIndex"}),"'th dynamic field."]})]})]})]}),"\n",(0,n.jsxs)(s.details,{children:[(0,n.jsx)(s.summary,{children:"Example: Appending and modifying data"}),(0,n.jsxs)(s.p,{children:["Using the same table definition as with ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),", we want to understand this data.\nNote that the log entry by itself does not tell us if we are appending data or modifying an existing value.\nIt only tells us that we are changing the data in bytes six and seven, not whether there is already data there or not."]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000000c0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000006"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000000"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000080000000000000000000000000000000008"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000120"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000060a7"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"8"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000005"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"9"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"10"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x1234000000000000000000000000000000000000000000000000000000000000"})})]})]})]}),(0,n.jsx)(s.p,{children:"The first six 256-bit words correspond to the unindexed event fields."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Event field"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...c0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint8 dynamicFieldIndex"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...02"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint48 start"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...06"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint40 deleteCount"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...00"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000 0000000000 0000000008 0000000000 0000000000 00000000000008"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes data"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...120"})})]})]})]}),(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"keyTuple"})," is interpreted the same way it is in ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),"."]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"uint8 dynamicFieldIndex"})})}),(0,n.jsx)(s.p,{children:"The index of the dynamic field we are modifying.\nThe value here is two.\nCounting from zero it is the third schema field."}),(0,n.jsx)(s.pre,{"data-language":"typescript","data-theme":"default",children:(0,n.jsx)(s.code,{"data-language":"typescript","data-theme":"default",children:(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"         dyn3"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"int16[]"'}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]})})}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"uint48 start"})})}),(0,n.jsxs)(s.p,{children:["The byte at which we start the change.\nHere is it byte six.\nThe effect on the length of the data depends on what we are doing.\nIf we are appending data, we would have six bytes now (three values) and add to them.\nIf we are modifying data, we should have at least eight bytes now (four values), and we modify the fourth value (",(0,n.jsx)(s.code,{children:"dyn3[3]"}),")."]}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"uint40 deleteCount"})})}),(0,n.jsx)(s.p,{children:"The number of bytes we delete.\nIn this case, zero."}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})})}),(0,n.jsx)(s.p,{children:"The encoded lengths in the data after the change (if they change).\nThis value tells us that only the third field changes, and that it will be eight bytes long."}),(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"bytes data"})})}),(0,n.jsxs)(s.p,{children:["This value starts at byte ",(0,n.jsx)(s.code,{children:"0x120 = 288 = 9*32"}),", or word nine."]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"9"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"10"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x1234 000000000000000000000000000000000000000000000000000000000000"})})]})]})]}),(0,n.jsxs)(s.p,{children:["Again, the first word of the ",(0,n.jsx)(s.code,{children:"bytes"})," value tells us how many bytes we have (two).\nThe second gives us the value we are adding, in this case ",(0,n.jsx)(s.code,{children:"0x1234"}),"."]})]}),"\n",(0,n.jsxs)(s.details,{children:[(0,n.jsx)(s.summary,{children:"Example: Deleting data"}),(0,n.jsxs)(s.p,{children:["Using the same table definition as with ",(0,n.jsx)(s.code,{children:"Store_SetRecord"}),", we want to understand this data:"]}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000000c0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000006"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000060000000000000000000000000000000006"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000120"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"6"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000002"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"7"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00000000000000000000000000000000000000000000000000000000000060a7"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"8"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000005"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"9"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000000000000000000000000000000000000000"})})]})]})]}),(0,n.jsx)(s.p,{children:"The first six 256-bit words correspond to the unindexed event fields."}),(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{align:"right",children:"Word"}),(0,n.jsx)(s.th,{children:"Event field"}),(0,n.jsx)(s.th,{children:"Data"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"0"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...c0"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"1"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint8 dynamicFieldIndex"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...02"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"2"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint48 start"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...06"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"3"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"uint40 deleteCount"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...02"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"4"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"EncodedLengths encodedLengths"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x0000000000000000000000000000060000000000000000000000000000000006"})})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{align:"right",children:"5"}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes data"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"0x00...120"})})]})]})]}),(0,n.jsxs)(s.p,{children:["This is very similar to appending or modifying data, except that ",(0,n.jsx)(s.code,{children:"deleteCount"})," has a value.\nThis is the number of bytes we are deleting, two (a single array element).\nCombining this with the ",(0,n.jsx)(s.code,{children:"start"})," value of six, we are deleting bytes six and seven."]}),(0,n.jsxs)(s.p,{children:["The other difference is that word 9 is zero - there is a ",(0,n.jsx)(s.code,{children:"bytes data"})," value, but it is empty."]})]}),"\n",(0,n.jsx)(s.h3,{id:"store_deleterecord",children:(0,n.jsx)(s.code,{children:"Store_DeleteRecord"})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreEvents.sol#L66-L71",children:"This event"})," is emitted when a record is deleted."]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Field"}),(0,n.jsx)(s.th,{children:"Encoding"})]})}),(0,n.jsx)(s.tbody,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"})}),(0,n.jsx)(s.td,{children:"Standard ABI encoding (32-byte fields)"})]})})]}),"\n",(0,n.jsxs)(s.p,{children:["The only unindexed event field is ",(0,n.jsx)(s.code,{children:"bytes32[] keyTuple"}),", which contains the key.\nSee the example in ",(0,n.jsx)(s.a,{href:"#store_setrecord",children:(0,n.jsx)(s.code,{children:"Store_SetRecord"})})," to interpret it."]}),"\n",(0,n.jsx)(s.h2,{id:"onchain-storage-layout",children:"Onchain storage layout"}),"\n",(0,n.jsx)(s.p,{children:"The data of each record of each table is stored in its own location in storage."}),"\n",(0,n.jsx)(s.p,{children:"The location of the static-length data is determined by a hash of the table ID and the key tuple.\nSince data is tightly packed, fields may wrap around two storage slots."}),"\n",(0,n.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"_getStaticDataLocation"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"ResourceId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bytes32"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple) "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"internal"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"pure"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"returns"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"return"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(SLOT "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"keccak256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(abi."}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"encodePacked"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple)));"})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsxs)(s.a,{href:"#encoded-lengths",children:["The ",(0,n.jsx)(s.code,{children:"encodedLengths"})," field"]})," (the length of all dynamic-length fields) is stored in a single storage slot, which is determined by a hash of the table ID and the key tuple."]}),"\n",(0,n.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"_getDynamicDataLengthLocation"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"ResourceId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bytes32"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple) "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"internal"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"pure"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"returns"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"return"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(DYNAMIC_DATA_LENGTH_SLOT "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"keccak256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(abi."}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"encodePacked"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple)));"})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),"\n",(0,n.jsx)(s.p,{children:"The data for each dynamic-length field is stored in its own location in storage, which is determined by a hash of the table ID, the key tuple, and the field index.\nThis allows MUD to change the length of a dynamic-length field without having to move the data of other fields."}),"\n",(0,n.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,n.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"_getDynamicDataLocation"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"ResourceId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bytes32"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint8"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" dynamicFieldIndex"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"internal"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"pure"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"returns"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"return"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(DYNAMIC_DATA_SLOT "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bytes1"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(dynamicFieldIndex) "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"keccak256"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(abi."}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"encodePacked"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(tableId"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyTuple)));"})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})})]})}s.default=(0,i.j)(c)},24737:function(e){e.exports={collapsed:"CollapseCode_collapsed__D1CXB",expanded:"CollapseCode_expanded__x1xKU"}}},function(e){e.O(0,[3720,2888,179],function(){return e(e.s=40157)}),_N_E=e.O()}]);