@@ -17,6 +17,7 @@ import { readContract, waitForTransactionReceipt } from "viem/actions";
1717import chalk from "chalk" ;
1818import { StoreRecord } from "./executeMirrorPlan" ;
1919import { debug } from "./debug" ;
20+ import { LibZip } from "solady" ;
2021
2122export function createRecordHandler ( {
2223 client,
@@ -127,8 +128,8 @@ Estimated L2 cost at 100k wei: ${parseFloat(formatEther(BigInt(estimatedGas) * 1
127128 } ) ;
128129
129130 const changedRecords = records . filter ( ( record , i ) => {
130- const recordEncoded = encodeAbiParameters ( tableRecordAbi , [ record ] ) ;
131- const existingRecordEncoded = encodeAbiParameters ( tableRecordAbi , [ existingRecords [ i ] ] ) ;
131+ const recordEncoded = encodeAbiParameters ( [ tableRecordAbiItem ] , [ record ] ) ;
132+ const existingRecordEncoded = encodeAbiParameters ( [ tableRecordAbiItem ] , [ existingRecords [ i ] ] ) ;
132133 if ( recordEncoded === existingRecordEncoded ) return false ;
133134 // console.log("record changed in", record.tableId);
134135 // console.log(" ", recordEncoded);
@@ -139,12 +140,24 @@ Estimated L2 cost at 100k wei: ${parseFloat(formatEther(BigInt(estimatedGas) * 1
139140 return ;
140141 }
141142
143+ const calldata = encodeAbiParameters (
144+ [ { type : "bytes32" } , tableRecordsAbiItem ] ,
145+ [ changedRecords [ 0 ] . tableId , changedRecords ] ,
146+ ) ;
142147 const args = encodeSystemCall ( {
143148 systemId : batchStoreConfig . systems . BatchStoreSystem . systemId ,
144149 abi : batchStoreSystemAbi ,
145- functionName : "_setTableRecords " ,
146- args : [ changedRecords [ 0 ] . tableId , changedRecords ] ,
150+ functionName : "_setTableRecords_flz " ,
151+ args : [ LibZip . flzCompress ( calldata ) as Hex ] ,
147152 } ) ;
153+ // console.log(
154+ // "flz compression",
155+ // size(calldata),
156+ // "=>",
157+ // size(LibZip.flzCompress(calldata) as Hex),
158+ // " = ",
159+ // size(LibZip.flzCompress(calldata) as Hex) / size(calldata),
160+ // );
148161 const hash = await writeContract ( client , {
149162 chain : client . chain ?? null ,
150163 address : worldAddress ,
@@ -159,35 +172,59 @@ Estimated L2 cost at 100k wei: ${parseFloat(formatEther(BigInt(estimatedGas) * 1
159172 return { set, finalize } ;
160173}
161174
162- const tableRecordAbi = [
163- {
164- name : "record" ,
165- type : "tuple" ,
166- internalType : "struct TableRecord" ,
167- components : [
168- {
169- name : "keyTuple" ,
170- type : "bytes32[]" ,
171- internalType : "bytes32[]" ,
172- } ,
173- {
174- name : "staticData" ,
175- type : "bytes" ,
176- internalType : "bytes" ,
177- } ,
178- {
179- name : "encodedLengths" ,
180- type : "bytes32" ,
181- internalType : "EncodedLengths" ,
182- } ,
183- {
184- name : "dynamicData" ,
185- type : "bytes" ,
186- internalType : "bytes" ,
187- } ,
188- ] ,
189- } ,
190- ] as const ;
175+ const tableRecordAbiItem = {
176+ type : "tuple" ,
177+ internalType : "struct TableRecord" ,
178+ components : [
179+ {
180+ name : "keyTuple" ,
181+ type : "bytes32[]" ,
182+ internalType : "bytes32[]" ,
183+ } ,
184+ {
185+ name : "staticData" ,
186+ type : "bytes" ,
187+ internalType : "bytes" ,
188+ } ,
189+ {
190+ name : "encodedLengths" ,
191+ type : "bytes32" ,
192+ internalType : "EncodedLengths" ,
193+ } ,
194+ {
195+ name : "dynamicData" ,
196+ type : "bytes" ,
197+ internalType : "bytes" ,
198+ } ,
199+ ] ,
200+ } as const ;
201+
202+ const tableRecordsAbiItem = {
203+ type : "tuple[]" ,
204+ internalType : "struct TableRecord[]" ,
205+ components : [
206+ {
207+ name : "keyTuple" ,
208+ type : "bytes32[]" ,
209+ internalType : "bytes32[]" ,
210+ } ,
211+ {
212+ name : "staticData" ,
213+ type : "bytes" ,
214+ internalType : "bytes" ,
215+ } ,
216+ {
217+ name : "encodedLengths" ,
218+ type : "bytes32" ,
219+ internalType : "EncodedLengths" ,
220+ } ,
221+ {
222+ name : "dynamicData" ,
223+ type : "bytes" ,
224+ internalType : "bytes" ,
225+ } ,
226+ ] ,
227+ } ;
191228
192229const batchStoreSystemAbi = [
193230 {
@@ -248,6 +285,19 @@ const batchStoreSystemAbi = [
248285 outputs : [ ] ,
249286 stateMutability : "nonpayable" ,
250287 } ,
288+ {
289+ type : "function" ,
290+ name : "_setTableRecords_flz" ,
291+ inputs : [
292+ {
293+ name : "data" ,
294+ type : "bytes" ,
295+ internalType : "bytes" ,
296+ } ,
297+ ] ,
298+ outputs : [ ] ,
299+ stateMutability : "nonpayable" ,
300+ } ,
251301 {
252302 type : "function" ,
253303 name : "deleteTableRecords" ,
0 commit comments