Address Contract Verified
Address
0xdB66F0Dc1C50335CD5EA59E3DC10aF9585a27f55
Balance
0 ETH
Nonce
25
Code Size
24566 bytes
Creator
0x5CB8d03a...ADa0 at tx 0x89d6afe3...91f575
Indexed Transactions
0
Contract Bytecode
24566 bytes
0x608060405260043610610371575f3560e01c806384b0196e116101c8578063c2fa7c85116100fd578063d846782b1161009d578063f04e283e1161006d578063f04e283e14610a4f578063f2fde38b14610a62578063feb6172414610a75578063fee81cf414610aa3575f5ffd5b8063d846782b146109dc578063d972a9af146109fb578063ecebf3d814610a0f578063ee5c4e5d14610a2e575f5ffd5b8063cd8686a9116100d8578063cd8686a91461094b578063d27b0afc1461097f578063d56d229d1461099e578063d6e58ca4146109bd575f5ffd5b8063c2fa7c85146108ee578063c550ca5d1461090d578063c87b56dd1461092c575f5ffd5b80639d9af4b411610168578063b94281f411610143578063b94281f414610866578063bdf39f6f14610885578063bf43db8b146108a4578063c01bd0e9146108c3575f5ffd5b80639d9af4b4146107fd578063a764fc771461081c578063b378ac401461083b575f5ffd5b80638da5cb5b116101a35780638da5cb5b1461077a57806390f5dd5314610792578063944303a8146107ab57806399b18394146107de575f5ffd5b806384b0196e14610715578063870d3ca11461073c57806389d8aeca1461075b575f5ffd5b80633ac0800b116102a95780635cda2c5e116102495780636fb9ec5d116102195780636fb9ec5d146106bb578063715018a6146106cf5780638165fd8b146106d75780638360b35e146106f6575f5ffd5b80635cda2c5e14610645578063600eb4d01461065e5780636b971ec91461067d5780636c19e7831461069c575f5ffd5b80635112711a116102845780635112711a146105b6578063518108d61461060557806352f5ad771461061e57806354d1f13d1461063d575f5ffd5b80633ac0800b1461055e578063426c7453146105775780635007346814610596575f5ffd5b806330f848181161031457806338525d85116102ef57806338525d85146104db578063388dd6911461050c5780633939726e14610520578063394512511461053f575f5ffd5b806330f8481814610479578063313c98461461049957806333fcbca7146104bc575f5ffd5b806321ceb8d51161034f57806321ceb8d514610405578063238ac93314610426578063256929621461045d5780632ebc4a1114610465575f5ffd5b8063162a863a146103755780631676ac72146103aa578063210dfeb1146103d5575b5f5ffd5b348015610380575f5ffd5b5061039461038f3660046142f8565b610ad4565b6040516103a19190614346565b60405180910390f35b3480156103b5575f5ffd5b506009546103c39060ff1681565b60405160ff90911681526020016103a1565b3480156103e0575f5ffd5b506003546103f590600160a81b900460ff1681565b60405190151581526020016103a1565b348015610410575f5ffd5b5061042461041f366004614365565b610b6b565b005b348015610431575f5ffd5b50601054610445906001600160a01b031681565b6040516001600160a01b0390911681526020016103a1565b610424610b91565b348015610470575f5ffd5b50610424610bdd565b348015610484575f5ffd5b506003546103f590600160b01b900460ff1681565b3480156104a4575f5ffd5b506104ae6103e981565b6040519081526020016103a1565b3480156104c7575f5ffd5b506104246104d6366004614365565b610c1a565b3480156104e6575f5ffd5b506104fa6104f53660046142f8565b610c40565b6040516103a196959493929190614380565b348015610517575f5ffd5b50610424610d0c565b34801561052b575f5ffd5b5061042461053a366004614365565b610d48565b34801561054a575f5ffd5b50600354610445906001600160a01b031681565b348015610569575f5ffd5b506012546103f59060ff1681565b348015610582575f5ffd5b5061042461059136600461440a565b610d97565b3480156105a1575f5ffd5b506003546103f590600160a01b900460ff1681565b3480156105c1575f5ffd5b506105d56105d0366004614448565b610e73565b6040805161ffff909416845265ffffffffffff90921660208401526001600160a01b0316908201526060016103a1565b348015610610575f5ffd5b506007546103c39060ff1681565b348015610629575f5ffd5b5061042461063836600461445f565b610ead565b610424610efe565b348015610650575f5ffd5b506005546103c39060ff1681565b348015610669575f5ffd5b50610424610678366004614485565b610f37565b348015610688575f5ffd5b50610424610697366004614557565b6112c9565b3480156106a7575f5ffd5b506104246106b636600461445f565b611400565b3480156106c6575f5ffd5b50610394611478565b610424611485565b3480156106e2575f5ffd5b506104246106f136600461445f565b611498565b348015610701575f5ffd5b50610424610710366004614557565b6114e9565b348015610720575f5ffd5b5061072961159b565b6040516103a19796959493929190614589565b348015610747575f5ffd5b50610424610756366004614557565b6115f8565b348015610766575f5ffd5b50610424610775366004614365565b6116a1565b348015610785575f5ffd5b50638b78c6d81954610445565b34801561079d575f5ffd5b50600b546103c39060ff1681565b3480156107b6575f5ffd5b506104ae7f04670f06d56d017ed42f57204cf59d457ff32b8a552ede1e4218883669d3307981565b3480156107e9575f5ffd5b506104246107f836600461440a565b6116c7565b348015610808575f5ffd5b5061042461081736600461440a565b61178f565b348015610827575f5ffd5b50610424610836366004614557565b611857565b348015610846575f5ffd5b506104ae610855366004614448565b600e6020525f908152604090205481565b348015610871575f5ffd5b50610424610880366004614557565b61193c565b348015610890575f5ffd5b5061042461089f36600461440a565b6119e5565b3480156108af575f5ffd5b506104246108be36600461461f565b611a98565b3480156108ce575f5ffd5b506104ae6108dd366004614448565b600c6020525f908152604090205481565b3480156108f9575f5ffd5b5061042461090836600461461f565b611b56565b348015610918575f5ffd5b50600d54610445906001600160a01b031681565b348015610937575f5ffd5b50610394610946366004614448565b611e09565b348015610956575f5ffd5b50610445610965366004614448565b600f6020525f90815260409020546001600160a01b031681565b34801561098a575f5ffd5b506103946109993660046142f8565b611eee565b3480156109a9575f5ffd5b50601954610445906001600160a01b031681565b3480156109c8575f5ffd5b506103946109d73660046142f8565b611f06565b3480156109e7575f5ffd5b506104246109f6366004614557565b611f1e565b348015610a06575f5ffd5b50610424612004565b348015610a1a575f5ffd5b50610424610a2936600461440a565b612041565b348015610a39575f5ffd5b50610a4261205b565b6040516103a19190614689565b610424610a5d36600461445f565b6120e2565b610424610a7036600461445f565b61211f565b348015610a80575f5ffd5b506103f5610a8f366004614448565b60116020525f908152604090205460ff1681565b348015610aae575f5ffd5b506104ae610abd36600461445f565b63389a75e1600c9081525f91909152602090205490565b60086020525f908152604090208054610aec906146e8565b80601f0160208091040260200160405190810160405280929190818152602001828054610b18906146e8565b8015610b635780601f10610b3a57610100808354040283529160200191610b63565b820191905f5260205f20905b815481529060010190602001808311610b4657829003601f168201915b505050505081565b610b73612145565b60038054911515600160a01b0260ff60a01b19909216919091179055565b5f6202a3006001600160401b03164201905063389a75e1600c52335f52806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f5fa250565b610be5612145565b610bf060025f61426e565b6040517f0e395b26eb5db059ef862ec935b94bf7c83763eeca9bddb4955b47dd1ada1942905f90a1565b610c22612145565b60038054911515600160a81b0260ff60a81b19909216919091179055565b60046020525f9081526040902080548190610c5a906146e8565b80601f0160208091040260200160405190810160405280929190818152602001828054610c86906146e8565b8015610cd15780601f10610ca857610100808354040283529160200191610cd1565b820191905f5260205f20905b815481529060010190602001808311610cb457829003601f168201915b5050506001909301549192505060ff808216916101008104821691620100008204811691630100000081048216916401000000009091041686565b610d14612145565b610d1e5f8061426e565b6040517f9d8810d9c5b5a56a703fe3172c7c06ed179bc09f3e6051c0f0a2f477890ef686905f90a1565b610d50612145565b6012805460ff19168215159081179091556040519081527ff62973d8836742c6d707e39dbdb1b01436dc195b01306f9d94ed6d6c97386cca9060200160405180910390a150565b610d9f612145565b5f819003610dc0576040516399d8fec960e01b815260040160405180910390fd5b6001610e0083838080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061215f92505050565b8154600180820184555f93845260209093200180546001600160a01b0319166001600160a01b039290921691909117905580547fa50e1c6e5ebbe420bcc8cc3423c93f3f08dd8af7cb022cec7a47c19c036d017991610e5e91614734565b60405190815260200160405180910390a15050565b60148160058110610e82575f80fd5b015461ffff8116915062010000810465ffffffffffff1690600160401b90046001600160a01b031683565b610eb5612145565b601980546001600160a01b0319166001600160a01b0383169081179091556040517fa27bdd7b0c9c795c64307abe4a8b21d993ec4bd2601c38dfaee5cfc991375ae8905f90a250565b63389a75e1600c52335f525f6020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c925f5fa2565b60125460ff16610f5a576040516322ce565360e11b815260040160405180910390fd5b82421115610f7b5760405163f87d927160e01b815260040160405180910390fd5b5f8481526011602052604090205460ff1615610fa957604051623f613760e71b815260040160405180910390fd5b6019546001600160a01b03161561104257601954604051634f558e7960e01b8152600481018a90526001600160a01b0390911690634f558e7990602401602060405180830381865afa158015611001573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110259190614747565b6110425760405163c1ab6dc160e01b815260040160405180910390fd5b5f7f04670f06d56d017ed42f57204cf59d457ff32b8a552ede1e4218883669d3307989898989604051611076929190614762565b6040805191829003822060208301959095528101929092526060820152608081019190915260a0810186905260c0810185905260e0016040516020818303038152906040528051906020012090505f6110ce826121a0565b90505f6111108286868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152506122b692505050565b6010549091506001600160a01b0380831691161461114157604051638baa579f60e01b815260040160405180910390fd5b5f878152601160209081526040808320805460ff191660011790558d8352600e9091529020548a11611186576040516358c4262360e11b815260040160405180910390fd5b5f8b8152600e602090815260408083208d9055600f909152902080546001600160a01b031916339081179091556111c0908c908c90612342565b6040518a815233908c907ffdeaad9f62c24dd107d87ba2c0b144114dec62d178cad522394390f1d233a62c9060200160405180910390a36019546001600160a01b0316156112bc576019546040516318c85cf560e11b8152600481018d90526001600160a01b0390911690633190b9ea906024015f604051808303815f87803b15801561124b575f5ffd5b505af115801561125d573d5f5f3e3d5ffd5b50506019546040516318c85cf560e11b81526103e960048201526001600160a01b039091169250633190b9ea91506024015f604051808303815f87803b1580156112a5575f5ffd5b505af11580156112b7573d5f5f3e3d5ffd5b505050505b5050505050505050505050565b6112d1612145565b6002545f5b828110156113fa578383828181106112f0576112f0614771565b90506020028101906113029190614785565b90505f03611323576040516399d8fec960e01b815260040160405180910390fd5b600261138585858481811061133a5761133a614771565b905060200281019061134c9190614785565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061215f92505050565b81546001810183555f928352602090922090910180546001600160a01b0319166001600160a01b039092169190911790557f33d43964bbac8fce8fbf2e1270b421c4c629ba08e661d75a6a8db1712003e9146113e182846147c7565b60405190815260200160405180910390a16001016112d6565b50505050565b611408612145565b6001600160a01b03811661142f5760405163d92e233d60e01b815260040160405180910390fd5b601080546001600160a01b0319166001600160a01b0383169081179091556040517f5553331329228fbd4123164423717a4a7539f6dfa1c3279a923b98fd681a6c73905f90a250565b60138054610aec906146e8565b61148d612145565b6114965f612622565b565b6114a0612145565b600d80546001600160a01b0319166001600160a01b0383169081179091556040517f30dcc34aca6d5928b57bfe50e7af27390db8d0fa24885122395e53391dee1399905f90a250565b6114f1612145565b805f5b8160ff168160ff16101561154f5783838260ff1681811061151757611517614771565b90506020028101906115299190614785565b60ff83165f908152600a6020526040902091611546919083614839565b506001016114f4565b50600b805460ff191660ff83169081179091556040519081527fb12f620125edddee320694666316c0498751688eab4f2ac9bdf1b93e1b686a82906020015b60405180910390a1505050565b600f60f81b6060805f8080836115e6604080518082018252600a815269436172706f6f6c65727360b01b602080830191909152825180840190935260018352603160f81b9083015291565b97989097965046955030945091925090565b611600612145565b805f5b8160ff168160ff16101561165e5783838260ff1681811061162657611626614771565b90506020028101906116389190614785565b60ff83165f90815260066020526040902091611655919083614839565b50600101611603565b506007805460ff191660ff83169081179091556040519081527fd6d4728380d1ad5481dfc27d9ceeac3b1ee9c6a0bf8a57ad62ed0335a25d48549060200161158e565b6116a9612145565b60038054911515600160b01b0260ff60b01b19909216919091179055565b6116cf612145565b5f8190036116f0576040516399d8fec960e01b815260040160405180910390fd5b5f61172f83838080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061215f92505050565b8154600180820184555f9384526020842090910180546001600160a01b0319166001600160a01b03939093169290921790915590547fbf9b70448c9c18dbeaa2bfc27dedf97e8e340dbfcc7afc105048e4d66c59afa891610e5e91614734565b611797612145565b5f8190036117b8576040516399d8fec960e01b815260040160405180910390fd5b60026117f883838080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061215f92505050565b8154600180820184555f93845260209093200180546001600160a01b0319166001600160a01b03929092169190911790556002547f33d43964bbac8fce8fbf2e1270b421c4c629ba08e661d75a6a8db1712003e91491610e5e91614734565b61185f612145565b5f8054905b828110156113fa5783838281811061187e5761187e614771565b90506020028101906118909190614785565b90505f036118b1576040516399d8fec960e01b815260040160405180910390fd5b5f6118c785858481811061133a5761133a614771565b81546001810183555f928352602090922090910180546001600160a01b0319166001600160a01b039092169190911790557fbf9b70448c9c18dbeaa2bfc27dedf97e8e340dbfcc7afc105048e4d66c59afa861192382846147c7565b60405190815260200160405180910390a1600101611864565b611944612145565b805f5b8160ff168160ff1610156119a25783838260ff1681811061196a5761196a614771565b905060200281019061197c9190614785565b60ff83165f90815260086020526040902091611999919083614839565b50600101611947565b506009805460ff191660ff83169081179091556040519081527fbc921e2941781caa4d0d58b49252dc21f1ac02a573ed8c21074499f99e9189d49060200161158e565b6119ed612145565b5f819003611a0e576040516399d8fec960e01b815260040160405180910390fd5b611a4c82828080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061215f92505050565b600380546001600160a01b0319166001600160a01b03929092169190911790556040517f93c9bc6e156749b7c5278be55263a55f56774285eb3bc080c4ae149427634cc8905f90a15050565b611aa0612145565b828114611ac3576040516001621398b960e31b0319815260040160405180910390fd5b5f5b83811015611b1c57828282818110611adf57611adf614771565b90506020020135600c5f878785818110611afb57611afb614771565b602090810292909201358352508101919091526040015f2055600101611ac5565b506040518381527f0512828aa9290dfa16f5af618ce67bc36a663036c4e7c72d22ff8c7a500bd2b49060200160405180910390a150505050565b611b5e612145565b828114611b81576040516001621398b960e31b0319815260040160405180910390fd5b825f5b8160ff168160ff161015611dbc575f84848360ff16818110611ba857611ba8614771565b9050602002810190611bba9190614785565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250506040805160c081019091529293508291508990508860ff8616818110611c1357611c13614771565b9050602002810190611c259190614785565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201829052509385525050845160209093019285929150611c7157611c71614771565b0160209081015160f81c8252835191019083906001908110611c9557611c95614771565b0160209081015160f81c8252835191019083906002908110611cb957611cb9614771565b0160209081015160f81c8252835191019083906003908110611cdd57611cdd614771565b0160209081015160f81c8252835191019083906004908110611d0157611d01614771565b0160209081015160f81c90915260ff84165f90815260049091526040902081518190611d2d90826148f2565b5060208201516001918201805460408501516060860151608087015160a09097015160ff9081166401000000000264ff000000001998821663010000000263ff0000001993831662010000029390931663ffff0000199483166101000261ffff199096169290971691909117939093179190911693909317929092179390931617909155919091019050611b84565b506005805460ff191660ff83169081179091556040519081527f1d433279870bf4e6cbc4ca0334e25e96470a41cb19851a0975bc5c9ee0aa8cbf9060200160405180910390a15050505050565b60606103e98203611e2257611e1c61265f565b92915050565b5f828152600c6020908152604080832054600e90925290912054611ee6611e4a858484612861565b611e8b6040518060400160405280600d81526020016c185b9a5b585d1a5bdb97dd5c9b609a1b815250611e86611e8189888861294f565b612996565b6129c7565b611ec06040518060400160405280600a8152602001696174747269627574657360b01b815250611ebb87876129f3565b612a33565b604051602001611ed2939291906149c3565b604051602081830303815290604052612a48565b949350505050565b600a6020525f908152604090208054610aec906146e8565b60066020525f908152604090208054610aec906146e8565b611f26612145565b6001545f5b828110156113fa57838382818110611f4557611f45614771565b9050602002810190611f579190614785565b90505f03611f78576040516399d8fec960e01b815260040160405180910390fd5b6001611f8f85858481811061133a5761133a614771565b81546001810183555f928352602090922090910180546001600160a01b0319166001600160a01b039092169190911790557fa50e1c6e5ebbe420bcc8cc3423c93f3f08dd8af7cb022cec7a47c19c036d0179611feb82846147c7565b60405190815260200160405180910390a1600101611f2b565b61200c612145565b61201760015f61426e565b6040517f010c033a28f96ee5dff90a75d579d42f95df07a19e9e3f10aaf45fa69816495d905f90a1565b612049612145565b6013612056828483614839565b505050565b612063614289565b5f5b60058110156120de576014816005811061208157612081614771565b60408051606081018252929091015461ffff8116835265ffffffffffff6201000082041660208401526001600160a01b03600160401b90910416908201528282600581106120d1576120d1614771565b6020020152600101612065565b5090565b6120ea612145565b63389a75e1600c52805f526020600c20805442111561211057636f5e88185f526004601cfd5b5f905561211c81612622565b50565b612127612145565b8060601b61213c57637448fbae5f526004601cfd5b61211c81612622565b638b78c6d819543314611496576382b429005f526004601cfd5b5f81518060401b6bfe61000180600a3d393df3000161fffe8211840152600b8101601584015ff091508161219a5763301164255f526004601cfd5b90915290565b7fac093902c228299d9d2b6a51cea1c92e00af2f7e1016e5e50e25e0497af1432e7f000000000000000000000000db66f0dc1c50335cd5ea59e3dc10af9585a27f5530147f00000000000000000000000000000000000000000000000000000000000000014614166122935750604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81527f237a246b386a3beac2359bf26ff9747478acb8ba606dbc17a3e56aee61c8cf7f60208201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc69181019190915246606082015230608082015260a090205b6719010000000000005f5280601a5281603a52604260182090505f603a52919050565b5f6040518251604081146122d257604181146122f3575061232e565b604084015160ff81901c601b016020526001600160ff1b0316606052612306565b60608401515f1a60205260408401516060525b50835f5260208301516040526020600160805f60015afa5191505f606052806040523d61233b575b638baa579f5f526004601cfd5b5092915050565b5f5b600581101561246b578361ffff166014826005811061236557612365614771565b015461ffff1614801561239957505f6014826005811061238757612387614771565b015462010000900465ffffffffffff16115b1561246357805b600481101561244d5760146123b68260016147c7565b600581106123c6576123c6614771565b01601482600581106123da576123da614771565b82549101805461ffff19811661ffff9093169283178255835465ffffffffffff6201000091829004160267ffffffffffffffff199091169092179190911780825591546001600160a01b03600160401b918290041602600160401b600160e01b03199092169190911790556001016123a0565b50601880546001600160e01b031916905561246b565b600101612344565b5060055f5b60058110156124b7576014816005811061248c5761248c614771565b015465ffffffffffff62010000909104811690851611156124af578091506124b7565b600101612470565b5060048111156124c75750505050565b60045b8181111561257e5760146124df600183614734565b600581106124ef576124ef614771565b016014826005811061250357612503614771565b82549101805461ffff19811661ffff9093169283178255835465ffffffffffff6201000091829004160267ffffffffffffffff199091169092179190911780825591546001600160a01b03600160401b918290041602600160401b600160e01b031990921691909117905561257781614a16565b90506124ca565b5060405180606001604052808561ffff1681526020018465ffffffffffff168152602001836001600160a01b0316815250601482600581106125c2576125c2614771565b82519101805460208401516040909401516001600160a01b0316600160401b02600160401b600160e01b031965ffffffffffff909516620100000267ffffffffffffffff1990921661ffff90941693909317179290921617905550505050565b638b78c6d81980546001600160a01b039092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a355565b600d5460609081906001600160a01b03161561282b5761267d6142c6565b6126856142c6565b61268d6142c6565b5f5b600581101561276a57601481600581106126ab576126ab614771565b015461ffff168482600581106126c3576126c3614771565b61ffff9092166020929092020152601481600581106126e4576126e4614771565b015462010000900465ffffffffffff1683826005811061270657612706614771565b65ffffffffffff90921660209290920201526014816005811061272b5761272b614771565b0154600160401b90046001600160a01b031682826005811061274f5761274f614771565b6001600160a01b03909216602092909202015260010161268f565b506040805180820182526005815264696d61676560d81b6020820152600d54915162cbcbc960e71b815261280692611e86916001600160a01b03909116906365e5e480906127c090899089908990600401614a56565b5f60405180830381865afa1580156127da573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526128019190810190614ac4565b612a63565b6040516020016128169190614b74565b60405160208183030381529060405293505050505b61285b8161284a60145f015462010000900465ffffffffffff16612a7e565b604051602001611ed2929190614b90565b91505090565b60606128b0604051806040016040528060048152602001636e616d6560e01b81525061288c86612a99565b60405160200161289c9190614c15565b6040516020818303038152906040526129c7565b6128f56040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250604051806060016040528060378152602001615f45603791396129c7565b61292460405180604001604052806005815260200164696d61676560d81b815250611e86612801898989612adb565b60405160200161293693929190614c35565b60405160208183030381529060405290505b9392505050565b6003546060906001600160a01b031661297b576040516377c45edd60e11b815260040160405180910390fd5b612986848484612bb7565b6040516020016129369190614c74565b60606129a182612d6e565b6040516020016129b19190614e7f565b6040516020818303038152906040529050919050565b606082826040516020016129dc929190614ea9565b604051602081830303815290604052905092915050565b606082612a2957612a0382612a7e565b604051602001612a139190614ee7565b6040516020818303038152906040529050611e1c565b6129488383612d7b565b606082826040516020016129dc929190614f0d565b6060612a5382612d6e565b6040516020016129b19190614f40565b6060612a6e82612d6e565b6040516020016129b19190614f71565b6060612a8982612a99565b6040516020016129b19190614fa2565b60606080604051019050602081016040525f8152805f19835b928101926030600a8206018453600a900480612ab2575050819003601f19909101908152919050565b600d546060906001600160a01b031615801590612af757508215155b15612bac57600d546001600160a01b0316633e70456f858585612b21612b1c83612e7e565b612e89565b612b32612b2d8a612f5f565b612f68565b612b43612b3e8b61303a565b613043565b6040518763ffffffff1660e01b8152600401612b6496959493929190614ff0565b5f60405180830381865afa158015612b7e573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612ba59190810190614ac4565b9050612948565b611ee68484846130c1565b6003546060905f90612bd1906001600160a01b0316613259565b90505f612bdd5f613285565b90505f612bea6001613285565b90505f612bf76002613285565b90505f612c0384612d6e565b90505f612c0f84612d6e565b90505f612c1b84612d6e565b6003549091505f90600160a01b900460ff16612c5057604051806040016040528060018152602001600360fc1b815250612c6b565b604051806040016040528060018152602001603160f81b8152505b6003548590600160a81b900460ff16612c9d57604051806040016040528060018152602001600360fc1b815250612cb8565b604051806040016040528060018152602001603160f81b8152505b6003548690600160b01b900460ff16612cea57604051806040016040528060018152602001600360fc1b815250612d05565b604051806040016040528060018152602001603160f81b8152505b86604051602001612d1b96959493929190615047565b6040516020818303038152906040529050612d378c8c8c6132f5565b60138983604051602001612d4e9493929190615103565b604051602081830303815290604052985050505050505050509392505050565b6060611e1c825f5f61338c565b60605f612d8f612d8a8561347e565b613487565b90505f612da3612d9e86613553565b61355c565b9050612dd6604051806040016040528060048152602001634369747960e01b815250612dd1612b1c88612e7e565b61359f565b612e0860405180604001604052806005815260200164537461746560d81b815250612dd1612e03896135b4565b6135bd565b612e3c60405180604001604052806007815260200166436f756e74727960c81b815250612dd1612e378a6135ed565b6135f6565b612e46888661363f565b612e5189868a6137b4565b604051602001612e659594939291906154c4565b6040516020818303038152906040529250505092915050565b5f81815b1a92915050565b60055460609060ff9081169083161015612f3c5760ff82165f9081526004602052604090208054612eb9906146e8565b80601f0160208091040260200160405190810160405280929190818152602001828054612ee5906146e8565b8015612f305780601f10612f0757610100808354040283529160200191612f30565b820191905f5260205f20905b815481529060010190602001808311612f1357829003601f168201915b50505050509050919050565b50506040805180820190915260078152663ab735b737bbb760c91b602082015290565b5f816001612e82565b60608160ff165f03612f9557505060408051808201909152600581526473756e6e7960d81b602082015290565b8160ff16600103612fc2575050604080518082019091526006815265636c6f75647960d01b602082015290565b8160ff16600203612fed5750506040805180820190915260048152633930b4b760e11b602082015290565b8160ff1660030361301a5750506040805180820190915260068152651cdd5b9cd95d60d21b602082015290565b5050604080518082019091526004815263736e6f7760e01b602082015290565b5f816002612e82565b60608160ff165f036130725750506040805180820190915260078152666d6f726e696e6760c81b602082015290565b8160ff166001036130a05750506040805180820190915260078152666576656e696e6760c81b602082015290565b50506040805180820190915260058152641b9a59da1d60da1b602082015290565b60605f836130cf575f6130d8565b6130d88461303a565b90505f846130e6575f6130f1565b6001600386901a8116145b90505f8561311e57604051806040016040528060078152602001663ab735b737bbb760c91b81525061312a565b61312a612b1c87612e7e565b90506060808460ff165f0361318257604051806040016040528060078152602001660236666393034360cc1b8152509150604051806040016040528060078152602001660233430383063360cc1b815250905061321b565b8460ff166001036131d657604051806040016040528060078152602001660233830343061360cc1b8152509150604051806040016040528060078152602001660236430363032360cc1b815250905061321b565b604051806040016040528060078152602001662330613061326160c81b8152509150604051806040016040528060078152602001660233130313033360cc1b81525090505b818161322a8b8888888d61392e565b60405160200161323c93929190615545565b604051602081830303815290604052955050505050509392505050565b60405164ffffffffff5f19833b0116602181015f601f8401853c80825260408201810160405250919050565b80546060905f5b818110156132ee57826132c38583815481106132aa576132aa614771565b5f918252602090912001546001600160a01b0316613259565b6040516020016132d49291906156d5565b60408051601f19818403018152919052925060010161328c565b5050919050565b6060826133815761330584612a99565b61330e83612a99565b60125460ff1661333b576040518060400160405280600581526020016466616c736560d81b815250613359565b604051806040016040528060048152602001637472756560e01b8152505b60405160200161336b939291906156e3565b6040516020818303038152906040529050612948565b611ee68484846139f9565b606083518015613476576003600282010460021b60405192507f4142434445464748494a4b4c4d4e4f505152535455565758595a616263646566601f526106708515027f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392d5f18603f526020830181810183886020010180515f82525b60038a0199508951603f8160121c16515f53603f81600c1c1651600153603f8160061c1651600253603f811651600353505f518452600484019350828410613407579052602001604052613d3d60f01b60038406600204808303919091525f8615159091029182900352900382525b509392505050565b5f816006612e82565b60608160ff165f036134a657505060408051602081019091525f815290565b8160ff166001036134d657505060408051808201909152600981526831b0b934b13132b0b760b91b602082015290565b8160ff166002036135045750506040805180820190915260078152667061636966696360c81b602082015290565b8160ff1660030361352f57505060408051808201909152600481526333bab63360e11b602082015290565b505060408051808201909152600881526761746c616e74696360c01b602082015290565b5f816009612e82565b60095460609060ff908116908316101561358c5760ff82165f9081526008602052604090208054612eb9906146e8565b505060408051602081019091525f815290565b606082826040516020016129dc929190615785565b5f816008612e82565b60075460609060ff9081169083161015612f3c5760ff82165f9081526006602052604090208054612eb9906146e8565b5f81600c612e82565b606060ff8216156136215760405180604001604052806002815260200161555360f01b815250611e1c565b505060408051808201909152600281526109ab60f31b602082015290565b60606136736040518060400160405280600581526020016442696f6d6560d81b815250612dd161366e86613aeb565b613af4565b6136a76040518060400160405280600781526020016650726f66696c6560c81b815250612dd16136a287613bfa565b613c03565b6136d6604051806040016040528060078152602001662bb2b0ba3432b960c91b815250612dd1612b2d88612f5f565b6137096040518060400160405280600b81526020016a54696d65206f662044617960a81b815250612dd1612b3e8961303a565b5f8651116137255760405180602001604052805f81525061376e565b61374e604051806040016040528060078152602001665365617369646560c81b8152508761359f565b60405160200161375e9190614b74565b6040516020818303038152906040525b61379f60405180604001604052806004815260200163149bd85960e21b815250612dd161379a8b613d0f565b613d18565b6040516020016129dc969594939291906157da565b606061383b604051806040016040528060098152602001682234b932b1ba34b7b760b91b8152506137ed86600160039190911a81161490565b6138155760405180604001604052806006815260200165139bdc9b585b60d21b81525061359f565b6040518060400160405280600881526020016714995d995c9cd95960c21b81525061359f565b60408051808201909152600781526656656869636c6560c81b60208201526138af906002600388901a81161461388e5760405180604001604052806005815260200164547275636b60d81b81525061359f565b6040518060400160405280600381526020016242757360e81b81525061359f565b5f8551116138cb5760405180602001604052805f815250613912565b6138f260405180604001604052806005815260200164547275636b60d81b8152508661359f565b6040516020016139029190614b74565b6040516020818303038152906040525b61391b85612a7e565b6040516020016129369493929190615844565b60605f8560ff166002146139505760405180602001604052805f81525061396a565b6040518060800160405280604e8152602001615eb2604e91395b90505f8561399057604051806080016040528060458152602001615f00604591396139aa565b604051806080016040528060458152602001615f7c604591395b905081816139b78a612a99565b6139c088613dcb565b6139c988613e90565b6040516020016139dd959493929190615887565b6040516020818303038152906040529250505095945050505050565b60605f613a08612d8a8561347e565b90505f613a1c613a1786614033565b61403c565b90505f613a2b612d9e87613553565b9050613a3687612a99565b613a42612b1c88612e7e565b613a4e61366e89613aeb565b613a5a6136a28a613bfa565b613a668a888888614097565b613a6f8a612a99565b60125460ff16613a9c576040518060400160405280600581526020016466616c736560d81b815250613aba565b604051806040016040528060048152602001637472756560e01b8152505b604051602001613ad09796959493929190615b80565b60405160208183030381529060405293505050509392505050565b5f816004612e82565b60608160ff165f03613b2257505060408051808201909152600681526519195cd95c9d60d21b602082015290565b8160ff16600103613b515750506040805180820190915260088152671d1c9bdc1a58d85b60c21b602082015290565b8160ff16600203613b7f57505060408051808201909152600781526618dbd85cdd185b60ca1b602082015290565b8160ff16600303613bae5750506040805180820190915260088152671a1a59da1b185b9960c21b602082015290565b8160ff16600403613bda5750506040805180820190915260058152643ab93130b760d91b602082015290565b50506040805180820190915260048152636d65736160e01b602082015290565b5f816005612e82565b60608160ff165f03613c31575050604080518082019091526006815265746f7765727360d01b602082015290565b8160ff16600103613c60575050604080518082019091526008815267636f6e637265746560c01b602082015290565b8160ff16600203613c8f57505060408051808201909152600881526718dbdb1bdb9a585b60c21b602082015290565b8160ff16600303613cbc5750506040805180820190915260068152651c995cdbdc9d60d21b602082015290565b8160ff16600403613ce9575050604080518082019091526006815265707565626c6f60d01b602082015290565b505060408051808201909152600a8152691a5b991d5cdd1c9a585b60b21b602082015290565b5f816007612e82565b60608160ff165f03613d475750506040805180820190915260078152666869676877617960c81b602082015290565b8160ff16600103613d77575050604080518082019091526009815268189bdd5b195d985c9960ba1b602082015290565b8160ff16600203613da35750506040805180820190915260058152641c9d5c985b60da1b602082015290565b505060408051808201909152600c81526b18dbd85cdd185b17dc9bd85960a21b602082015290565b6060815f5b815181101561233b57606160f81b828281518110613df057613df0614771565b01602001516001600160f81b03191610801590613e315750607a60f81b828281518110613e1f57613e1f614771565b01602001516001600160f81b03191611155b15613e88576020828281518110613e4a57613e4a614771565b0160200151613e5c919060f81c615ca8565b60f81b828281518110613e7157613e71614771565b60200101906001600160f81b03191690815f1a9053505b600101613dd0565b6060815f03613eb65750506040805180820190915260018152600360fc1b602082015290565b5f613ec083612a99565b8051909150819060038111613ed85750909392505050565b5f6003613ee6600184614734565b613ef09190615cd5565b90505f613efd82846147c7565b6001600160401b03811115613f1457613f146147da565b6040519080825280601f01601f191660200182016040528015613f3e576020820181803683370190505b508051909150835b80156140265785613f58600183614734565b81518110613f6857613f68614771565b01602001516001600160f81b03191683613f8184614a16565b93508381518110613f9457613f94614771565b60200101906001600160f81b03191690815f1a9053506003613fb68287614734565b613fc19060016147c7565b613fcb9190615ce8565b158015613fd85750600181115b1561401657600b60fa1b83613fec84614a16565b93508381518110613fff57613fff614771565b60200101906001600160f81b03191690815f1a9053505b61401f81614a16565b9050613f46565b5090979650505050505050565b5f81600d612e82565b60608160ff165f0361405b57505060408051602081019091525f815290565b600b5460ff9081169083161161358c57600a5f614079600185615ca8565b60ff1660ff1681526020019081526020015f208054612eb9906146e8565b60606140a5612b2d86612f5f565b6140b1612b3e8761303a565b6001600388901a8116146140e2576040518060400160405280600581526020016466616c736560d81b815250614100565b604051806040016040528060048152602001637472756560e01b8152505b61410c612e37896135ed565b5f8851116141285760405180602001604052805f815250614149565b876040516020016141399190615cfb565b6040516020818303038152906040525b61415561379a8b613d0f565b600260038c901a8116146141865760405180604001604052806005815260200164747275636b60d81b8152506141a3565b6040518060400160405280600381526020016262757360e81b8152505b6141c2600b8d901a600a8e901a60081b62ffff00161761ffff16612a99565b5f8a51116141de5760405180602001604052805f8152506141ff565b896040516020016141ef9190615d2a565b6040516020818303038152906040525b5f8c511161421b5760405180602001604052805f81525061423c565b8b60405160200161422c9190615d45565b6040516020818303038152906040525b6040516020016142559a99989796959493929190615d63565b6040516020818303038152906040529050949350505050565b5080545f8255905f5260205f209081019061211c91906142e4565b6040518060a001604052806005905b604080516060810182525f80825260208083018290529282015282525f199092019101816142985790505090565b6040518060a001604052806005906020820280368337509192915050565b5b808211156120de575f81556001016142e5565b5f60208284031215614308575f5ffd5b813560ff81168114612948575f5ffd5b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f6129486020830184614318565b801515811461211c575f5ffd5b5f60208284031215614375575f5ffd5b813561294881614358565b60c081525f61439260c0830189614318565b60ff97881660208401529587166040830152509285166060840152908416608083015290921660a090920191909152919050565b5f5f83601f8401126143d6575f5ffd5b5081356001600160401b038111156143ec575f5ffd5b602083019150836020828501011115614403575f5ffd5b9250929050565b5f5f6020838503121561441b575f5ffd5b82356001600160401b03811115614430575f5ffd5b61443c858286016143c6565b90969095509350505050565b5f60208284031215614458575f5ffd5b5035919050565b5f6020828403121561446f575f5ffd5b81356001600160a01b0381168114612948575f5ffd5b5f5f5f5f5f5f5f5f60c0898b03121561449c575f5ffd5b883597506020890135965060408901356001600160401b038111156144bf575f5ffd5b6144cb8b828c016143c6565b909750955050606089013593506080890135925060a08901356001600160401b038111156144f7575f5ffd5b6145038b828c016143c6565b999c989b5096995094979396929594505050565b5f5f83601f840112614527575f5ffd5b5081356001600160401b0381111561453d575f5ffd5b6020830191508360208260051b8501011115614403575f5ffd5b5f5f60208385031215614568575f5ffd5b82356001600160401b0381111561457d575f5ffd5b61443c85828601614517565b60ff60f81b8816815260e060208201525f6145a760e0830189614318565b82810360408401526145b98189614318565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b8181101561460e5783518352602093840193909201916001016145f0565b50909b9a5050505050505050505050565b5f5f5f5f60408587031215614632575f5ffd5b84356001600160401b03811115614647575f5ffd5b61465387828801614517565b90955093505060208501356001600160401b03811115614671575f5ffd5b61467d87828801614517565b95989497509550505050565b6101e0810181835f5b60058110156146df578151805161ffff16845260208082015165ffffffffffff16818601526040918201516001600160a01b03169185019190915260609093019290910190600101614692565b50505092915050565b600181811c908216806146fc57607f821691505b60208210810361471a57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115611e1c57611e1c614720565b5f60208284031215614757575f5ffd5b815161294881614358565b818382375f9101908152919050565b634e487b7160e01b5f52603260045260245ffd5b5f5f8335601e1984360301811261479a575f5ffd5b8301803591506001600160401b038211156147b3575f5ffd5b602001915036819003821315614403575f5ffd5b80820180821115611e1c57611e1c614720565b634e487b7160e01b5f52604160045260245ffd5b601f82111561205657805f5260205f20601f840160051c810160208510156148135750805b601f840160051c820191505b81811015614832575f815560010161481f565b5050505050565b6001600160401b03831115614850576148506147da565b6148648361485e83546146e8565b836147ee565b5f601f841160018114614895575f851561487e5750838201355b5f19600387901b1c1916600186901b178355614832565b5f83815260208120601f198716915b828110156148c457868501358255602094850194600190920191016148a4565b50868210156148e0575f1960f88860031b161c19848701351681555b505060018560011b0183555050505050565b81516001600160401b0381111561490b5761490b6147da565b61491f8161491984546146e8565b846147ee565b6020601f821160018114614951575f831561493a5750848201515b5f19600385901b1c1916600184901b178455614832565b5f84815260208120601f198516915b828110156149805787850151825560209485019460019092019101614960565b508482101561499d57868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f81518060208401855e5f93019283525090919050565b607b60f81b81525f6149d860018301866149ac565b600b60fa1b81526149ec60018201866149ac565b9050600b60fa1b8152614a0260018201856149ac565b607d60f81b81526001019695505050505050565b5f81614a2457614a24614720565b505f190190565b805f5b60058110156113fa5781516001600160a01b0316845260209384019390910190600101614a2e565b6101e0810181855f5b6005811015614a8257815161ffff16835260209283019290910190600101614a5f565b50505060a08201845f5b6005811015614ab357815165ffffffffffff16835260209283019290910190600101614a8c565b505050611ee6610140830184614a2b565b5f60208284031215614ad4575f5ffd5b81516001600160401b03811115614ae9575f5ffd5b8201601f81018413614af9575f5ffd5b80516001600160401b03811115614b1257614b126147da565b604051601f8201601f19908116603f011681016001600160401b0381118282101715614b4057614b406147da565b604052818152828201602001861015614b57575f5ffd5b8160208401602083015e5f91810160200191909152949350505050565b5f614b7f82846149ac565b600b60fa1b81526001019392505050565b7f7b226e616d65223a2253636f7265626f617264222c226465736372697074696f8152751b888e88931a5d99481b195859195c989bd85c99088b60521b60208201525f614be060368301856149ac565b6d2261747472696275746573223a5b60901b8152614c01600e8201856149ac565b615d7d60f01b815260020195945050505050565b6b436172706f6f6c657273202360a01b81525f612948600c8301846149ac565b5f614c4082866149ac565b600b60fa1b8152614c5460018201866149ac565b9050600b60fa1b8152614c6a60018201856149ac565b9695505050505050565b7f3c21444f43545950452068746d6c3e3c68746d6c3e3c686561643e3c6d6574618152701031b430b939b2ba1e913aba33169c111f60791b60208201527f3c6d657461206e616d653d2276696577706f72742220636f6e74656e743d227760318201527f696474683d6465766963652d77696474682c696e697469616c2d7363616c653d60518201526218911f60e91b60718201527f3c7374796c653e2a7b6d617267696e3a303b70616464696e673a307d68746d6c60748201527f2c626f64797b6f766572666c6f773a68696464656e3b706f736974696f6e3a6660948201527f697865643b6865696768743a313030253b77696474683a313030253b6261636b60b48201526b67726f756e643a233030307d60a01b60d48201527f234c7b706f736974696f6e3a66697865643b746f703a3530253b6c6566743a3560e08201527f30253b7472616e73666f726d3a7472616e736c617465282d3530252c2d3530256101008201527f293b636f6c6f723a233066303b666f6e743a31347078206d6f6e6f7370616365610120820152683e9e17b9ba3cb6329f60b91b6101408201527f3c2f686561643e3c626f64793e3c6469762069643d224c223e4c4f4144494e47610149820152681717171e17b234bb1f60b91b6101698201525f614e6161017283015b846149ac565b6d1e17b137b23c9f1e17b43a36b61f60911b8152600e019392505050565b7519185d184e9d195e1d0bda1d1b5b0ed8985cd94d8d0b60521b81525f61294860168301846149ac565b601160f91b81525f614ebe60018301856149ac565b62111d1160e91b8152614ed460038201856149ac565b601160f91b815260010195945050505050565b605b60f81b81525f614efc60018301846149ac565b605d60f81b81526001019392505050565b601160f91b81525f614f2260018301856149ac565b61111d60f11b8152614f3760028201856149ac565b95945050505050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c00000081525f612948601d8301846149ac565b7f646174613a696d6167652f7376672b786d6c3b6261736536342c00000000000081525f612948601a8301846149ac565b7f7b2274726169745f74797065223a22486967682053636f7265222c2276616c7581526232911d60e91b60208201525f614fdf60238301846149ac565b607d60f81b81526001019392505050565b86815285602082015284604082015260c060608201525f61501460c0830186614318565b82810360808401526150268186614318565b905082810360a084015261503a8185614318565b9998505050505050505050565b652dbd9131911d60d11b81525f61506160068301896149ac565b65161132111d1160d11b815261507a60068201896149ac565b67113e963d9131911d60c11b8152905061509760088201886149ac565b65161132111d1160d11b815290506150b260068201876149ac565b67113e963d9131911d60c11b815290506150cf60088201866149ac565b65161132111d1160d11b815290506150ea60068201856149ac565b62227d5d60e81b81526003019998505050505050505050565b671e39b1b934b83a1f60c11b81525f61511f60088301876149ac565b6e3b30b91029a1a7a922afa0a8249e9160891b815285545f90615141816146e8565b6001821680156151585760018114615173576151a6565b60ff198316600f860152600f821515830286010193506151a6565b895f5260205f205f5b8381101561519b578154878201600f015260019091019060200161517c565b5050600f8286010193505b505061223b60f01b8252506151be60028201876149ac565b9150506151d3816576617220533d60d01b9052565b6151e060068201856149ac565b603b60f81b81527f66756e6374696f6e20422873297b76617220623d61746f622873292c613d6e6560018201527f772055696e7438417272617928622e6c656e677468293b666f7228766172206960218201527f3d303b693c622e6c656e6774683b692b2b29615b695d3d622e63686172436f6460418201526f6541742869293b72657475726e20617d60801b60618201527f66756e6374696f6e20472864297b76617220663d747970656f662066666c617460718201527f65213d22756e646566696e656422262666666c6174657c7c747970656f66207060918201527f616b6f213d22756e646566696e656422262670616b6f3b69662821662974687260b18201527f6f77206e6577204572726f7228226465636f6d70726573736f72206e6f74206660d18201527f6f756e6422293b72657475726e20662e67756e7a697053796e633f662e67756e60f18201527f7a697053796e632864293a662e756e677a69703f662e756e677a69702864293a6101118201526c662e696e666c6174652864297d60981b6101318201527f6173796e632066756e6374696f6e204c28297b76617220653d6576616c3b666f61013e8201527f72287661722073206f662053297b76617220643d4228732e64293b766172207461015e8201527f3d732e633f472864293a643b65286e657720546578744465636f64657228292e61017e8201526b6465636f6465287429297d7d60a01b61019e8201527f4c28292e7468656e2866756e6374696f6e28297b646f63756d656e742e6765746101aa8201527f456c656d656e744279496428224c22292e72656d6f766528297d292e636174636101ca8201527f682866756e6374696f6e2865297b646f63756d656e742e676574456c656d656e6101ea8201527f744279496428224c22292e696e6e6572546578743d224572726f723a20222b6561020a820152627d293b60e81b61022a820152681e17b9b1b934b83a1f60b91b61022d82015261023601979650505050505050565b605b60f81b81525f6154d960018301886149ac565b600b60fa1b81526154ed60018201886149ac565b9050600b60fa1b815261550360018201876149ac565b9050600b60fa1b815261551960018201866149ac565b9050600b60fa1b815261552f60018201856149ac565b605d60f81b815260010198975050505050505050565b7f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323081527f30302f737667222076696577426f783d223020302034303020343030223e000060208201527f3c646566733e3c6c696e6561724772616469656e742069643d22736b79222078603e8201527f313d2230222079313d2230222078323d2230222079323d2231223e3c73746f70605e8201527f206f66667365743d223025222073746f702d636f6c6f723d2200000000000000607e8201525f61560e60978301866149ac565b7f222f3e3c73746f70206f66667365743d2231303025222073746f702d636f6c6f815262391e9160e91b602082015261564a60238201866149ac565b7f222f3e3c2f6c696e6561724772616469656e743e3c2f646566733e000000000081527f3c726563742077696474683d2234303022206865696768743d22343030222066601b8201527034b6361e913ab9361411b9b5bc9491179f60791b603b82015290506156bc604c8201856149ac565b651e17b9bb339f60d11b81526006019695505050505050565b5f611ee6614e5b83866149ac565b7477696e646f772e544f4b454e5f434f4e4649473d7b60581b8152673a37b5b2b724b21d60c11b60158201525f61571d601d8301866149ac565b600b60fa1b8152693434b3b429b1b7b9329d60b11b6001820152615744600b8201866149ac565b9050600b60fa1b81526c39b1b7b932a2b730b13632b21d60991b6001820152615770600e8201856149ac565b617d3b60f01b81526002019695505050505050565b6e3d913a3930b4ba2fba3cb832911d1160891b81525f6157a8600f8301856149ac565b6a1116113b30b63ab2911d1160a91b81526157c6600b8201856149ac565b61227d60f01b815260020195945050505050565b5f6157e582896149ac565b600b60fa1b81526157f960018201896149ac565b9050600b60fa1b815261580f60018201886149ac565b9050600b60fa1b815261582560018201876149ac565b9050600b60fa1b815261503a61583e60018301876149ac565b856149ac565b5f61584f82876149ac565b600b60fa1b815261586360018201876149ac565b9050600b60fa1b815261587c61583e60018301876149ac565b979650505050505050565b7f3c7265637420783d223132302220793d22323030222077696474683d2231363081527f22206865696768743d22323030222066696c6c3d2223353835343530222f3e0060208201527f3c7265637420783d223138322220793d22323830222077696474683d22333622603f8201527f206865696768743d223234222066696c6c3d2223646432303230222072783d22605f820152631911179f60e11b607f8201527f3c7265637420783d223138322220793d22333034222077696474683d2233362260838201527f206865696768743d223330222066696c6c3d2223373035303330222f3e00000060a38201525f61598c61598660c08401896149ac565b876149ac565b7f3c7465787420783d223230302220793d2233302220746578742d616e63686f7281527f3d226d6964646c65222066696c6c3d22233066302220666f6e742d66616d696c60208201527f793d226d6f6e6f73706163652220666f6e742d73697a653d2231382220666f6e60408201527f742d7765696768743d22626f6c64223e434152504f4f4c4552532023000000006060820152607c8101615a2f81886149ac565b915050615a4581661e17ba32bc3a1f60c91b9052565b7f3c7465787420783d223230302220793d223337302220746578742d616e63686f60078201527f723d226d6964646c65222066696c6c3d22233066302220666f6e742d66616d6960278201527f6c793d226d6f6e6f73706163652220666f6e742d73697a653d223132223e00006047820152615ac460658201866149ac565b661e17ba32bc3a1f60c91b815290507f3c7465787420783d223230302220793d223338382220746578742d616e63686f60078201527f723d226d6964646c65222066696c6c3d22233066302220666f6e742d66616d6960278201527f6c793d226d6f6e6f73706163652220666f6e742d73697a653d223132223e4849604782015269023a41029a1a7a9229d160b51b6067820152615b646071820161583e565b661e17ba32bc3a1f60c91b815260070198975050505050505050565b7477696e646f772e544f4b454e5f434f4e4649473d7b60581b8152673a37b5b2b724b21d60c11b60158201525f615bba601d83018a6149ac565b600b60fa1b81526531b4ba3c9d1160d11b6001820152615bdd600782018a6149ac565b61088b60f21b81529050663134b7b6b29d1160c91b6002820152615c0460098201896149ac565b61088b60f21b8152905068383937b334b6329d1160b91b6002820152615c2d600b8201886149ac565b61088b60f21b81529050615c4460028201876149ac565b693434b3b429b1b7b9329d60b11b81529050615c63600a8201866149ac565b600b60fa1b815290506c39b1b7b932a2b730b13632b21d60991b6001820152615c8f600e8201856149ac565b617d3b60f01b81526002019a9950505050505050505050565b60ff8281168282160390811115611e1c57611e1c614720565b634e487b7160e01b5f52601260045260245ffd5b5f82615ce357615ce3615cc1565b500490565b5f82615cf657615cf6615cc1565b500690565b6839b2b0b9b4b2329d1160b91b81525f615d1860098301846149ac565b61088b60f21b81526002019392505050565b663a393ab1b59d1160c91b81525f615d1860078301846149ac565b693630b73236b0b9359d1160b11b81525f615d18600a8301846149ac565b683bb2b0ba3432b91d1160b91b81525f615d80600983018d6149ac565b61088b60f21b81526a3a34b6b2a7b32230bc9d1160a91b6002820152615da9600d82018d6149ac565b61088b60f21b81529050683932bb32b939b2b21d60b91b6002820152615dd2600b82018c6149ac565b600b60fa1b815290506831b7bab73a393c9d1160b91b6001820152615dfa600a82018b6149ac565b61088b60f21b81529050615e11600282018a6149ac565b693937b0b22332b2b61d1160b11b81529050615e30600a8201896149ac565b61088b60f21b815290506c3b32b434b1b632aa3cb8329d1160991b6002820152615e5d600f8201886149ac565b61088b60f21b81529050693232b1b7b929b2b2b21d60b11b6002820152615e87600c8201876149ac565b600b60fa1b81529050615ea061583e60018301876149ac565b9d9c5050505050505050505050505056fe3c7265637420783d223138362220793d22323732222077696474683d22323822206865696768743d2236222066696c6c3d222366663022206f7061636974793d22302e36222072783d2231222f3e3c706f6c79676f6e20706f696e74733d223230302c323638203139302c323830203231302c323830222066696c6c3d222330663022206f7061636974793d22302e37222f3e4f6e2d636861696e2064726976696e672067616d65207769746820756e6971756520636974792c207765617468657220262074696d652e3c706f6c79676f6e20706f696e74733d223230302c323630203139302c323438203231302c323438222066696c6c3d222330663022206f7061636974793d22302e37222f3ea26469706673582212200fea0f6ded081f986d6a0c19e7da8e53d7a13ba66652dd243698e944bfbd476264736f6c634300081e0033
Verified Source Code Full Match
Compiler: v0.8.30+commit.73712a01
EVM: prague
Optimization: Yes (200 runs)
CarpoolersMetadata.sol 817 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "solady/auth/Ownable.sol";
import "solady/utils/SSTORE2.sol";
import "solady/utils/Base64.sol";
import "solady/utils/LibString.sol";
import "solady/utils/EIP712.sol";
import "solady/utils/ECDSA.sol";
import "./libraries/Metadata.sol";
import "./CarpoolersImage.sol";
interface ICarpoolersSeaDrop {
function exists(uint256 tokenId) external view returns (bool);
function emitMetadataUpdate(uint256 tokenId) external;
}
/// @title CarpoolersMetadata
/// @notice On-chain metadata, renderer, and score system for Carpoolers NFT.
/// Consolidates CarpoolersRendererV2 + score system from CarpoolersNFT.
/// @dev Three-chunk SSTORE2 system: data (traits/profiles/assign) + core + skin.
/// Expanded tokenConfigs (bytes32) per token. No legacy uint32 trait path.
/// EIP-712 verified scores. Delegates rich SVG to CarpoolersImage.
contract CarpoolersMetadata is Ownable, EIP712 {
using LibString for uint256;
// ============ Structs ============
struct CityInfo {
string name;
uint8 biomeId;
uint8 stateId;
uint8 profileId;
uint8 seasideId; // 0=none, 1=caribbean, 2=pacific, 3=gulf, 4=atlantic
uint8 countryId; // 0=MX, 1=US
}
struct LeaderEntry {
uint16 tokenId;
uint48 score;
address player;
}
// ============ Storage: Renderer ============
// Three script chunk arrays (loaded in order: data → core → skin)
address[] internal _dataChunks; // traits.js + city-profiles.js + assign.js
address[] internal _coreChunks; // carpoolers-core.js
address[] internal _skinChunks; // carpoolers-skin.js
address public gunzipPointer;
bool public dataCompressed;
bool public coreCompressed;
bool public skinCompressed;
// City registry (0-based IDs)
mapping(uint8 => CityInfo) public cities;
uint8 public cityCount;
// State name registry
mapping(uint8 => string) public states;
uint8 public stateCount;
// Truck name registry
mapping(uint8 => string) public trucks;
uint8 public truckCount;
// Landmark name registry
mapping(uint8 => string) public landmarks;
uint8 public landmarkCount;
/// @notice Per-token expanded config
/// @dev bytes32 layout:
/// byte 0: cityId (0-255)
/// byte 1: weatherId (0-4: sunny/cloudy/rain/sunset/snow)
/// byte 2: timeId (0-2: morning/evening/night)
/// byte 3: flags (bit0=reversed, bit1=isBus)
/// byte 4: biomeId (0-5: desert/tropical/coastal/highland/urban/mesa)
/// byte 5: profileId (0-5: towers/concrete/colonial/resort/pueblo/industrial)
/// byte 6: seasideId (0=none, 1=caribbean, 2=pacific, 3=gulf, 4=atlantic)
/// byte 7: roadFeelId (0=highway, 1=boulevard, 2=rural, 3=coastal_road)
/// byte 8: stateId (0-41)
/// byte 9: truckId
/// byte 10: decorSeed high byte
/// byte 11: decorSeed low byte
/// byte 12: countryId (0=MX, 1=US)
/// byte 13: landmarkId (0=none, 1+=landmark keys)
/// bytes 14-31: reserved (14-16=cab RGB, 17-19=bed RGB)
mapping(uint256 => bytes32) public tokenConfigs;
/// @notice External rich SVG builder contract (CarpoolersImage)
CarpoolersImage public imageRenderer;
// ============ Storage: Score System ============
mapping(uint256 => uint256) public highScores;
mapping(uint256 => address) public scoreHolders;
address public signer;
mapping(bytes32 => bool) public usedNonces;
bool public scoreEnabled;
string public scoreAPI;
// ============ Storage: Leaderboard ============
uint256 public constant SCOREBOARD_TOKEN = 1001;
LeaderEntry[5] public topScores;
// ============ Storage: NFT Reference ============
address public nftContract;
// ============ Constants ============
bytes32 public constant SCORE_TYPEHASH = keccak256(
"ScoreSubmission(uint256 tokenId,uint256 score,string weather,bytes32 nonce,uint256 deadline)"
);
// ============ Events: Renderer ============
event DataChunkStored(uint256 index);
event CoreChunkStored(uint256 index);
event SkinChunkStored(uint256 index);
event DataChunksReset();
event CoreChunksReset();
event SkinChunksReset();
event GunzipUpdated();
event CitiesUpdated(uint8 count);
event StatesUpdated(uint8 count);
event TrucksUpdated(uint8 count);
event LandmarksUpdated(uint8 count);
event TokenConfigsSet(uint256 count);
event ImageRendererSet(address indexed renderer);
// ============ Events: Score ============
event ScoreSubmitted(uint256 indexed tokenId, address indexed player, uint256 score);
event ScoreEnabledUpdated(bool enabled);
event SignerUpdated(address indexed newSigner);
event NftContractUpdated(address indexed nftContract);
// ============ Errors ============
error EmptyData();
error NoGunzip();
error LengthMismatch();
error InvalidSignature();
error ExpiredDeadline();
error NonceAlreadyUsed();
error ScoreNotHigher();
error ScoreDisabled();
error ZeroAddress();
error InvalidToken();
// ============ Constructor ============
constructor(address owner_) {
_initializeOwner(owner_);
}
// ============ EIP-712 ============
function _domainNameAndVersion() internal pure override returns (string memory domainName, string memory version) {
domainName = "Carpoolers";
version = "1";
}
// ============ Token URI (called by NFT contract) ============
/// @notice Build the full on-chain metadata JSON for a token
/// @param tokenId The token to query
/// @return Base64-encoded data URI with JSON metadata
function tokenURI(uint256 tokenId) external view returns (string memory) {
if (tokenId == SCOREBOARD_TOKEN) return _scoreboardURI();
bytes32 c = tokenConfigs[tokenId];
uint256 score = highScores[tokenId];
return Metadata.encodeJSON(
string.concat(
'{',
_tokenURITop(tokenId, c, score), ',',
Metadata.kv("animation_url", Metadata.encodeHTML(_buildHTML(tokenId, c, score))), ',',
Metadata.kvRaw("attributes", _buildAttributes(c, score)),
'}'
)
);
}
function _tokenURITop(uint256 tokenId, bytes32 c, uint256 score) internal view returns (string memory) {
return string.concat(
Metadata.kv("name", string.concat("Carpoolers #", tokenId.toString())), ',',
Metadata.kv("description", "On-chain driving game with unique city, weather & time."), ',',
Metadata.kv("image", Metadata.encodeSVG(_buildSVG(tokenId, c, score)))
);
}
// ============ Score Submission ============
/// @notice Submit a verified high score via EIP-712 signature
function submitScore(
uint256 tokenId,
uint256 score,
string calldata weather,
bytes32 nonce,
uint256 deadline,
bytes calldata signature
) external {
if (!scoreEnabled) revert ScoreDisabled();
if (block.timestamp > deadline) revert ExpiredDeadline();
if (usedNonces[nonce]) revert NonceAlreadyUsed();
// Validate token exists via NFT contract
if (nftContract != address(0)) {
if (!ICarpoolersSeaDrop(nftContract).exists(tokenId)) revert InvalidToken();
}
bytes32 structHash = keccak256(
abi.encode(SCORE_TYPEHASH, tokenId, score, keccak256(bytes(weather)), nonce, deadline)
);
bytes32 digest = _hashTypedData(structHash);
address recovered = ECDSA.recover(digest, signature);
if (recovered != signer) revert InvalidSignature();
usedNonces[nonce] = true;
if (score <= highScores[tokenId]) revert ScoreNotHigher();
highScores[tokenId] = score;
scoreHolders[tokenId] = msg.sender;
_updateLeaderboard(uint16(tokenId), uint48(score), msg.sender);
emit ScoreSubmitted(tokenId, msg.sender, score);
// Trigger ERC-4906 metadata refresh on the NFT contract
if (nftContract != address(0)) {
ICarpoolersSeaDrop(nftContract).emitMetadataUpdate(tokenId);
ICarpoolersSeaDrop(nftContract).emitMetadataUpdate(SCOREBOARD_TOKEN);
}
}
// ============ Admin: Score ============
function setScoreEnabled(bool enabled) external onlyOwner {
scoreEnabled = enabled;
emit ScoreEnabledUpdated(enabled);
}
function setSigner(address newSigner) external onlyOwner {
if (newSigner == address(0)) revert ZeroAddress();
signer = newSigner;
emit SignerUpdated(newSigner);
}
function setScoreAPI(string calldata url) external onlyOwner {
scoreAPI = url;
}
function setNftContract(address nft_) external onlyOwner {
nftContract = nft_;
emit NftContractUpdated(nft_);
}
// ============ Data Chunk Storage (traits.js + city-profiles.js + assign.js) ============
function storeDataChunk(bytes calldata data) external onlyOwner {
if (data.length == 0) revert EmptyData();
_dataChunks.push(SSTORE2.write(data));
emit DataChunkStored(_dataChunks.length - 1);
}
function storeDataChunks(bytes[] calldata chunks) external onlyOwner {
uint256 startIdx = _dataChunks.length;
for (uint256 i; i < chunks.length; ++i) {
if (chunks[i].length == 0) revert EmptyData();
_dataChunks.push(SSTORE2.write(chunks[i]));
emit DataChunkStored(startIdx + i);
}
}
function resetDataChunks() external onlyOwner {
delete _dataChunks;
emit DataChunksReset();
}
function setDataCompressed(bool compressed) external onlyOwner {
dataCompressed = compressed;
}
// ============ Core Chunk Storage ============
function storeCoreChunk(bytes calldata data) external onlyOwner {
if (data.length == 0) revert EmptyData();
_coreChunks.push(SSTORE2.write(data));
emit CoreChunkStored(_coreChunks.length - 1);
}
function storeCoreChunks(bytes[] calldata chunks) external onlyOwner {
uint256 startIdx = _coreChunks.length;
for (uint256 i; i < chunks.length; ++i) {
if (chunks[i].length == 0) revert EmptyData();
_coreChunks.push(SSTORE2.write(chunks[i]));
emit CoreChunkStored(startIdx + i);
}
}
function resetCoreChunks() external onlyOwner {
delete _coreChunks;
emit CoreChunksReset();
}
function setCoreCompressed(bool compressed) external onlyOwner {
coreCompressed = compressed;
}
// ============ Skin Chunk Storage ============
function storeSkinChunk(bytes calldata data) external onlyOwner {
if (data.length == 0) revert EmptyData();
_skinChunks.push(SSTORE2.write(data));
emit SkinChunkStored(_skinChunks.length - 1);
}
function storeSkinChunks(bytes[] calldata chunks) external onlyOwner {
uint256 startIdx = _skinChunks.length;
for (uint256 i; i < chunks.length; ++i) {
if (chunks[i].length == 0) revert EmptyData();
_skinChunks.push(SSTORE2.write(chunks[i]));
emit SkinChunkStored(startIdx + i);
}
}
function resetSkinChunks() external onlyOwner {
delete _skinChunks;
emit SkinChunksReset();
}
function setSkinCompressed(bool compressed) external onlyOwner {
skinCompressed = compressed;
}
// ============ Gunzip ============
function setGunzip(bytes calldata data) external onlyOwner {
if (data.length == 0) revert EmptyData();
gunzipPointer = SSTORE2.write(data);
emit GunzipUpdated();
}
// ============ Registries ============
/// @notice Register cities. `packed[i]` = abi.encodePacked(biomeId, stateId, profileId, seasideId, countryId) = 5 bytes
function setCities(string[] calldata names, bytes[] calldata packed) external onlyOwner {
if (names.length != packed.length) revert LengthMismatch();
uint8 count = uint8(names.length);
for (uint8 i; i < count; ++i) {
bytes memory p = packed[i];
cities[i] = CityInfo(
names[i],
uint8(p[0]), // biomeId
uint8(p[1]), // stateId
uint8(p[2]), // profileId
uint8(p[3]), // seasideId
uint8(p[4]) // countryId
);
}
cityCount = count;
emit CitiesUpdated(count);
}
function setStates(string[] calldata names) external onlyOwner {
uint8 count = uint8(names.length);
for (uint8 i; i < count; ++i) {
states[i] = names[i];
}
stateCount = count;
emit StatesUpdated(count);
}
function setTrucks(string[] calldata names) external onlyOwner {
uint8 count = uint8(names.length);
for (uint8 i; i < count; ++i) {
trucks[i] = names[i];
}
truckCount = count;
emit TrucksUpdated(count);
}
function setLandmarks(string[] calldata names) external onlyOwner {
uint8 count = uint8(names.length);
for (uint8 i; i < count; ++i) {
landmarks[i] = names[i];
}
landmarkCount = count;
emit LandmarksUpdated(count);
}
// ============ Token Config (Expanded Traits) ============
function setTokenConfigs(uint256[] calldata tokenIds, bytes32[] calldata configs) external onlyOwner {
if (tokenIds.length != configs.length) revert LengthMismatch();
for (uint256 i; i < tokenIds.length; ++i) {
tokenConfigs[tokenIds[i]] = configs[i];
}
emit TokenConfigsSet(tokenIds.length);
}
function setImageRenderer(address renderer) external onlyOwner {
imageRenderer = CarpoolersImage(renderer);
emit ImageRendererSet(renderer);
}
// ============ Config Decoding ============
function _cfgCityId(bytes32 c) internal pure returns (uint8) { return uint8(c[0]); }
function _cfgWeatherId(bytes32 c) internal pure returns (uint8) { return uint8(c[1]); }
function _cfgTimeId(bytes32 c) internal pure returns (uint8) { return uint8(c[2]); }
function _cfgReversed(bytes32 c) internal pure returns (bool) { return uint8(c[3]) & 1 == 1; }
function _cfgIsBus(bytes32 c) internal pure returns (bool) { return uint8(c[3]) & 2 == 2; }
function _cfgBiomeId(bytes32 c) internal pure returns (uint8) { return uint8(c[4]); }
function _cfgProfileId(bytes32 c) internal pure returns (uint8) { return uint8(c[5]); }
function _cfgSeasideId(bytes32 c) internal pure returns (uint8) { return uint8(c[6]); }
function _cfgRoadFeelId(bytes32 c) internal pure returns (uint8) { return uint8(c[7]); }
function _cfgStateId(bytes32 c) internal pure returns (uint8) { return uint8(c[8]); }
function _cfgTruckId(bytes32 c) internal pure returns (uint8) { return uint8(c[9]); }
function _cfgDecorSeed(bytes32 c) internal pure returns (uint16) { return uint16(uint8(c[10])) << 8 | uint16(uint8(c[11])); }
function _cfgCountryId(bytes32 c) internal pure returns (uint8) { return uint8(c[12]); }
function _cfgLandmarkId(bytes32 c) internal pure returns (uint8) { return uint8(c[13]); }
// ============ Name Lookups ============
function _weatherName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "sunny";
if (id == 1) return "cloudy";
if (id == 2) return "rain";
if (id == 3) return "sunset";
return "snow";
}
function _timeName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "morning";
if (id == 1) return "evening";
return "night";
}
function _biomeName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "desert";
if (id == 1) return "tropical";
if (id == 2) return "coastal";
if (id == 3) return "highland";
if (id == 4) return "urban";
return "mesa";
}
function _profileName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "towers";
if (id == 1) return "concrete";
if (id == 2) return "colonial";
if (id == 3) return "resort";
if (id == 4) return "pueblo";
return "industrial";
}
function _seasideName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "";
if (id == 1) return "caribbean";
if (id == 2) return "pacific";
if (id == 3) return "gulf";
return "atlantic";
}
function _roadFeelName(uint8 id) internal pure returns (string memory) {
if (id == 0) return "highway";
if (id == 1) return "boulevard";
if (id == 2) return "rural";
return "coastal_road";
}
function _countryName(uint8 id) internal pure returns (string memory) {
return id == 0 ? "MX" : "US";
}
function _cityName(uint8 id) internal view returns (string memory) {
if (id < cityCount) return cities[id].name;
return "unknown";
}
function _stateName(uint8 id) internal view returns (string memory) {
if (id < stateCount) return states[id];
return "unknown";
}
function _truckName(uint8 id) internal view returns (string memory) {
if (id < truckCount) return trucks[id];
return "";
}
function _landmarkName(uint8 id) internal view returns (string memory) {
if (id == 0) return "";
if (id <= landmarkCount) return landmarks[id - 1];
return "";
}
// ============ Attributes ============
function _buildAttributes(bytes32 c, uint256 score) internal view returns (string memory) {
if (c == bytes32(0)) {
// No config set — minimal attributes
return string.concat('[', _highScoreAttr(score), ']');
}
return _expandedAttributes(c, score);
}
function _expandedAttributes(bytes32 c, uint256 score) internal view returns (string memory) {
string memory seaside = _seasideName(_cfgSeasideId(c));
string memory truck = _truckName(_cfgTruckId(c));
return string.concat(
'[',
Metadata.attr("City", _cityName(_cfgCityId(c))), ',',
Metadata.attr("State", _stateName(_cfgStateId(c))), ',',
Metadata.attr("Country", _countryName(_cfgCountryId(c))), ',',
_expandedAttributesMid(c, seaside), ',',
_expandedAttributesEnd(c, truck, score),
']'
);
}
function _expandedAttributesMid(bytes32 c, string memory seaside) internal pure returns (string memory) {
return string.concat(
Metadata.attr("Biome", _biomeName(_cfgBiomeId(c))), ',',
Metadata.attr("Profile", _profileName(_cfgProfileId(c))), ',',
Metadata.attr("Weather", _weatherName(_cfgWeatherId(c))), ',',
Metadata.attr("Time of Day", _timeName(_cfgTimeId(c))), ',',
bytes(seaside).length > 0 ? string.concat(Metadata.attr("Seaside", seaside), ',') : "",
Metadata.attr("Road", _roadFeelName(_cfgRoadFeelId(c)))
);
}
function _expandedAttributesEnd(bytes32 c, string memory truck, uint256 score) internal pure returns (string memory) {
return string.concat(
Metadata.attr("Direction", _cfgReversed(c) ? "Reversed" : "Normal"), ',',
Metadata.attr("Vehicle", _cfgIsBus(c) ? "Bus" : "Truck"), ',',
bytes(truck).length > 0 ? string.concat(Metadata.attr("Truck", truck), ',') : "",
_highScoreAttr(score)
);
}
function _highScoreAttr(uint256 score) internal pure returns (string memory) {
return string.concat('{"trait_type":"High Score","value":', score.toString(), '}');
}
// ============ Build HTML (internal) ============
function _buildHTML(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
if (gunzipPointer == address(0)) revert NoGunzip();
return string.concat(
'<!DOCTYPE html><html><head><meta charset="utf-8">',
'<meta name="viewport" content="width=device-width,initial-scale=1">',
'<style>*{margin:0;padding:0}html,body{overflow:hidden;position:fixed;height:100%;width:100%;background:#000}',
'#L{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);color:#0f0;font:14px monospace}</style>',
'</head><body><div id="L">LOADING...</div>',
_embedScripts(tokenId, c, score),
'</body></html>'
);
}
function _embedScripts(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
string memory gunzipCode = string(SSTORE2.read(gunzipPointer));
// Read all three chunk sets
bytes memory dataData = _readChunks(_dataChunks);
bytes memory coreData = _readChunks(_coreChunks);
bytes memory skinData = _readChunks(_skinChunks);
string memory b64Data = Base64.encode(dataData);
string memory b64Core = Base64.encode(coreData);
string memory b64Skin = Base64.encode(skinData);
// Three script entries: data → core → skin (order matters)
string memory scriptsArr = string.concat(
'[{"c":', dataCompressed ? '1' : '0', ',"d":"', b64Data,
'"},{"c":', coreCompressed ? '1' : '0', ',"d":"', b64Core,
'"},{"c":', skinCompressed ? '1' : '0', ',"d":"', b64Skin, '"}]'
);
return string.concat(
'<script>',
_buildTokenConfig(tokenId, c, score),
'var SCORE_API="', scoreAPI, '";',
gunzipCode,
'var S=', scriptsArr, ';',
'function B(s){var b=atob(s),a=new Uint8Array(b.length);for(var i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a}',
'function G(d){var f=typeof fflate!="undefined"&&fflate||typeof pako!="undefined"&&pako;if(!f)throw new Error("decompressor not found");return f.gunzipSync?f.gunzipSync(d):f.ungzip?f.ungzip(d):f.inflate(d)}',
'async function L(){var e=eval;for(var s of S){var d=B(s.d);var t=s.c?G(d):d;e(new TextDecoder().decode(t))}}',
'L().then(function(){document.getElementById("L").remove()}).catch(function(e){document.getElementById("L").innerText="Error: "+e});',
'</script>'
);
}
function _buildTokenConfig(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
if (c == bytes32(0)) {
// Minimal config for tokens without expanded config
return string.concat(
'window.TOKEN_CONFIG={',
'tokenId:', tokenId.toString(), ',',
'highScore:', score.toString(), ',',
'scoreEnabled:', scoreEnabled ? 'true' : 'false',
'};'
);
}
return _expandedTokenConfig(tokenId, c, score);
}
function _expandedTokenConfig(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
string memory seaside = _seasideName(_cfgSeasideId(c));
string memory landmark = _landmarkName(_cfgLandmarkId(c));
string memory truck = _truckName(_cfgTruckId(c));
return string.concat(
'window.TOKEN_CONFIG={',
'tokenId:', tokenId.toString(), ',',
'city:"', _cityName(_cfgCityId(c)), '",',
'biome:"', _biomeName(_cfgBiomeId(c)), '",',
'profile:"', _profileName(_cfgProfileId(c)), '",',
_expandedTokenConfigMid(c, seaside, landmark, truck),
'highScore:', score.toString(), ',',
'scoreEnabled:', scoreEnabled ? 'true' : 'false',
'};'
);
}
function _expandedTokenConfigMid(
bytes32 c,
string memory seaside,
string memory landmark,
string memory truck
) internal pure returns (string memory) {
return string.concat(
'weather:"', _weatherName(_cfgWeatherId(c)), '",',
'timeOfDay:"', _timeName(_cfgTimeId(c)), '",',
'reversed:', _cfgReversed(c) ? 'true' : 'false', ',',
'country:"', _countryName(_cfgCountryId(c)), '",',
bytes(seaside).length > 0 ? string.concat('seaside:"', seaside, '",') : "",
'roadFeel:"', _roadFeelName(_cfgRoadFeelId(c)), '",',
'vehicleType:"', _cfgIsBus(c) ? 'bus' : 'truck', '",',
'decorSeed:', uint256(_cfgDecorSeed(c)).toString(), ',',
bytes(truck).length > 0 ? string.concat('truck:"', truck, '",') : "",
bytes(landmark).length > 0 ? string.concat('landmark:"', landmark, '",') : ""
);
}
// ============ Build SVG (internal) ============
function _buildSVG(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
// If imageRenderer is set and we have an expanded config, delegate to it
if (address(imageRenderer) != address(0) && c != bytes32(0)) {
return imageRenderer.buildRichSVG(
tokenId,
c,
score,
_cityName(_cfgCityId(c)),
_weatherName(_cfgWeatherId(c)),
_timeName(_cfgTimeId(c))
);
}
// Fallback: minimal SVG
return _fallbackSVG(tokenId, c, score);
}
function _fallbackSVG(
uint256 tokenId,
bytes32 c,
uint256 score
) internal view returns (string memory) {
uint8 tid = c != bytes32(0) ? _cfgTimeId(c) : 0;
bool reversed = c != bytes32(0) ? _cfgReversed(c) : false;
string memory cityLabel = c != bytes32(0) ? _cityName(_cfgCityId(c)) : "unknown";
string memory c1;
string memory c2;
if (tid == 0) { c1 = "#ff9040"; c2 = "#4080c0"; }
else if (tid == 1) { c1 = "#8040a0"; c2 = "#d06020"; }
else { c1 = "#0a0a2a"; c2 = "#101030"; }
return string.concat(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">',
'<defs><linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="', c1,
'"/><stop offset="100%" stop-color="', c2, '"/></linearGradient></defs>',
'<rect width="400" height="400" fill="url(#sky)"/>',
_fallbackSVGBody(tokenId, tid, reversed, cityLabel, score),
'</svg>'
);
}
function _fallbackSVGBody(
uint256 tokenId,
uint8 tid,
bool reversed,
string memory cityLabel,
uint256 score
) internal pure returns (string memory) {
string memory headlights = tid == 2
? '<rect x="186" y="272" width="28" height="6" fill="#ff0" opacity="0.6" rx="1"/>'
: "";
string memory arrow = reversed
? '<polygon points="200,260 190,248 210,248" fill="#0f0" opacity="0.7"/>'
: '<polygon points="200,268 190,280 210,280" fill="#0f0" opacity="0.7"/>';
return string.concat(
'<rect x="120" y="200" width="160" height="200" fill="#585450"/>',
'<rect x="182" y="280" width="36" height="24" fill="#dd2020" rx="2"/>',
'<rect x="182" y="304" width="36" height="30" fill="#705030"/>',
headlights, arrow,
'<text x="200" y="30" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="18" font-weight="bold">CARPOOLERS #', tokenId.toString(), '</text>',
'<text x="200" y="370" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="12">', _toUpper(cityLabel), '</text>',
'<text x="200" y="388" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="12">HIGH SCORE: ', _formatScore(score), '</text>'
);
}
// ============ Chunk Reader ============
function _readChunks(address[] storage chunks) internal view returns (bytes memory data) {
uint256 len = chunks.length;
for (uint256 i; i < len; ++i) {
data = bytes.concat(data, SSTORE2.read(chunks[i]));
}
}
// ============ String Helpers ============
function _toUpper(string memory s) internal pure returns (string memory) {
bytes memory b = bytes(s);
for (uint256 i; i < b.length; ++i) {
if (b[i] >= 0x61 && b[i] <= 0x7a) b[i] = bytes1(uint8(b[i]) - 32);
}
return string(b);
}
function _formatScore(uint256 score) internal pure returns (string memory) {
if (score == 0) return "0";
string memory raw = score.toString();
bytes memory b = bytes(raw);
uint256 len = b.length;
if (len <= 3) return raw;
uint256 commas = (len - 1) / 3;
bytes memory result = new bytes(len + commas);
uint256 j = result.length;
for (uint256 i = len; i > 0; --i) {
result[--j] = b[i - 1];
if ((len - i + 1) % 3 == 0 && i > 1) result[--j] = ",";
}
return string(result);
}
// ============ Leaderboard ============
function getTopScores() external view returns (LeaderEntry[5] memory e) {
for (uint256 i; i < 5; ++i) e[i] = topScores[i];
}
function _updateLeaderboard(uint16 tid, uint48 score, address player) internal {
for (uint256 i; i < 5; ++i) {
if (topScores[i].tokenId == tid && topScores[i].score > 0) {
for (uint256 j = i; j < 4; ++j) topScores[j] = topScores[j + 1];
delete topScores[4]; break;
}
}
uint256 p = 5;
for (uint256 i; i < 5; ++i) { if (score > topScores[i].score) { p = i; break; } }
if (p > 4) return;
for (uint256 i = 4; i > p; --i) topScores[i] = topScores[i - 1];
topScores[p] = LeaderEntry(tid, score, player);
}
// ============ Scoreboard Token URI ============
function _scoreboardURI() internal view returns (string memory) {
string memory img;
if (address(imageRenderer) != address(0)) {
uint16[5] memory ids;
uint48[5] memory sc;
address[5] memory pl;
for (uint256 i; i < 5; ++i) {
ids[i] = topScores[i].tokenId;
sc[i] = topScores[i].score;
pl[i] = topScores[i].player;
}
img = string.concat(Metadata.kv("image", Metadata.encodeSVG(imageRenderer.buildScoreboardSVG(ids, sc, pl))), ',');
}
return Metadata.encodeJSON(string.concat(
'{"name":"Scoreboard","description":"Live leaderboard",',
img,
'"attributes":[', _highScoreAttr(topScores[0].score), ']}'
));
}
}
CarpoolersImage.sol 578 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "solady/utils/LibString.sol";
/// @title CarpoolersImage
/// @notice Stateless on-chain SVG builder for Carpoolers NFT rich poster images.
/// @dev Renders a 400x400 SVG scene matching the game's TITLE screen visual feel.
/// All palette data is hardcoded as pure functions. No storage, no ownership.
/// Called by CarpoolersRendererV2 via external delegation.
contract CarpoolersImage {
using LibString for uint256;
// ============ Public Entry Point ============
/// @notice Build a rich on-chain SVG for a token.
/// @param tokenId Token number for label
/// @param config bytes32 expanded config (layout per RendererV2 spec)
/// @param score High score for label
/// @param cityLabel City name string
/// @param weatherLabel Weather name string
/// @param timeLabel Time of day name string
function buildRichSVG(
uint256 tokenId,
bytes32 config,
uint256 score,
string calldata cityLabel,
string calldata weatherLabel,
string calldata timeLabel
) external pure returns (string memory) {
return string.concat(
_sceneTop(config),
_sceneBottom(config),
_labelBlock(tokenId, score, cityLabel, weatherLabel, timeLabel),
"</svg>"
);
}
function _sceneTop(bytes32 config) internal pure returns (string memory) {
return string.concat(
_svgOpenAndDefs(uint8(config[2]), uint8(config[1])),
_backgroundLayers(config)
);
}
function _sceneBottom(bytes32 config) internal pure returns (string memory) {
return string.concat(
_roadAndVehicle(config),
_weatherOverlay(uint8(config[1]), uint8(config[2]))
);
}
function _labelBlock(
uint256 tokenId,
uint256 score,
string calldata cityLabel,
string calldata weatherLabel,
string calldata timeLabel
) internal pure returns (string memory) {
return string.concat(
_labelTitle(tokenId),
_labelInfo(cityLabel, weatherLabel, timeLabel),
_labelScore(score)
);
}
function _labelTitle(uint256 tokenId) internal pure returns (string memory) {
return string.concat(
'<text x="200" y="30" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="18" font-weight="bold">CARPOOLERS #',
tokenId.toString(),
'</text>'
);
}
function _labelInfo(
string calldata city,
string calldata weather,
string calldata time
) internal pure returns (string memory) {
return string.concat(
'<text x="200" y="370" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="12">',
_toUpper(city), unicode" \u00b7 ", _toUpper(weather), unicode" \u00b7 ", _toUpper(time),
'</text>'
);
}
function _labelScore(uint256 score) internal pure returns (string memory) {
return string.concat(
'<text x="200" y="388" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="12">HIGH SCORE: ',
_formatScore(score), '</text>'
);
}
// ============ SVG Open + Defs ============
function _svgOpenAndDefs(uint8 timeId, uint8 weatherId) internal pure returns (string memory) {
(string memory c1, string memory c2) = _skyGradient(timeId, weatherId);
return string.concat(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">',
'<defs><linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">',
'<stop offset="0%" stop-color="', c1, '"/>',
'<stop offset="100%" stop-color="', c2, '"/>',
'</linearGradient></defs>',
'<rect width="400" height="400" fill="url(#sky)"/>'
);
}
// ============ Background Layers ============
function _backgroundLayers(bytes32 config) internal pure returns (string memory) {
uint8 timeId = uint8(config[2]);
uint16 decorSeed = uint16(uint8(config[10])) << 8 | uint16(uint8(config[11]));
return string.concat(
_nightLayer(timeId, decorSeed),
_landFill(uint8(config[4]), timeId),
_seasideLayer(uint8(config[6]), timeId),
_buildingLayer(uint8(config[5]), timeId, decorSeed, uint8(config[6]))
);
}
// ============ Night: Stars + Moon ============
function _nightLayer(uint8 timeId, uint16 seed) internal pure returns (string memory) {
if (timeId != 2) return "";
// Deterministic star positions from seed
uint256 s = seed;
string memory stars = "";
for (uint256 i; i < 8; ++i) {
s = _lcg(s);
uint256 sx = s % 380 + 10;
s = _lcg(s);
uint256 sy = s % 140 + 10;
s = _lcg(s);
uint256 opacity = 40 + s % 40; // 0.40-0.79
stars = string.concat(
stars,
'<circle cx="', sx.toString(), '" cy="', sy.toString(),
'" r="1" fill="#fff" opacity="0.', opacity.toString(), '"/>'
);
}
// Moon
return string.concat(
stars,
'<circle cx="340" cy="40" r="12" fill="#f0e8c0" opacity="0.8"/>'
);
}
// ============ Land Fill ============
function _landFill(uint8 biomeId, uint8 timeId) internal pure returns (string memory) {
uint24 col = timeId == 2 ? _biomeLandNight(biomeId) : _biomeLand(biomeId);
return string.concat(
'<rect x="0" y="180" width="400" height="220" fill="', _hex6(col), '"/>'
);
}
// ============ Seaside Layer ============
function _seasideLayer(uint8 seasideId, uint8 timeId) internal pure returns (string memory) {
if (seasideId == 0) return "";
bool isNight = timeId == 2;
(uint24 water, uint24 sand, uint24 foam) = _seasidePalette(seasideId, isNight);
// Pacific on left side, others on right
bool leftSide = seasideId == 2;
string memory sx = leftSide ? "0" : "300";
string memory sandX = leftSide ? "0" : "285";
string memory foamX = leftSide ? "95" : "285";
return string.concat(
'<rect x="', sx, '" y="180" width="100" height="220" fill="', _hex6(water), '"/>',
'<rect x="', sandX, '" y="180" width="15" height="220" fill="', _hex6(sand), '"/>',
'<rect x="', foamX, '" y="180" width="3" height="220" fill="', _hex6(foam), '" opacity="0.6"/>'
);
}
// ============ Building Layer ============
function _buildingLayer(
uint8 profileId,
uint8 timeId,
uint16 decorSeed,
uint8 seasideId
) internal pure returns (string memory) {
(uint8 count, uint8 minH, uint8 maxH) = _profileParams(profileId);
bool isNight = timeId == 2;
(uint24 col1, uint24 col2) = _profileColors(profileId, isNight);
// Buildings go on opposite side from seaside
// If seasideId==2 (pacific=left), buildings on right (x=300-390)
// If seasideId!=0 && !=2 (right side), buildings on left (x=10-100)
// If seasideId==0, buildings on both sides
uint256 s = uint256(decorSeed) + 7;
string memory bldgs = "";
if (seasideId == 0) {
// Buildings on both sides
bldgs = string.concat(
_buildingsOnSide(10, 100, count, minH, maxH, s, col1, col2, isNight),
_buildingsOnSide(300, 390, count, minH, maxH, s + 999, col1, col2, isNight)
);
} else if (seasideId == 2) {
// Pacific=left → buildings on right
bldgs = _buildingsOnSide(300, 390, count, minH, maxH, s, col1, col2, isNight);
} else {
// Others=right → buildings on left
bldgs = _buildingsOnSide(10, 100, count, minH, maxH, s, col1, col2, isNight);
}
return bldgs;
}
function _buildingsOnSide(
uint256 xMin,
uint256 xMax,
uint8 count,
uint8 minH,
uint8 maxH,
uint256 seed,
uint24 col1,
uint24 col2,
bool isNight
) internal pure returns (string memory) {
string memory result = "";
uint256 s = seed;
uint256 range = xMax - xMin;
for (uint256 i; i < count; ++i) {
s = _lcg(s);
uint256 bx = xMin + (s % range);
s = _lcg(s);
uint256 bh = minH + (s % (uint256(maxH) - uint256(minH) + 1));
uint256 bw = 12 + (s % 14); // 12-25px wide
uint256 by = 200 - bh;
s = _lcg(s);
uint24 col = s % 2 == 0 ? col1 : col2;
result = string.concat(
result,
'<rect x="', bx.toString(), '" y="', by.toString(),
'" width="', bw.toString(), '" height="', bh.toString(),
'" fill="', _hex6(col), '"/>'
);
// Night windows
if (isNight && bh > 15) {
s = _lcg(s);
uint256 wy = by + 4;
uint256 wx = bx + 3;
result = string.concat(
result,
'<rect x="', wx.toString(), '" y="', wy.toString(),
'" width="3" height="3" fill="#ffe060" opacity="0.6"/>',
'<rect x="', (wx + 5).toString(), '" y="', (wy + 8).toString(),
'" width="3" height="3" fill="#ffe060" opacity="0.5"/>'
);
}
}
return result;
}
// ============ Road + Vehicle ============
function _roadAndVehicle(bytes32 config) internal pure returns (string memory) {
uint8 timeId = uint8(config[2]);
return string.concat(
_shoulders(uint8(config[4]), timeId),
_road(timeId),
_laneDashes(uint8(config[12])),
_truck(timeId, _extractRGB(config, 14), _extractRGB(config, 17)),
_dirArrow(uint8(config[3]) & 1 == 1)
);
}
function _shoulders(uint8 biomeId, uint8 timeId) internal pure returns (string memory) {
uint24 col = timeId == 2 ? _biomeShoulderNight(biomeId) : _biomeShoulder(biomeId);
return string.concat(
'<rect x="110" y="200" width="15" height="200" fill="', _hex6(col), '"/>',
'<rect x="275" y="200" width="15" height="200" fill="', _hex6(col), '"/>'
);
}
function _road(uint8 timeId) internal pure returns (string memory) {
string memory fill = timeId == 2 ? "#2a2a30" : "#585450";
return string.concat('<rect x="125" y="200" width="150" height="200" fill="', fill, '"/>');
}
function _laneDashes(uint8 countryId) internal pure returns (string memory) {
// MX=white, US=yellow
string memory col = countryId == 0 ? "#eee" : "#dd0";
return string.concat(
'<rect x="198" y="210" width="4" height="22" fill="', col, '" rx="1"/>',
'<rect x="198" y="248" width="4" height="22" fill="', col, '" rx="1"/>',
'<rect x="198" y="286" width="4" height="22" fill="', col, '" rx="1"/>',
'<rect x="198" y="324" width="4" height="22" fill="', col, '" rx="1"/>',
'<rect x="198" y="362" width="4" height="22" fill="', col, '" rx="1"/>'
);
}
function _truck(uint8 timeId, uint24 cabColor, uint24 bedColor) internal pure returns (string memory) {
// Default to red/brown if zeros
string memory cab = cabColor == 0 ? "#dd2020" : _hex6(cabColor);
string memory bed = bedColor == 0 ? "#705030" : _hex6(bedColor);
string memory headlights = "";
if (timeId == 2) {
headlights = '<rect x="186" y="272" width="28" height="6" fill="#ff0" opacity="0.6" rx="1"/>';
}
return string.concat(
'<rect x="182" y="280" width="36" height="24" fill="', cab, '" rx="2"/>',
'<rect x="182" y="304" width="36" height="30" fill="', bed, '"/>',
headlights
);
}
function _dirArrow(bool reversed) internal pure returns (string memory) {
if (reversed) return '<polygon points="200,260 190,248 210,248" fill="#0f0" opacity="0.7"/>';
return '<polygon points="200,268 190,280 210,280" fill="#0f0" opacity="0.7"/>';
}
// ============ Overlay + Labels ============
function _weatherOverlay(uint8 wid, uint8 tid) internal pure returns (string memory) {
if (wid == 0) {
// Sunny — sun disc
return '<circle cx="320" cy="60" r="28" fill="#ffd700" opacity="0.8"/>';
}
if (wid == 1) {
// Cloudy
return string.concat(
'<circle cx="100" cy="70" r="25" fill="#aaa" opacity="0.5"/>',
'<circle cx="130" cy="62" r="20" fill="#bbb" opacity="0.5"/>',
'<circle cx="280" cy="50" r="22" fill="#aaa" opacity="0.4"/>'
);
}
if (wid == 2) {
// Rain — clouds + rain lines
return string.concat(
'<circle cx="100" cy="65" r="25" fill="#888" opacity="0.5"/>',
'<circle cx="130" cy="60" r="20" fill="#999" opacity="0.5"/>',
'<line x1="80" y1="100" x2="70" y2="130" stroke="#6af" stroke-width="1" opacity="0.4"/>',
'<line x1="150" y1="90" x2="140" y2="120" stroke="#6af" stroke-width="1" opacity="0.4"/>',
'<line x1="220" y1="95" x2="210" y2="125" stroke="#6af" stroke-width="1" opacity="0.4"/>',
'<line x1="300" y1="85" x2="290" y2="115" stroke="#6af" stroke-width="1" opacity="0.4"/>'
);
}
if (wid == 3) {
// Sunset glow
return string.concat(
'<circle cx="200" cy="165" r="40" fill="#ff6020" opacity="0.6"/>',
'<rect x="0" y="145" width="400" height="20" fill="#ff8040" opacity="0.12"/>'
);
}
// Snow (wid==4) — snowflakes
string memory color = tid == 2 ? "#dde" : "#fff";
return string.concat(
'<circle cx="60" cy="50" r="2" fill="', color, '" opacity="0.7"/>',
'<circle cx="140" cy="70" r="2" fill="', color, '" opacity="0.6"/>',
'<circle cx="220" cy="40" r="2" fill="', color, '" opacity="0.7"/>',
'<circle cx="300" cy="80" r="2" fill="', color, '" opacity="0.5"/>',
'<circle cx="350" cy="55" r="2" fill="', color, '" opacity="0.6"/>',
'<circle cx="180" cy="90" r="2" fill="', color, '" opacity="0.7"/>'
);
}
// ============ Sky Gradient Palettes ============
// 3 times x 5 weathers = 15 gradient pairs
function _skyGradient(uint8 timeId, uint8 weatherId) internal pure returns (string memory c1, string memory c2) {
if (timeId == 0) {
// Morning
if (weatherId == 1) return ("#b0c0d0", "#6090b0"); // cloudy
if (weatherId == 2) return ("#708090", "#506070"); // rain
if (weatherId == 3) return ("#ff9040", "#d06020"); // sunset
return ("#ff9040", "#4080c0"); // sunny/snow default
}
if (timeId == 1) {
// Evening
if (weatherId == 1) return ("#6a5080", "#a05030"); // cloudy
if (weatherId == 2) return ("#504060", "#604030"); // rain
if (weatherId == 3) return ("#c04080", "#ff6020"); // sunset
return ("#8040a0", "#d06020"); // sunny/snow default
}
// Night (timeId == 2)
if (weatherId == 1) return ("#0a0a30", "#151530"); // cloudy
if (weatherId == 2) return ("#080818", "#101020"); // rain
return ("#0a0a2a", "#101030"); // sunny/sunset/snow default
}
// ============ Biome Palettes ============
function _biomeLand(uint8 id) internal pure returns (uint24) {
if (id == 0) return 0xd4b060; // desert
if (id == 1) return 0x4a8030; // tropical
if (id == 2) return 0xb8a870; // coastal
if (id == 3) return 0x6a8a50; // highland
if (id == 4) return 0x606060; // urban
return 0xb89860; // mesa
}
function _biomeLandNight(uint8 id) internal pure returns (uint24) {
if (id == 0) return 0x5a4820; // desert
if (id == 1) return 0x1a3010; // tropical
if (id == 2) return 0x4a4430; // coastal
if (id == 3) return 0x1a2a10; // highland
if (id == 4) return 0x1a1c20; // urban
return 0x4a3820; // mesa
}
function _biomeShoulder(uint8 id) internal pure returns (uint24) {
if (id == 0) return 0xc4a050; // desert
if (id == 1) return 0x8a7a50; // tropical
if (id == 2) return 0xd4c8a0; // coastal
if (id == 3) return 0x8a8060; // highland
if (id == 4) return 0x808080; // urban
return 0xa08850; // mesa
}
function _biomeShoulderNight(uint8 id) internal pure returns (uint24) {
if (id == 0) return 0x3a3018; // desert
if (id == 1) return 0x3a3420; // tropical
if (id == 2) return 0x5a5438; // coastal
if (id == 3) return 0x2a2820; // highland
if (id == 4) return 0x2a2c30; // urban
return 0x3a3018; // mesa
}
// ============ Seaside Palettes ============
function _seasidePalette(uint8 id, bool isNight)
internal pure returns (uint24 water, uint24 sand, uint24 foam)
{
if (id == 1) {
// Caribbean
return isNight ? (uint24(0x0a3838), uint24(0x5a5438), uint24(0x304858))
: (uint24(0x20c0c0), uint24(0xf0e8c0), uint24(0xe0f8ff));
}
if (id == 2) {
// Pacific
return isNight ? (uint24(0x0a2030), uint24(0x4a4428), uint24(0x283840))
: (uint24(0x2070a0), uint24(0xd8c890), uint24(0xc8e8f0));
}
if (id == 3) {
// Gulf
return isNight ? (uint24(0x0a2830), uint24(0x504830), uint24(0x283840))
: (uint24(0x3888a0), uint24(0xe0d0a0), uint24(0xd0e8f0));
}
// Atlantic (id == 4)
return isNight ? (uint24(0x0a2838), uint24(0x5a5438), uint24(0x304858))
: (uint24(0x3090c0), uint24(0xf0e0b0), uint24(0xd8f0f8));
}
// ============ Profile Building Params ============
function _profileParams(uint8 id) internal pure returns (uint8 count, uint8 minH, uint8 maxH) {
if (id == 0) return (5, 50, 80); // towers
if (id == 1) return (4, 25, 50); // concrete
if (id == 2) return (4, 15, 30); // colonial
if (id == 3) return (3, 30, 55); // resort
if (id == 4) return (2, 10, 20); // pueblo
return (3, 15, 30); // industrial
}
function _profileColors(uint8 id, bool isNight) internal pure returns (uint24 c1, uint24 c2) {
if (id == 0) return isNight ? (uint24(0x1a1c24), uint24(0x202430)) : (uint24(0x505868), uint24(0x606878));
if (id == 1) return isNight ? (uint24(0x2a2a2e), uint24(0x303030)) : (uint24(0x909090), uint24(0xa0a098));
if (id == 2) return isNight ? (uint24(0x504020), uint24(0x3a2818)) : (uint24(0xd4a050), uint24(0xc08040));
if (id == 3) return isNight ? (uint24(0x3a3a40), uint24(0x303840)) : (uint24(0xe0e0e0), uint24(0xd0e0f0));
if (id == 4) return isNight ? (uint24(0x4a3828), uint24(0x3a2818)) : (uint24(0xc8a878), uint24(0xb89868));
return isNight ? (uint24(0x1a1e20), uint24(0x181c1e)) : (uint24(0x808888), uint24(0x707878));
}
// ============ Scoreboard SVG ============
/// @notice Build a leaderboard SVG showing top 5 scores
function buildScoreboardSVG(
uint16[5] calldata tokenIds,
uint48[5] calldata scores,
address[5] calldata players
) external pure returns (string memory) {
return string.concat(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">',
'<rect width="400" height="400" fill="#0a0a2a"/>',
'<text x="200" y="50" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="18" font-weight="bold">CARPOOLERS LEADERBOARD</text>',
'<line x1="40" y1="70" x2="360" y2="70" stroke="#0f0" stroke-width="1"/>',
_scoreboardRows(tokenIds, scores, players),
'<text x="200" y="380" text-anchor="middle" fill="#0f0" font-family="monospace" font-size="10" opacity="0.6">LIVE ON-CHAIN</text>',
'</svg>'
);
}
function _scoreboardRows(
uint16[5] calldata tokenIds,
uint48[5] calldata scores,
address[5] calldata players
) internal pure returns (string memory) {
string memory rows;
for (uint256 i; i < 5; ++i) {
if (tokenIds[i] == 0 && scores[i] == 0) continue;
rows = string.concat(rows, _scoreRow(i, tokenIds[i], scores[i], players[i]));
}
return rows;
}
function _scoreRow(
uint256 rank,
uint16 tokenId,
uint48 score,
address player
) internal pure returns (string memory) {
uint256 y = 110 + rank * 50;
string memory color = _rankColor(rank);
return string.concat(
'<text x="40" y="', y.toString(), '" fill="', color, '" font-family="monospace" font-size="16" font-weight="bold">#', (rank + 1).toString(), '</text>',
'<text x="80" y="', y.toString(), '" fill="#0f0" font-family="monospace" font-size="14">TOKEN #', uint256(tokenId).toString(), '</text>',
'<text x="220" y="', y.toString(), '" fill="#0f0" font-family="monospace" font-size="14">', _formatScore(uint256(score)), '</text>',
'<text x="320" y="', y.toString(), '" fill="#0f0" font-family="monospace" font-size="10" opacity="0.7">', _truncAddr(player), '</text>'
);
}
function _rankColor(uint256 rank) internal pure returns (string memory) {
if (rank == 0) return "#ffd700";
if (rank == 1) return "#c0c0c0";
if (rank == 2) return "#cd7f32";
return "#0f0";
}
function _truncAddr(address addr) internal pure returns (string memory) {
string memory full = LibString.toHexString(addr);
bytes memory b = bytes(full);
// "0xABCD...WXYZ" — first 6 chars + last 4 chars
bytes memory result = new bytes(13);
for (uint256 i; i < 6; ++i) result[i] = b[i];
result[6] = ".";
result[7] = ".";
result[8] = ".";
for (uint256 i; i < 4; ++i) result[9 + i] = b[b.length - 4 + i];
return string(result);
}
// ============ Helpers ============
function _extractRGB(bytes32 c, uint8 offset) internal pure returns (uint24) {
return uint24(uint8(c[offset])) << 16 | uint24(uint8(c[offset + 1])) << 8 | uint24(uint8(c[offset + 2]));
}
/// @dev Lehmer LCG PRNG: seed * 48271 % 2^31
function _lcg(uint256 s) internal pure returns (uint256) {
return (s * 48271 + 1) % 2147483647;
}
function _hex6(uint24 c) internal pure returns (string memory) {
return string.concat("#", LibString.toHexStringNoPrefix(uint256(c), 3));
}
function _toUpper(string calldata s) internal pure returns (string memory) {
bytes memory b = bytes(s);
for (uint256 i; i < b.length; ++i) {
if (b[i] >= 0x61 && b[i] <= 0x7a) b[i] = bytes1(uint8(b[i]) - 32);
}
return string(b);
}
function _formatScore(uint256 score) internal pure returns (string memory) {
if (score == 0) return "0";
string memory raw = score.toString();
bytes memory b = bytes(raw);
uint256 len = b.length;
if (len <= 3) return raw;
uint256 commas = (len - 1) / 3;
bytes memory result = new bytes(len + commas);
uint256 j = result.length;
for (uint256 i = len; i > 0; --i) {
result[--j] = b[i - 1];
if ((len - i + 1) % 3 == 0 && i > 1) result[--j] = ",";
}
return string(result);
}
}
Metadata.sol 42 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "solady/utils/Base64.sol";
import "solady/utils/LibString.sol";
/// @title Metadata
/// @notice Library for encoding NFT metadata and data URIs
library Metadata {
function encodeJSON(string memory json) internal pure returns (string memory) {
return string.concat("data:application/json;base64,", Base64.encode(bytes(json)));
}
function encodeHTML(string memory html) internal pure returns (string memory) {
return string.concat("data:text/html;base64,", Base64.encode(bytes(html)));
}
function encodeSVG(string memory svg) internal pure returns (string memory) {
return string.concat("data:image/svg+xml;base64,", Base64.encode(bytes(svg)));
}
function kv(string memory key, string memory value) internal pure returns (string memory) {
return string.concat('"', key, '":"', value, '"');
}
function kvRaw(string memory key, string memory value) internal pure returns (string memory) {
return string.concat('"', key, '":', value);
}
function kvNum(string memory key, uint256 value) internal pure returns (string memory) {
return string.concat('"', key, '":', LibString.toString(value));
}
function attr(string memory traitType, string memory value) internal pure returns (string memory) {
return string.concat('{"trait_type":"', traitType, '","value":"', value, '"}');
}
function attrNum(string memory traitType, uint256 value) internal pure returns (string memory) {
return string.concat('{"trait_type":"', traitType, '","value":', LibString.toString(value), '}');
}
}
ECDSA.sol 443 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Gas optimized ECDSA wrapper.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol)
///
/// @dev Note:
/// - The recovery functions use the ecrecover precompile (0x1).
/// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure.
/// This is for more safety by default.
/// Use the `tryRecover` variants if you need to get the zero address back
/// upon recovery failure instead.
/// - As of Solady version 0.0.134, all `bytes signature` variants accept both
/// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures.
/// See: https://eips.ethereum.org/EIPS/eip-2098
/// This is for calldata efficiency on smart accounts prevalent on L2s.
///
/// WARNING! Do NOT directly use signatures as unique identifiers:
/// - The recovery operations do NOT check if a signature is non-malleable.
/// - Use a nonce in the digest to prevent replay attacks on the same contract.
/// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts.
/// EIP-712 also enables readable signing of typed data for better user safety.
/// - If you need a unique hash from a signature, please use the `canonicalHash` functions.
library ECDSA {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The order of the secp256k1 elliptic curve.
uint256 internal constant N =
0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141;
/// @dev `N/2 + 1`. Used for checking the malleability of the signature.
uint256 private constant _HALF_N_PLUS_1 =
0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The signature is invalid.
error InvalidSignature();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RECOVERY OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function recover(bytes32 hash, bytes memory signature) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
for { let m := mload(0x40) } 1 {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
} {
switch mload(signature)
case 64 {
let vs := mload(add(signature, 0x40))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
}
case 65 {
mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
mstore(0x60, mload(add(signature, 0x40))) // `s`.
}
default { continue }
mstore(0x00, hash)
mstore(0x40, mload(add(signature, 0x20))) // `r`.
result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20))
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if returndatasize() { break }
}
}
}
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function recoverCalldata(bytes32 hash, bytes calldata signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
for { let m := mload(0x40) } 1 {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
} {
switch signature.length
case 64 {
let vs := calldataload(add(signature.offset, 0x20))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, calldataload(signature.offset)) // `r`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
}
case 65 {
mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
}
default { continue }
mstore(0x00, hash)
result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20))
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if returndatasize() { break }
}
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the EIP-2098 short form signature defined by `r` and `vs`.
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, r)
mstore(0x60, shr(1, shl(1, vs))) // `s`.
result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20))
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the signature defined by `v`, `r`, `s`.
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, and(v, 0xff))
mstore(0x40, r)
mstore(0x60, s)
result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20))
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* TRY-RECOVER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// WARNING!
// These functions will NOT revert upon recovery failure.
// Instead, they will return the zero address upon recovery failure.
// It is critical that the returned address is NEVER compared against
// a zero address (e.g. an uninitialized address variable).
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function tryRecover(bytes32 hash, bytes memory signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
for { let m := mload(0x40) } 1 {} {
switch mload(signature)
case 64 {
let vs := mload(add(signature, 0x40))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
}
case 65 {
mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
mstore(0x60, mload(add(signature, 0x40))) // `s`.
}
default { break }
mstore(0x00, hash)
mstore(0x40, mload(add(signature, 0x20))) // `r`.
pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20))
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
break
}
}
}
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function tryRecoverCalldata(bytes32 hash, bytes calldata signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
for { let m := mload(0x40) } 1 {} {
switch signature.length
case 64 {
let vs := calldataload(add(signature.offset, 0x20))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, calldataload(signature.offset)) // `r`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
}
case 65 {
mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
}
default { break }
mstore(0x00, hash)
pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20))
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
break
}
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the EIP-2098 short form signature defined by `r` and `vs`.
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, r)
mstore(0x60, shr(1, shl(1, vs))) // `s`.
pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20))
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the signature defined by `v`, `r`, `s`.
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, and(v, 0xff))
mstore(0x40, r)
mstore(0x60, s)
pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20))
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an Ethereum Signed Message, created from a `hash`.
/// This produces a hash corresponding to the one signed with the
/// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign)
/// JSON-RPC method as part of EIP-191.
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x20, hash) // Store into scratch space for keccak256.
mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes.
result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`.
}
}
/// @dev Returns an Ethereum Signed Message, created from `s`.
/// This produces a hash corresponding to the one signed with the
/// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign)
/// JSON-RPC method as part of EIP-191.
/// Note: Supports lengths of `s` up to 999999 bytes.
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let sLength := mload(s)
let o := 0x20
mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded.
mstore(0x00, 0x00)
// Convert the `s.length` to ASCII decimal representation: `base10(s.length)`.
for { let temp := sLength } 1 {} {
o := sub(o, 1)
mstore8(o, add(48, mod(temp, 10)))
temp := div(temp, 10)
if iszero(temp) { break }
}
let n := sub(0x3a, o) // Header length: `26 + 32 - o`.
// Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes.
returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20))
mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header.
result := keccak256(add(s, sub(0x20, n)), add(n, sLength))
mstore(s, sLength) // Restore the length.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CANONICAL HASH FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// The following functions return the hash of the signature in its canonicalized format,
// which is the 65-byte `abi.encodePacked(r, s, uint8(v))`, where `v` is either 27 or 28.
// If `s` is greater than `N / 2` then it will be converted to `N - s`
// and the `v` value will be flipped.
// If the signature has an invalid length, or if `v` is invalid,
// a uniquely corrupt hash will be returned.
// These functions are useful for "poor-mans-VRF".
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(bytes memory signature) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let l := mload(signature)
for {} 1 {} {
mstore(0x00, mload(add(signature, 0x20))) // `r`.
let s := mload(add(signature, 0x40))
let v := mload(add(signature, 0x41))
if eq(l, 64) {
v := add(shr(255, s), 27)
s := shr(1, shl(1, s))
}
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
break
}
// If the length is neither 64 nor 65, return a uniquely corrupted hash.
if iszero(lt(sub(l, 64), 2)) {
// `bytes4(keccak256("InvalidSignatureLength"))`.
result := xor(keccak256(add(signature, 0x20), l), 0xd62f1ab2)
}
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHashCalldata(bytes calldata signature)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
for {} 1 {} {
mstore(0x00, calldataload(signature.offset)) // `r`.
let s := calldataload(add(signature.offset, 0x20))
let v := calldataload(add(signature.offset, 0x21))
if eq(signature.length, 64) {
v := add(shr(255, s), 27)
s := shr(1, shl(1, s))
}
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
break
}
// If the length is neither 64 nor 65, return a uniquely corrupted hash.
if iszero(lt(sub(signature.length, 64), 2)) {
calldatacopy(mload(0x40), signature.offset, signature.length)
// `bytes4(keccak256("InvalidSignatureLength"))`.
result := xor(keccak256(mload(0x40), signature.length), 0xd62f1ab2)
}
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(bytes32 r, bytes32 vs) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, r) // `r`.
let v := add(shr(255, vs), 27)
let s := shr(1, shl(1, vs))
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(uint8 v, bytes32 r, bytes32 s) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, r) // `r`.
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EMPTY CALLDATA HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an empty calldata bytes.
function emptySignature() internal pure returns (bytes calldata signature) {
/// @solidity memory-safe-assembly
assembly {
signature.length := 0
}
}
}
EIP712.sol 300 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Contract for EIP-712 typed structured data hashing and signing.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/EIP712.sol)
/// @author Modified from Solbase (https://github.com/Sol-DAO/solbase/blob/main/src/utils/EIP712.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol)
///
/// @dev Note, this implementation:
/// - Uses `address(this)` for the `verifyingContract` field.
/// - Does NOT use the optional EIP-712 salt.
/// - Does NOT use any EIP-712 extensions.
/// This is for simplicity and to save gas.
/// If you need to customize, please fork / modify accordingly.
abstract contract EIP712 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS AND IMMUTABLES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
bytes32 internal constant _DOMAIN_TYPEHASH =
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
/// @dev `keccak256("EIP712Domain(string name,string version,address verifyingContract)")`.
/// This is only used in `_hashTypedDataSansChainId`.
bytes32 internal constant _DOMAIN_TYPEHASH_SANS_CHAIN_ID =
0x91ab3d17e3a50a9d89e63fd30b92be7f5336b03b287bb946787a83a9d62a2766;
/// @dev `keccak256("EIP712Domain(string name,string version)")`.
/// This is only used in `_hashTypedDataSansChainIdAndVerifyingContract`.
bytes32 internal constant _DOMAIN_TYPEHASH_SANS_CHAIN_ID_AND_VERIFYING_CONTRACT =
0xb03948446334eb9b2196d5eb166f69b9d49403eb4a12f36de8d3f9f3cb8e15c3;
/// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId)")`.
/// This is only used in `_hashTypedDataSansVerifyingContract`.
bytes32 internal constant _DOMAIN_TYPEHASH_SANS_VERIFYING_CONTRACT =
0xc2f8787176b8ac6bf7215b4adcc1e069bf4ab82d9ab1df05a57a91d425935b6e;
uint256 private immutable _cachedThis;
uint256 private immutable _cachedChainId;
bytes32 private immutable _cachedNameHash;
bytes32 private immutable _cachedVersionHash;
bytes32 private immutable _cachedDomainSeparator;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTRUCTOR */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Cache the hashes for cheaper runtime gas costs.
/// In the case of upgradeable contracts (i.e. proxies),
/// or if the chain id changes due to a hard fork,
/// the domain separator will be seamlessly calculated on-the-fly.
constructor() {
_cachedThis = uint256(uint160(address(this)));
_cachedChainId = block.chainid;
string memory name;
string memory version;
if (!_domainNameAndVersionMayChange()) (name, version) = _domainNameAndVersion();
bytes32 nameHash = _domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(name));
bytes32 versionHash =
_domainNameAndVersionMayChange() ? bytes32(0) : keccak256(bytes(version));
_cachedNameHash = nameHash;
_cachedVersionHash = versionHash;
bytes32 separator;
if (!_domainNameAndVersionMayChange()) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Load the free memory pointer.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), nameHash)
mstore(add(m, 0x40), versionHash)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
separator := keccak256(m, 0xa0)
}
}
_cachedDomainSeparator = separator;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* FUNCTIONS TO OVERRIDE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Please override this function to return the domain name and version.
/// ```
/// function _domainNameAndVersion()
/// internal
/// pure
/// virtual
/// returns (string memory name, string memory version)
/// {
/// name = "Solady";
/// version = "1";
/// }
/// ```
///
/// Note: If the returned result may change after the contract has been deployed,
/// you must override `_domainNameAndVersionMayChange()` to return true.
function _domainNameAndVersion()
internal
view
virtual
returns (string memory name, string memory version);
/// @dev Returns if `_domainNameAndVersion()` may change
/// after the contract has been deployed (i.e. after the constructor).
/// Default: false.
function _domainNameAndVersionMayChange() internal pure virtual returns (bool result) {}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the EIP-712 domain separator.
function _domainSeparator() internal view virtual returns (bytes32 separator) {
if (_domainNameAndVersionMayChange()) {
separator = _buildDomainSeparator();
} else {
separator = _cachedDomainSeparator;
if (_cachedDomainSeparatorInvalidated()) separator = _buildDomainSeparator();
}
}
/// @dev Returns the hash of the fully encoded EIP-712 message for this domain,
/// given `structHash`, as defined in
/// https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
///
/// The hash can be used together with {ECDSA-recover} to obtain the signer of a message:
/// ```
/// bytes32 digest = _hashTypedData(keccak256(abi.encode(
/// keccak256("Mail(address to,string contents)"),
/// mailTo,
/// keccak256(bytes(mailContents))
/// )));
/// address signer = ECDSA.recover(digest, signature);
/// ```
function _hashTypedData(bytes32 structHash) internal view virtual returns (bytes32 digest) {
// We will use `digest` to store the domain separator to save a bit of gas.
if (_domainNameAndVersionMayChange()) {
digest = _buildDomainSeparator();
} else {
digest = _cachedDomainSeparator;
if (_cachedDomainSeparatorInvalidated()) digest = _buildDomainSeparator();
}
/// @solidity memory-safe-assembly
assembly {
// Compute the digest.
mstore(0x00, 0x1901000000000000) // Store "\x19\x01".
mstore(0x1a, digest) // Store the domain separator.
mstore(0x3a, structHash) // Store the struct hash.
digest := keccak256(0x18, 0x42)
// Restore the part of the free memory slot that was overwritten.
mstore(0x3a, 0)
}
}
/// @dev Variant of `_hashTypedData` that excludes the chain ID.
/// Included for the niche use case of cross-chain workflows.
function _hashTypedDataSansChainId(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)
{
(string memory name, string memory version) = _domainNameAndVersion();
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Load the free memory pointer.
mstore(0x00, _DOMAIN_TYPEHASH_SANS_CHAIN_ID)
mstore(0x20, keccak256(add(name, 0x20), mload(name)))
mstore(0x40, keccak256(add(version, 0x20), mload(version)))
mstore(0x60, address())
// Compute the digest.
mstore(0x20, keccak256(0x00, 0x80)) // Store the domain separator.
mstore(0x00, 0x1901) // Store "\x19\x01".
mstore(0x40, structHash) // Store the struct hash.
digest := keccak256(0x1e, 0x42)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/// @dev Variant of `_hashTypedData` that excludes the chain ID and verifying contract.
/// Included for the niche use case of cross-chain and multi-verifier workflows.
function _hashTypedDataSansChainIdAndVerifyingContract(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)
{
(string memory name, string memory version) = _domainNameAndVersion();
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Load the free memory pointer.
mstore(0x00, _DOMAIN_TYPEHASH_SANS_CHAIN_ID_AND_VERIFYING_CONTRACT)
mstore(0x20, keccak256(add(name, 0x20), mload(name)))
mstore(0x40, keccak256(add(version, 0x20), mload(version)))
// Compute the digest.
mstore(0x20, keccak256(0x00, 0x60)) // Store the domain separator.
mstore(0x00, 0x1901) // Store "\x19\x01".
mstore(0x40, structHash) // Store the struct hash.
digest := keccak256(0x1e, 0x42)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/// @dev Variant of `_hashTypedData` that excludes the chain ID and verifying contract.
/// Included for the niche use case of multi-verifier workflows.
function _hashTypedDataSansVerifyingContract(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)
{
(string memory name, string memory version) = _domainNameAndVersion();
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Load the free memory pointer.
mstore(0x00, _DOMAIN_TYPEHASH_SANS_VERIFYING_CONTRACT)
mstore(0x20, keccak256(add(name, 0x20), mload(name)))
mstore(0x40, keccak256(add(version, 0x20), mload(version)))
mstore(0x60, chainid())
// Compute the digest.
mstore(0x20, keccak256(0x00, 0x80)) // Store the domain separator.
mstore(0x00, 0x1901) // Store "\x19\x01".
mstore(0x40, structHash) // Store the struct hash.
digest := keccak256(0x1e, 0x42)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EIP-5267 OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev See: https://eips.ethereum.org/EIPS/eip-5267
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
fields = hex"0f"; // `0b01111`.
(name, version) = _domainNameAndVersion();
chainId = block.chainid;
verifyingContract = address(this);
salt = salt; // `bytes32(0)`.
extensions = extensions; // `new uint256[](0)`.
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PRIVATE HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the EIP-712 domain separator.
function _buildDomainSeparator() private view returns (bytes32 separator) {
// We will use `separator` to store the name hash to save a bit of gas.
bytes32 versionHash;
if (_domainNameAndVersionMayChange()) {
(string memory name, string memory version) = _domainNameAndVersion();
separator = keccak256(bytes(name));
versionHash = keccak256(bytes(version));
} else {
separator = _cachedNameHash;
versionHash = _cachedVersionHash;
}
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Load the free memory pointer.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), separator) // Name hash.
mstore(add(m, 0x40), versionHash)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
separator := keccak256(m, 0xa0)
}
}
/// @dev Returns if the cached domain separator has been invalidated.
function _cachedDomainSeparatorInvalidated() private view returns (bool result) {
uint256 cachedChainId = _cachedChainId;
uint256 cachedThis = _cachedThis;
/// @solidity memory-safe-assembly
assembly {
result := iszero(and(eq(chainid(), cachedChainId), eq(address(), cachedThis)))
}
}
}
LibString.sol 979 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {LibBytes} from "./LibBytes.sol";
/// @notice Library for converting numbers into strings and other string operations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol)
///
/// @dev Note:
/// For performance and bytecode compactness, most of the string operations are restricted to
/// byte strings (7-bit ASCII), except where otherwise specified.
/// Usage of byte string operations on charsets with runes spanning two or more bytes
/// can lead to undefined behavior.
library LibString {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Goated string storage struct that totally MOGs, no cap, fr.
/// Uses less gas and bytecode than Solidity's native string storage. It's meta af.
/// Packs length with the first 31 bytes if <255 bytes, so it’s mad tight.
struct StringStorage {
bytes32 _spacer;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The length of the output is too small to contain all the hex digits.
error HexLengthInsufficient();
/// @dev The length of the string is more than 32 bytes.
error TooBigForSmallString();
/// @dev The input string must be a 7-bit ASCII.
error StringNot7BitASCII();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The constant returned when the `search` is not found in the string.
uint256 internal constant NOT_FOUND = type(uint256).max;
/// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant ALPHANUMERIC_7_BIT_ASCII = 0x7fffffe07fffffe03ff000000000000;
/// @dev Lookup for 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant LETTERS_7_BIT_ASCII = 0x7fffffe07fffffe0000000000000000;
/// @dev Lookup for 'abcdefghijklmnopqrstuvwxyz'.
uint128 internal constant LOWERCASE_7_BIT_ASCII = 0x7fffffe000000000000000000000000;
/// @dev Lookup for 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant UPPERCASE_7_BIT_ASCII = 0x7fffffe0000000000000000;
/// @dev Lookup for '0123456789'.
uint128 internal constant DIGITS_7_BIT_ASCII = 0x3ff000000000000;
/// @dev Lookup for '0123456789abcdefABCDEF'.
uint128 internal constant HEXDIGITS_7_BIT_ASCII = 0x7e0000007e03ff000000000000;
/// @dev Lookup for '01234567'.
uint128 internal constant OCTDIGITS_7_BIT_ASCII = 0xff000000000000;
/// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'.
uint128 internal constant PRINTABLE_7_BIT_ASCII = 0x7fffffffffffffffffffffff00003e00;
/// @dev Lookup for '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.
uint128 internal constant PUNCTUATION_7_BIT_ASCII = 0x78000001f8000001fc00fffe00000000;
/// @dev Lookup for ' \t\n\r\x0b\x0c'.
uint128 internal constant WHITESPACE_7_BIT_ASCII = 0x100003e00;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRING STORAGE OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Sets the value of the string storage `$` to `s`.
function set(StringStorage storage $, string memory s) internal {
LibBytes.set(bytesStorage($), bytes(s));
}
/// @dev Sets the value of the string storage `$` to `s`.
function setCalldata(StringStorage storage $, string calldata s) internal {
LibBytes.setCalldata(bytesStorage($), bytes(s));
}
/// @dev Sets the value of the string storage `$` to the empty string.
function clear(StringStorage storage $) internal {
delete $._spacer;
}
/// @dev Returns whether the value stored is `$` is the empty string "".
function isEmpty(StringStorage storage $) internal view returns (bool) {
return uint256($._spacer) & 0xff == uint256(0);
}
/// @dev Returns the length of the value stored in `$`.
function length(StringStorage storage $) internal view returns (uint256) {
return LibBytes.length(bytesStorage($));
}
/// @dev Returns the value stored in `$`.
function get(StringStorage storage $) internal view returns (string memory) {
return string(LibBytes.get(bytesStorage($)));
}
/// @dev Returns the uint8 at index `i`. If out-of-bounds, returns 0.
function uint8At(StringStorage storage $, uint256 i) internal view returns (uint8) {
return LibBytes.uint8At(bytesStorage($), i);
}
/// @dev Helper to cast `$` to a `BytesStorage`.
function bytesStorage(StringStorage storage $)
internal
pure
returns (LibBytes.BytesStorage storage casted)
{
/// @solidity memory-safe-assembly
assembly {
casted.slot := $.slot
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DECIMAL OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the base 10 decimal representation of `value`.
function toString(uint256 value) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
// The maximum value of a uint256 contains 78 digits (1 byte per digit), but
// we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
// We will need 1 word for the trailing zeros padding, 1 word for the length,
// and 3 words for a maximum of 78 digits.
result := add(mload(0x40), 0x80)
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end of the memory to calculate the length later.
let w := not(0) // Tsk.
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
for { let temp := value } 1 {} {
result := add(result, w) // `sub(result, 1)`.
// Store the character to the pointer.
// The ASCII index of the '0' character is 48.
mstore8(result, add(48, mod(temp, 10)))
temp := div(temp, 10) // Keep dividing `temp` until zero.
if iszero(temp) { break }
}
let n := sub(end, result)
result := sub(result, 0x20) // Move the pointer 32 bytes back to make room for the length.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the base 10 decimal representation of `value`.
function toString(int256 value) internal pure returns (string memory result) {
if (value >= 0) return toString(uint256(value));
unchecked {
result = toString(~uint256(value) + 1);
}
/// @solidity memory-safe-assembly
assembly {
// We still have some spare memory space on the left,
// as we have allocated 3 words (96 bytes) for up to 78 digits.
let n := mload(result) // Load the string length.
mstore(result, 0x2d) // Store the '-' character.
result := sub(result, 1) // Move back the string pointer by a byte.
mstore(result, add(n, 1)) // Update the string length.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HEXADECIMAL OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the hexadecimal representation of `value`,
/// left-padded to an input length of `byteCount` bytes.
/// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte,
/// giving a total length of `byteCount * 2 + 2` bytes.
/// Reverts if `byteCount` is too small for the output to contain all the digits.
function toHexString(uint256 value, uint256 byteCount)
internal
pure
returns (string memory result)
{
result = toHexStringNoPrefix(value, byteCount);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`,
/// left-padded to an input length of `byteCount` bytes.
/// The output is not prefixed with "0x" and is encoded using 2 hexadecimal digits per byte,
/// giving a total length of `byteCount * 2` bytes.
/// Reverts if `byteCount` is too small for the output to contain all the digits.
function toHexStringNoPrefix(uint256 value, uint256 byteCount)
internal
pure
returns (string memory result)
{
/// @solidity memory-safe-assembly
assembly {
// We need 0x20 bytes for the trailing zeros padding, `byteCount * 2` bytes
// for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length.
// We add 0x20 to the total and round down to a multiple of 0x20.
// (0x20 + 0x20 + 0x02 + 0x20) = 0x62.
result := add(mload(0x40), and(add(shl(1, byteCount), 0x42), not(0x1f)))
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end to calculate the length later.
// Store "0123456789abcdef" in scratch space.
mstore(0x0f, 0x30313233343536373839616263646566)
let start := sub(result, add(byteCount, byteCount))
let w := not(1) // Tsk.
let temp := value
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
for {} 1 {} {
result := add(result, w) // `sub(result, 2)`.
mstore8(add(result, 1), mload(and(temp, 15)))
mstore8(result, mload(and(shr(4, temp), 15)))
temp := shr(8, temp)
if iszero(xor(result, start)) { break }
}
if temp {
mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`.
revert(0x1c, 0x04)
}
let n := sub(end, result)
result := sub(result, 0x20)
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
/// As address are 20 bytes long, the output will left-padded to have
/// a length of `20 * 2 + 2` bytes.
function toHexString(uint256 value) internal pure returns (string memory result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is prefixed with "0x".
/// The output excludes leading "0" from the `toHexString` output.
/// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`.
function toMinimalHexString(uint256 value) internal pure returns (string memory result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present.
let n := add(mload(result), 2) // Compute the length.
mstore(add(result, o), 0x3078) // Store the "0x" prefix, accounting for leading zero.
result := sub(add(result, o), 2) // Move the pointer, accounting for leading zero.
mstore(result, sub(n, o)) // Store the length, accounting for leading zero.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output excludes leading "0" from the `toHexStringNoPrefix` output.
/// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`.
function toMinimalHexStringNoPrefix(uint256 value)
internal
pure
returns (string memory result)
{
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present.
let n := mload(result) // Get the length.
result := add(result, o) // Move the pointer, accounting for leading zero.
mstore(result, sub(n, o)) // Store the length, accounting for leading zero.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is encoded using 2 hexadecimal digits per byte.
/// As address are 20 bytes long, the output will left-padded to have
/// a length of `20 * 2` bytes.
function toHexStringNoPrefix(uint256 value) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
// We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
// 0x02 bytes for the prefix, and 0x40 bytes for the digits.
// The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0.
result := add(mload(0x40), 0x80)
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end to calculate the length later.
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
let w := not(1) // Tsk.
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
for { let temp := value } 1 {} {
result := add(result, w) // `sub(result, 2)`.
mstore8(add(result, 1), mload(and(temp, 15)))
mstore8(result, mload(and(shr(4, temp), 15)))
temp := shr(8, temp)
if iszero(temp) { break }
}
let n := sub(end, result)
result := sub(result, 0x20)
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte,
/// and the alphabets are capitalized conditionally according to
/// https://eips.ethereum.org/EIPS/eip-55
function toHexStringChecksummed(address value) internal pure returns (string memory result) {
result = toHexString(value);
/// @solidity memory-safe-assembly
assembly {
let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...`
let o := add(result, 0x22)
let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... `
let t := shl(240, 136) // `0b10001000 << 240`
for { let i := 0 } 1 {} {
mstore(add(i, i), mul(t, byte(i, hashed)))
i := add(i, 1)
if eq(i, 20) { break }
}
mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask)))))
o := add(o, 0x20)
mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask)))))
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
function toHexString(address value) internal pure returns (string memory result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`.
/// The output is encoded using 2 hexadecimal digits per byte.
function toHexStringNoPrefix(address value) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
// Allocate memory.
// We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
// 0x02 bytes for the prefix, and 0x28 bytes for the digits.
// The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80.
mstore(0x40, add(result, 0x80))
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
result := add(result, 2)
mstore(result, 40) // Store the length.
let o := add(result, 0x20)
mstore(add(o, 40), 0) // Zeroize the slot after the string.
value := shl(96, value)
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
for { let i := 0 } 1 {} {
let p := add(o, add(i, i))
let temp := byte(i, value)
mstore8(add(p, 1), mload(and(temp, 15)))
mstore8(p, mload(shr(4, temp)))
i := add(i, 1)
if eq(i, 20) { break }
}
}
}
/// @dev Returns the hex encoded string from the raw bytes.
/// The output is encoded using 2 hexadecimal digits per byte.
function toHexString(bytes memory raw) internal pure returns (string memory result) {
result = toHexStringNoPrefix(raw);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hex encoded string from the raw bytes.
/// The output is encoded using 2 hexadecimal digits per byte.
function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(raw)
result := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix.
mstore(result, add(n, n)) // Store the length of the output.
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
let o := add(result, 0x20)
let end := add(raw, n)
for {} iszero(eq(raw, end)) {} {
raw := add(raw, 1)
mstore8(add(o, 1), mload(and(mload(raw), 15)))
mstore8(o, mload(and(shr(4, mload(raw)), 15)))
o := add(o, 2)
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RUNE STRING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the number of UTF characters in the string.
function runeCount(string memory s) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
if mload(s) {
mstore(0x00, div(not(0), 255))
mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506)
let o := add(s, 0x20)
let end := add(o, mload(s))
for { result := 1 } 1 { result := add(result, 1) } {
o := add(o, byte(0, mload(shr(250, mload(o)))))
if iszero(lt(o, end)) { break }
}
}
}
}
/// @dev Returns if this string is a 7-bit ASCII string.
/// (i.e. all characters codes are in [0..127])
function is7BitASCII(string memory s) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := 1
let mask := shl(7, div(not(0), 255))
let n := mload(s)
if n {
let o := add(s, 0x20)
let end := add(o, n)
let last := mload(end)
mstore(end, 0)
for {} 1 {} {
if and(mask, mload(o)) {
result := 0
break
}
o := add(o, 0x20)
if iszero(lt(o, end)) { break }
}
mstore(end, last)
}
}
}
/// @dev Returns if this string is a 7-bit ASCII string,
/// AND all characters are in the `allowed` lookup.
/// Note: If `s` is empty, returns true regardless of `allowed`.
function is7BitASCII(string memory s, uint128 allowed) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := 1
if mload(s) {
let allowed_ := shr(128, shl(128, allowed))
let o := add(s, 0x20)
for { let end := add(o, mload(s)) } 1 {} {
result := and(result, shr(byte(0, mload(o)), allowed_))
o := add(o, 1)
if iszero(and(result, lt(o, end))) { break }
}
}
}
}
/// @dev Converts the bytes in the 7-bit ASCII string `s` to
/// an allowed lookup for use in `is7BitASCII(s, allowed)`.
/// To save runtime gas, you can cache the result in an immutable variable.
function to7BitASCIIAllowedLookup(string memory s) internal pure returns (uint128 result) {
/// @solidity memory-safe-assembly
assembly {
if mload(s) {
let o := add(s, 0x20)
for { let end := add(o, mload(s)) } 1 {} {
result := or(result, shl(byte(0, mload(o)), 1))
o := add(o, 1)
if iszero(lt(o, end)) { break }
}
if shr(128, result) {
mstore(0x00, 0xc9807e0d) // `StringNot7BitASCII()`.
revert(0x1c, 0x04)
}
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* BYTE STRING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// For performance and bytecode compactness, byte string operations are restricted
// to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets.
// Usage of byte string operations on charsets with runes spanning two or more bytes
// can lead to undefined behavior.
/// @dev Returns `subject` all occurrences of `needle` replaced with `replacement`.
function replace(string memory subject, string memory needle, string memory replacement)
internal
pure
returns (string memory)
{
return string(LibBytes.replace(bytes(subject), bytes(needle), bytes(replacement)));
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(string memory subject, string memory needle, uint256 from)
internal
pure
returns (uint256)
{
return LibBytes.indexOf(bytes(subject), bytes(needle), from);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(string memory subject, string memory needle) internal pure returns (uint256) {
return LibBytes.indexOf(bytes(subject), bytes(needle), 0);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from right to left, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(string memory subject, string memory needle, uint256 from)
internal
pure
returns (uint256)
{
return LibBytes.lastIndexOf(bytes(subject), bytes(needle), from);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from right to left.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(string memory subject, string memory needle)
internal
pure
returns (uint256)
{
return LibBytes.lastIndexOf(bytes(subject), bytes(needle), type(uint256).max);
}
/// @dev Returns true if `needle` is found in `subject`, false otherwise.
function contains(string memory subject, string memory needle) internal pure returns (bool) {
return LibBytes.contains(bytes(subject), bytes(needle));
}
/// @dev Returns whether `subject` starts with `needle`.
function startsWith(string memory subject, string memory needle) internal pure returns (bool) {
return LibBytes.startsWith(bytes(subject), bytes(needle));
}
/// @dev Returns whether `subject` ends with `needle`.
function endsWith(string memory subject, string memory needle) internal pure returns (bool) {
return LibBytes.endsWith(bytes(subject), bytes(needle));
}
/// @dev Returns `subject` repeated `times`.
function repeat(string memory subject, uint256 times) internal pure returns (string memory) {
return string(LibBytes.repeat(bytes(subject), times));
}
/// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function slice(string memory subject, uint256 start, uint256 end)
internal
pure
returns (string memory)
{
return string(LibBytes.slice(bytes(subject), start, end));
}
/// @dev Returns a copy of `subject` sliced from `start` to the end of the string.
/// `start` is a byte offset.
function slice(string memory subject, uint256 start) internal pure returns (string memory) {
return string(LibBytes.slice(bytes(subject), start, type(uint256).max));
}
/// @dev Returns all the indices of `needle` in `subject`.
/// The indices are byte offsets.
function indicesOf(string memory subject, string memory needle)
internal
pure
returns (uint256[] memory)
{
return LibBytes.indicesOf(bytes(subject), bytes(needle));
}
/// @dev Returns an arrays of strings based on the `delimiter` inside of the `subject` string.
function split(string memory subject, string memory delimiter)
internal
pure
returns (string[] memory result)
{
bytes[] memory a = LibBytes.split(bytes(subject), bytes(delimiter));
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Returns a concatenated string of `a` and `b`.
/// Cheaper than `string.concat()` and does not de-align the free memory pointer.
function concat(string memory a, string memory b) internal pure returns (string memory) {
return string(LibBytes.concat(bytes(a), bytes(b)));
}
/// @dev Returns a copy of the string in either lowercase or UPPERCASE.
/// WARNING! This function is only compatible with 7-bit ASCII strings.
function toCase(string memory subject, bool toUpper)
internal
pure
returns (string memory result)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(subject)
if n {
result := mload(0x40)
let o := add(result, 0x20)
let d := sub(subject, result)
let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff)
for { let end := add(o, n) } 1 {} {
let b := byte(0, mload(add(d, o)))
mstore8(o, xor(and(shr(b, flags), 0x20), b))
o := add(o, 1)
if eq(o, end) { break }
}
mstore(result, n) // Store the length.
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
}
/// @dev Returns a string from a small bytes32 string.
/// `s` must be null-terminated, or behavior will be undefined.
function fromSmallString(bytes32 s) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let n := 0
for {} // Scan for '\0'.
byte(n, s) { n := add(n, 1) } {}
mstore(result, n) // Store the length.
let o := add(result, 0x20)
mstore(o, s) // Store the bytes of the string.
mstore(add(o, n), 0) // Zeroize the slot after the string.
mstore(0x40, add(result, 0x40)) // Allocate memory.
}
}
/// @dev Returns the small string, with all bytes after the first null byte zeroized.
function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
for {} // Scan for '\0'.
byte(result, s) { result := add(result, 1) } {}
mstore(0x00, s)
mstore(result, 0x00)
result := mload(0x00)
}
}
/// @dev Returns the string as a normalized null-terminated small string.
function toSmallString(string memory s) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(s)
if iszero(lt(result, 33)) {
mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`.
revert(0x1c, 0x04)
}
result := shl(shl(3, sub(32, result)), mload(add(s, result)))
}
}
/// @dev Returns a lowercased copy of the string.
/// WARNING! This function is only compatible with 7-bit ASCII strings.
function lower(string memory subject) internal pure returns (string memory result) {
result = toCase(subject, false);
}
/// @dev Returns an UPPERCASED copy of the string.
/// WARNING! This function is only compatible with 7-bit ASCII strings.
function upper(string memory subject) internal pure returns (string memory result) {
result = toCase(subject, true);
}
/// @dev Escapes the string to be used within HTML tags.
function escapeHTML(string memory s) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let end := add(s, mload(s))
let o := add(result, 0x20)
// Store the bytes of the packed offsets and strides into the scratch space.
// `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6.
mstore(0x1f, 0x900094)
mstore(0x08, 0xc0000000a6ab)
// Store ""&'<>" into the scratch space.
mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b))
for {} iszero(eq(s, end)) {} {
s := add(s, 1)
let c := and(mload(s), 0xff)
// Not in `["\"","'","&","<",">"]`.
if iszero(and(shl(c, 1), 0x500000c400000000)) {
mstore8(o, c)
o := add(o, 1)
continue
}
let t := shr(248, mload(c))
mstore(o, mload(and(t, 0x1f)))
o := add(o, shr(5, t))
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
/// @dev Escapes the string to be used within double-quotes in a JSON.
/// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes.
function escapeJSON(string memory s, bool addDoubleQuotes)
internal
pure
returns (string memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let o := add(result, 0x20)
if addDoubleQuotes {
mstore8(o, 34)
o := add(1, o)
}
// Store "\\u0000" in scratch space.
// Store "0123456789abcdef" in scratch space.
// Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`.
// into the scratch space.
mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672)
// Bitmask for detecting `["\"","\\"]`.
let e := or(shl(0x22, 1), shl(0x5c, 1))
for { let end := add(s, mload(s)) } iszero(eq(s, end)) {} {
s := add(s, 1)
let c := and(mload(s), 0xff)
if iszero(lt(c, 0x20)) {
if iszero(and(shl(c, 1), e)) {
// Not in `["\"","\\"]`.
mstore8(o, c)
o := add(o, 1)
continue
}
mstore8(o, 0x5c) // "\\".
mstore8(add(o, 1), c)
o := add(o, 2)
continue
}
if iszero(and(shl(c, 1), 0x3700)) {
// Not in `["\b","\t","\n","\f","\d"]`.
mstore8(0x1d, mload(shr(4, c))) // Hex value.
mstore8(0x1e, mload(and(c, 15))) // Hex value.
mstore(o, mload(0x19)) // "\\u00XX".
o := add(o, 6)
continue
}
mstore8(o, 0x5c) // "\\".
mstore8(add(o, 1), mload(add(c, 8)))
o := add(o, 2)
}
if addDoubleQuotes {
mstore8(o, 34)
o := add(1, o)
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
/// @dev Escapes the string to be used within double-quotes in a JSON.
function escapeJSON(string memory s) internal pure returns (string memory result) {
result = escapeJSON(s, false);
}
/// @dev Encodes `s` so that it can be safely used in a URI,
/// just like `encodeURIComponent` in JavaScript.
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
/// See: https://datatracker.ietf.org/doc/html/rfc2396
/// See: https://datatracker.ietf.org/doc/html/rfc3986
function encodeURIComponent(string memory s) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
// Store "0123456789ABCDEF" in scratch space.
// Uppercased to be consistent with JavaScript's implementation.
mstore(0x0f, 0x30313233343536373839414243444546)
let o := add(result, 0x20)
for { let end := add(s, mload(s)) } iszero(eq(s, end)) {} {
s := add(s, 1)
let c := and(mload(s), 0xff)
// If not in `[0-9A-Z-a-z-_.!~*'()]`.
if iszero(and(1, shr(c, 0x47fffffe87fffffe03ff678200000000))) {
mstore8(o, 0x25) // '%'.
mstore8(add(o, 1), mload(and(shr(4, c), 15)))
mstore8(add(o, 2), mload(and(c, 15)))
o := add(o, 3)
continue
}
mstore8(o, c)
o := add(o, 1)
}
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
/// @dev Returns whether `a` equals `b`.
function eq(string memory a, string memory b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b)))
}
}
/// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small string.
function eqs(string memory a, bytes32 b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
// These should be evaluated on compile time, as far as possible.
let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`.
let x := not(or(m, or(b, add(m, and(b, m)))))
let r := shl(7, iszero(iszero(shr(128, x))))
r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x))))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))),
xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20)))))
}
}
/// @dev Returns 0 if `a == b`, -1 if `a < b`, +1 if `a > b`.
/// If `a` == b[:a.length]`, and `a.length < b.length`, returns -1.
function cmp(string memory a, string memory b) internal pure returns (int256) {
return LibBytes.cmp(bytes(a), bytes(b));
}
/// @dev Packs a single string with its length into a single word.
/// Returns `bytes32(0)` if the length is zero or greater than 31.
function packOne(string memory a) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
// We don't need to zero right pad the string,
// since this is our own custom non-standard packing scheme.
result := mul(
// Load the length and the bytes.
mload(add(a, 0x1f)),
// `length != 0 && length < 32`. Abuses underflow.
// Assumes that the length is valid and within the block gas limit.
lt(sub(mload(a), 1), 0x1f)
)
}
}
/// @dev Unpacks a string packed using {packOne}.
/// Returns the empty string if `packed` is `bytes32(0)`.
/// If `packed` is not an output of {packOne}, the output behavior is undefined.
function unpackOne(bytes32 packed) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40) // Grab the free memory pointer.
mstore(0x40, add(result, 0x40)) // Allocate 2 words (1 for the length, 1 for the bytes).
mstore(result, 0) // Zeroize the length slot.
mstore(add(result, 0x1f), packed) // Store the length and bytes.
mstore(add(add(result, 0x20), mload(result)), 0) // Right pad with zeroes.
}
}
/// @dev Packs two strings with their lengths into a single word.
/// Returns `bytes32(0)` if combined length is zero or greater than 30.
function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let aLen := mload(a)
// We don't need to zero right pad the strings,
// since this is our own custom non-standard packing scheme.
result := mul(
or( // Load the length and the bytes of `a` and `b`.
shl(shl(3, sub(0x1f, aLen)), mload(add(a, aLen))),
shr(shl(3, add(aLen, 1)), mload(add(b, 0x1f)))
),
// `totalLen != 0 && totalLen < 31`. Abuses underflow.
// Assumes that the lengths are valid and within the block gas limit.
lt(sub(add(aLen, mload(b)), 1), 0x1e)
)
}
}
/// @dev Unpacks strings packed using {packTwo}.
/// Returns the empty strings if `packed` is `bytes32(0)`.
/// If `packed` is not an output of {packTwo}, the output behavior is undefined.
function unpackTwo(bytes32 packed)
internal
pure
returns (string memory resultA, string memory resultB)
{
/// @solidity memory-safe-assembly
assembly {
resultA := mload(0x40) // Grab the free memory pointer.
resultB := add(resultA, 0x40)
// Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words.
mstore(0x40, add(resultB, 0x40))
// Zeroize the length slots.
mstore(resultA, 0)
mstore(resultB, 0)
// Store the lengths and bytes.
mstore(add(resultA, 0x1f), packed)
mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA))))
// Right pad with zeroes.
mstore(add(add(resultA, 0x20), mload(resultA)), 0)
mstore(add(add(resultB, 0x20), mload(resultB)), 0)
}
}
/// @dev Directly returns `a` without copying.
function directReturn(string memory a) internal pure {
/// @solidity memory-safe-assembly
assembly {
// Assumes that the string does not start from the scratch space.
let retStart := sub(a, 0x20)
let retUnpaddedSize := add(mload(a), 0x40)
// Right pad with zeroes. Just in case the string is produced
// by a method that doesn't zero right pad.
mstore(add(retStart, retUnpaddedSize), 0)
mstore(retStart, 0x20) // Store the return offset.
// End the transaction, returning the string.
return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize)))
}
}
}
Base64.sol 171 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library to encode strings in Base64. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Base64.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Base64.sol) /// @author Modified from (https://github.com/Brechtpd/base64/blob/main/base64.sol) by Brecht Devos - <[email protected]>. library Base64 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ENCODING / DECODING */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// See: https://datatracker.ietf.org/doc/html/rfc4648 /// @param fileSafe Whether to replace '+' with '-' and '/' with '_'. /// @param noPadding Whether to strip away the padding. function encode(bytes memory data, bool fileSafe, bool noPadding) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let dataLength := mload(data) if dataLength { // Multiply by 4/3 rounded up. // The `shl(2, ...)` is equivalent to multiplying by 4. let encodedLength := shl(2, div(add(dataLength, 2), 3)) // Set `result` to point to the start of the free memory. result := mload(0x40) // Store the table into the scratch space. // Offsetted by -1 byte so that the `mload` will load the character. // We will rewrite the free memory pointer at `0x40` later with // the allocated size. // The magic constant 0x0670 will turn "-_" into "+/". mstore(0x1f, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef") mstore(0x3f, xor("ghijklmnopqrstuvwxyz0123456789-_", mul(iszero(fileSafe), 0x0670))) // Skip the first slot, which stores the length. let ptr := add(result, 0x20) let end := add(ptr, encodedLength) let dataEnd := add(add(0x20, data), dataLength) let dataEndValue := mload(dataEnd) // Cache the value at the `dataEnd` slot. mstore(dataEnd, 0x00) // Zeroize the `dataEnd` slot to clear dirty bits. // Run over the input, 3 bytes at a time. for {} 1 {} { data := add(data, 3) // Advance 3 bytes. let input := mload(data) // Write 4 bytes. Optimized for fewer stack operations. mstore8(0, mload(and(shr(18, input), 0x3F))) mstore8(1, mload(and(shr(12, input), 0x3F))) mstore8(2, mload(and(shr(6, input), 0x3F))) mstore8(3, mload(and(input, 0x3F))) mstore(ptr, mload(0x00)) ptr := add(ptr, 4) // Advance 4 bytes. if iszero(lt(ptr, end)) { break } } mstore(dataEnd, dataEndValue) // Restore the cached value at `dataEnd`. mstore(0x40, add(end, 0x20)) // Allocate the memory. // Equivalent to `o = [0, 2, 1][dataLength % 3]`. let o := div(2, mod(dataLength, 3)) // Offset `ptr` and pad with '='. We can simply write over the end. mstore(sub(ptr, o), shl(240, 0x3d3d)) // Set `o` to zero if there is padding. o := mul(iszero(iszero(noPadding)), o) mstore(sub(ptr, o), 0) // Zeroize the slot after the string. mstore(result, sub(encodedLength, o)) // Store the length. } } } /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// Equivalent to `encode(data, false, false)`. function encode(bytes memory data) internal pure returns (string memory result) { result = encode(data, false, false); } /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// Equivalent to `encode(data, fileSafe, false)`. function encode(bytes memory data, bool fileSafe) internal pure returns (string memory result) { result = encode(data, fileSafe, false); } /// @dev Decodes base64 encoded `data`. /// /// Supports: /// - RFC 4648 (both standard and file-safe mode). /// - RFC 3501 (63: ','). /// /// Does not support: /// - Line breaks. /// /// Note: For performance reasons, /// this function will NOT revert on invalid `data` inputs. /// Outputs for invalid inputs will simply be undefined behaviour. /// It is the user's responsibility to ensure that the `data` /// is a valid base64 encoded string. function decode(string memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { let dataLength := mload(data) if dataLength { let decodedLength := mul(shr(2, dataLength), 3) for {} 1 {} { // If padded. if iszero(and(dataLength, 3)) { let t := xor(mload(add(data, dataLength)), 0x3d3d) // forgefmt: disable-next-item decodedLength := sub( decodedLength, add(iszero(byte(30, t)), iszero(byte(31, t))) ) break } // If non-padded. decodedLength := add(decodedLength, sub(and(dataLength, 3), 1)) break } result := mload(0x40) // Write the length of the bytes. mstore(result, decodedLength) // Skip the first slot, which stores the length. let ptr := add(result, 0x20) let end := add(ptr, decodedLength) // Load the table into the scratch space. // Constants are optimized for smaller bytecode with zero gas overhead. // `m` also doubles as the mask of the upper 6 bits. let m := 0xfc000000fc00686c7074787c8084888c9094989ca0a4a8acb0b4b8bcc0c4c8cc mstore(0x5b, m) mstore(0x3b, 0x04080c1014181c2024282c3034383c4044484c5054585c6064) mstore(0x1a, 0xf8fcf800fcd0d4d8dce0e4e8ecf0f4) for {} 1 {} { // Read 4 bytes. data := add(data, 4) let input := mload(data) // Write 3 bytes. // forgefmt: disable-next-item mstore(ptr, or( and(m, mload(byte(28, input))), shr(6, or( and(m, mload(byte(29, input))), shr(6, or( and(m, mload(byte(30, input))), shr(6, mload(byte(31, input))) )) )) )) ptr := add(ptr, 3) if iszero(lt(ptr, end)) { break } } mstore(0x40, add(end, 0x20)) // Allocate the memory. mstore(end, 0) // Zeroize the slot after the bytes. mstore(0x60, 0) // Restore the zero slot. } } } }
SSTORE2.sol 259 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Read and write to persistent storage at a fraction of the cost.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SSTORE2.sol)
/// @author Saw-mon-and-Natalie (https://github.com/Saw-mon-and-Natalie)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)
/// @author Modified from SSTORE3 (https://github.com/Philogy/sstore3)
library SSTORE2 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The proxy initialization code.
uint256 private constant _CREATE3_PROXY_INITCODE = 0x67363d3d37363d34f03d5260086018f3;
/// @dev Hash of the `_CREATE3_PROXY_INITCODE`.
/// Equivalent to `keccak256(abi.encodePacked(hex"67363d3d37363d34f03d5260086018f3"))`.
bytes32 internal constant CREATE3_PROXY_INITCODE_HASH =
0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Unable to deploy the storage contract.
error DeploymentFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE LOGIC */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Writes `data` into the bytecode of a storage contract and returns its address.
function write(bytes memory data) internal returns (address pointer) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(data) // Let `l` be `n + 1`. +1 as we prefix a STOP opcode.
/**
* ---------------------------------------------------+
* Opcode | Mnemonic | Stack | Memory |
* ---------------------------------------------------|
* 61 l | PUSH2 l | l | |
* 80 | DUP1 | l l | |
* 60 0xa | PUSH1 0xa | 0xa l l | |
* 3D | RETURNDATASIZE | 0 0xa l l | |
* 39 | CODECOPY | l | [0..l): code |
* 3D | RETURNDATASIZE | 0 l | [0..l): code |
* F3 | RETURN | | [0..l): code |
* 00 | STOP | | |
* ---------------------------------------------------+
* @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called.
* Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16.
*/
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
// Deploy a new contract with the generated creation code.
pointer := create(0, add(data, 0x15), add(n, 0xb))
if iszero(pointer) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Writes `data` into the bytecode of a storage contract with `salt`
/// and returns its normal CREATE2 deterministic address.
function writeCounterfactual(bytes memory data, bytes32 salt)
internal
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
// Deploy a new contract with the generated creation code.
pointer := create2(0, add(data, 0x15), add(n, 0xb), salt)
if iszero(pointer) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Writes `data` into the bytecode of a storage contract and returns its address.
/// This uses the so-called "CREATE3" workflow,
/// which means that `pointer` is agnostic to `data, and only depends on `salt`.
function writeDeterministic(bytes memory data, bytes32 salt)
internal
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
mstore(0x00, _CREATE3_PROXY_INITCODE) // Store the `_PROXY_INITCODE`.
let proxy := create2(0, 0x10, 0x10, salt)
if iszero(proxy) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(0x14, proxy) // Store the proxy's address.
// 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
mstore(0x00, 0xd694)
mstore8(0x34, 0x01) // Nonce of the proxy contract (1).
pointer := keccak256(0x1e, 0x17)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))
if iszero(
mul( // The arguments of `mul` are evaluated last to first.
extcodesize(pointer),
call(gas(), proxy, 0, add(data, 0x15), add(n, 0xb), codesize(), 0x00)
)
) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(data, n) // Restore the length of `data`.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ADDRESS CALCULATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the initialization code hash of the storage contract for `data`.
/// Used for mining vanity addresses with create2crunch.
function initCodeHash(bytes memory data) internal pure returns (bytes32 hash) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(data)
// Do a out-of-gas revert if `n + 1` is more than 2 bytes.
returndatacopy(returndatasize(), returndatasize(), gt(n, 0xfffe))
mstore(data, add(0x61000180600a3d393df300, shl(0x40, n)))
hash := keccak256(add(data, 0x15), add(n, 0xb))
mstore(data, n) // Restore the length of `data`.
}
}
/// @dev Equivalent to `predictCounterfactualAddress(data, salt, address(this))`
function predictCounterfactualAddress(bytes memory data, bytes32 salt)
internal
view
returns (address pointer)
{
pointer = predictCounterfactualAddress(data, salt, address(this));
}
/// @dev Returns the CREATE2 address of the storage contract for `data`
/// deployed with `salt` by `deployer`.
/// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
function predictCounterfactualAddress(bytes memory data, bytes32 salt, address deployer)
internal
pure
returns (address predicted)
{
bytes32 hash = initCodeHash(data);
/// @solidity memory-safe-assembly
assembly {
// Compute and store the bytecode hash.
mstore8(0x00, 0xff) // Write the prefix.
mstore(0x35, hash)
mstore(0x01, shl(96, deployer))
mstore(0x15, salt)
predicted := keccak256(0x00, 0x55)
// Restore the part of the free memory pointer that has been overwritten.
mstore(0x35, 0)
}
}
/// @dev Equivalent to `predictDeterministicAddress(salt, address(this))`.
function predictDeterministicAddress(bytes32 salt) internal view returns (address pointer) {
pointer = predictDeterministicAddress(salt, address(this));
}
/// @dev Returns the "CREATE3" deterministic address for `salt` with `deployer`.
function predictDeterministicAddress(bytes32 salt, address deployer)
internal
pure
returns (address pointer)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, deployer) // Store `deployer`.
mstore8(0x0b, 0xff) // Store the prefix.
mstore(0x20, salt) // Store the salt.
mstore(0x40, CREATE3_PROXY_INITCODE_HASH) // Store the bytecode hash.
mstore(0x14, keccak256(0x0b, 0x55)) // Store the proxy's address.
mstore(0x40, m) // Restore the free memory pointer.
// 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
mstore(0x00, 0xd694)
mstore8(0x34, 0x01) // Nonce of the proxy contract (1).
pointer := keccak256(0x1e, 0x17)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* READ LOGIC */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `read(pointer, 0, 2 ** 256 - 1)`.
function read(address pointer) internal view returns (bytes memory data) {
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
let n := and(0xffffffffff, sub(extcodesize(pointer), 0x01))
extcodecopy(pointer, add(data, 0x1f), 0x00, add(n, 0x21))
mstore(data, n) // Store the length.
mstore(0x40, add(n, add(data, 0x40))) // Allocate memory.
}
}
/// @dev Equivalent to `read(pointer, start, 2 ** 256 - 1)`.
function read(address pointer, uint256 start) internal view returns (bytes memory data) {
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
let n := and(0xffffffffff, sub(extcodesize(pointer), 0x01))
let l := sub(n, and(0xffffff, mul(lt(start, n), start)))
extcodecopy(pointer, add(data, 0x1f), start, add(l, 0x21))
mstore(data, mul(sub(n, start), lt(start, n))) // Store the length.
mstore(0x40, add(data, add(0x40, mload(data)))) // Allocate memory.
}
}
/// @dev Returns a slice of the data on `pointer` from `start` to `end`.
/// `start` and `end` will be clamped to the range `[0, args.length]`.
/// The `pointer` MUST be deployed via the SSTORE2 write functions.
/// Otherwise, the behavior is undefined.
/// Out-of-gas reverts if `pointer` does not have any code.
function read(address pointer, uint256 start, uint256 end)
internal
view
returns (bytes memory data)
{
/// @solidity memory-safe-assembly
assembly {
data := mload(0x40)
if iszero(lt(end, 0xffff)) { end := 0xffff }
let d := mul(sub(end, start), lt(start, end))
extcodecopy(pointer, add(data, 0x1f), start, add(d, 0x01))
if iszero(and(0xff, mload(add(data, d)))) {
let n := sub(extcodesize(pointer), 0x01)
returndatacopy(returndatasize(), returndatasize(), shr(40, n))
d := mul(gt(n, start), sub(d, mul(gt(end, n), sub(end, n))))
}
mstore(data, d) // Store the length.
mstore(add(add(data, 0x20), d), 0) // Zeroize the slot after the bytes.
mstore(0x40, add(add(data, 0x40), d)) // Allocate memory.
}
}
}
Ownable.sol 278 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The caller is not authorized to call the function.
error Unauthorized();
/// @dev The `newOwner` cannot be the zero address.
error NewOwnerIsZeroAddress();
/// @dev The `pendingOwner` does not have a valid handover request.
error NoHandoverRequest();
/// @dev Cannot double-initialize.
error AlreadyInitialized();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ownership is transferred from `oldOwner` to `newOwner`.
/// This event is intentionally kept the same as OpenZeppelin's Ownable to be
/// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
/// despite it not being as lightweight as a single argument event.
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
/// @dev An ownership handover to `pendingOwner` has been requested.
event OwnershipHandoverRequested(address indexed pendingOwner);
/// @dev The ownership handover to `pendingOwner` has been canceled.
event OwnershipHandoverCanceled(address indexed pendingOwner);
/// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
/// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
/// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The owner slot is given by:
/// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
/// It is intentionally chosen to be a high value
/// to avoid collision with lower slots.
/// The choice of manual storage layout is to enable compatibility
/// with both regular and upgradeable contracts.
bytes32 internal constant _OWNER_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
/// The ownership handover slot of `newOwner` is given by:
/// ```
/// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
/// let handoverSlot := keccak256(0x00, 0x20)
/// ```
/// It stores the expiry timestamp of the two-step ownership handover.
uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
/// @dev Initializes the owner directly without authorization guard.
/// This function must be called upon initialization,
/// regardless of whether the contract is upgradeable or not.
/// This is to enable generalization to both regular and upgradeable contracts,
/// and to save gas in case the initial owner is not the caller.
/// For performance reasons, this function will not check if there
/// is an existing owner.
function _initializeOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
if sload(ownerSlot) {
mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
revert(0x1c, 0x04)
}
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
} else {
/// @solidity memory-safe-assembly
assembly {
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(_OWNER_SLOT, newOwner)
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
}
}
/// @dev Sets the owner directly without authorization guard.
function _setOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
}
} else {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, newOwner)
}
}
}
/// @dev Throws if the sender is not the owner.
function _checkOwner() internal view virtual {
/// @solidity memory-safe-assembly
assembly {
// If the caller is not the stored owner, revert.
if iszero(eq(caller(), sload(_OWNER_SLOT))) {
mstore(0x00, 0x82b42900) // `Unauthorized()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Returns how long a two-step ownership handover is valid for in seconds.
/// Override to return a different value if needed.
/// Made internal to conserve bytecode. Wrap it in a public function if needed.
function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
return 48 * 3600;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC UPDATE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Allows the owner to transfer the ownership to `newOwner`.
function transferOwnership(address newOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
if iszero(shl(96, newOwner)) {
mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
revert(0x1c, 0x04)
}
}
_setOwner(newOwner);
}
/// @dev Allows the owner to renounce their ownership.
function renounceOwnership() public payable virtual onlyOwner {
_setOwner(address(0));
}
/// @dev Request a two-step ownership handover to the caller.
/// The request will automatically expire in 48 hours (172800 seconds) by default.
function requestOwnershipHandover() public payable virtual {
unchecked {
uint256 expires = block.timestamp + _ownershipHandoverValidFor();
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to `expires`.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), expires)
// Emit the {OwnershipHandoverRequested} event.
log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
}
}
}
/// @dev Cancels the two-step ownership handover to the caller, if any.
function cancelOwnershipHandover() public payable virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), 0)
// Emit the {OwnershipHandoverCanceled} event.
log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
}
}
/// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
/// Reverts if there is no existing ownership handover requested by `pendingOwner`.
function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
let handoverSlot := keccak256(0x0c, 0x20)
// If the handover does not exist, or has expired.
if gt(timestamp(), sload(handoverSlot)) {
mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
revert(0x1c, 0x04)
}
// Set the handover slot to 0.
sstore(handoverSlot, 0)
}
_setOwner(pendingOwner);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC READ FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the owner of the contract.
function owner() public view virtual returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_OWNER_SLOT)
}
}
/// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
function ownershipHandoverExpiresAt(address pendingOwner)
public
view
virtual
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
// Compute the handover slot.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
// Load the handover slot.
result := sload(keccak256(0x0c, 0x20))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MODIFIERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Marks a function as only callable by the owner.
modifier onlyOwner() virtual {
_checkOwner();
_;
}
}
LibBytes.sol 884 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Library for byte related operations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBytes.sol)
library LibBytes {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Goated bytes storage struct that totally MOGs, no cap, fr.
/// Uses less gas and bytecode than Solidity's native bytes storage. It's meta af.
/// Packs length with the first 31 bytes if <255 bytes, so it’s mad tight.
struct BytesStorage {
bytes32 _spacer;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The constant returned when the `search` is not found in the bytes.
uint256 internal constant NOT_FOUND = type(uint256).max;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* BYTE STORAGE OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Sets the value of the bytes storage `$` to `s`.
function set(BytesStorage storage $, bytes memory s) internal {
/// @solidity memory-safe-assembly
assembly {
let n := mload(s)
let packed := or(0xff, shl(8, n))
for { let i := 0 } 1 {} {
if iszero(gt(n, 0xfe)) {
i := 0x1f
packed := or(n, shl(8, mload(add(s, i))))
if iszero(gt(n, i)) { break }
}
let o := add(s, 0x20)
mstore(0x00, $.slot)
for { let p := keccak256(0x00, 0x20) } 1 {} {
sstore(add(p, shr(5, i)), mload(add(o, i)))
i := add(i, 0x20)
if iszero(lt(i, n)) { break }
}
break
}
sstore($.slot, packed)
}
}
/// @dev Sets the value of the bytes storage `$` to `s`.
function setCalldata(BytesStorage storage $, bytes calldata s) internal {
/// @solidity memory-safe-assembly
assembly {
let packed := or(0xff, shl(8, s.length))
for { let i := 0 } 1 {} {
if iszero(gt(s.length, 0xfe)) {
i := 0x1f
packed := or(s.length, shl(8, shr(8, calldataload(s.offset))))
if iszero(gt(s.length, i)) { break }
}
mstore(0x00, $.slot)
for { let p := keccak256(0x00, 0x20) } 1 {} {
sstore(add(p, shr(5, i)), calldataload(add(s.offset, i)))
i := add(i, 0x20)
if iszero(lt(i, s.length)) { break }
}
break
}
sstore($.slot, packed)
}
}
/// @dev Sets the value of the bytes storage `$` to the empty bytes.
function clear(BytesStorage storage $) internal {
delete $._spacer;
}
/// @dev Returns whether the value stored is `$` is the empty bytes "".
function isEmpty(BytesStorage storage $) internal view returns (bool) {
return uint256($._spacer) & 0xff == uint256(0);
}
/// @dev Returns the length of the value stored in `$`.
function length(BytesStorage storage $) internal view returns (uint256 result) {
result = uint256($._spacer);
/// @solidity memory-safe-assembly
assembly {
let n := and(0xff, result)
result := or(mul(shr(8, result), eq(0xff, n)), mul(n, iszero(eq(0xff, n))))
}
}
/// @dev Returns the value stored in `$`.
function get(BytesStorage storage $) internal view returns (bytes memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let o := add(result, 0x20)
let packed := sload($.slot)
let n := shr(8, packed)
for { let i := 0 } 1 {} {
if iszero(eq(or(packed, 0xff), packed)) {
mstore(o, packed)
n := and(0xff, packed)
i := 0x1f
if iszero(gt(n, i)) { break }
}
mstore(0x00, $.slot)
for { let p := keccak256(0x00, 0x20) } 1 {} {
mstore(add(o, i), sload(add(p, shr(5, i))))
i := add(i, 0x20)
if iszero(lt(i, n)) { break }
}
break
}
mstore(result, n) // Store the length of the memory.
mstore(add(o, n), 0) // Zeroize the slot after the bytes.
mstore(0x40, add(add(o, n), 0x20)) // Allocate memory.
}
}
/// @dev Returns the uint8 at index `i`. If out-of-bounds, returns 0.
function uint8At(BytesStorage storage $, uint256 i) internal view returns (uint8 result) {
/// @solidity memory-safe-assembly
assembly {
for { let packed := sload($.slot) } 1 {} {
if iszero(eq(or(packed, 0xff), packed)) {
if iszero(gt(i, 0x1e)) {
result := byte(i, packed)
break
}
if iszero(gt(i, and(0xff, packed))) {
mstore(0x00, $.slot)
let j := sub(i, 0x1f)
result := byte(and(j, 0x1f), sload(add(keccak256(0x00, 0x20), shr(5, j))))
}
break
}
if iszero(gt(i, shr(8, packed))) {
mstore(0x00, $.slot)
result := byte(and(i, 0x1f), sload(add(keccak256(0x00, 0x20), shr(5, i))))
}
break
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* BYTES OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `subject` all occurrences of `needle` replaced with `replacement`.
function replace(bytes memory subject, bytes memory needle, bytes memory replacement)
internal
pure
returns (bytes memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let needleLen := mload(needle)
let replacementLen := mload(replacement)
let d := sub(result, subject) // Memory difference.
let i := add(subject, 0x20) // Subject bytes pointer.
mstore(0x00, add(i, mload(subject))) // End of subject.
if iszero(gt(needleLen, mload(subject))) {
let subjectSearchEnd := add(sub(mload(0x00), needleLen), 1)
let h := 0 // The hash of `needle`.
if iszero(lt(needleLen, 0x20)) {
h := keccak256(add(needle, 0x20), needleLen)
}
let s := mload(add(needle, 0x20))
for { let m := shl(3, sub(0x20, and(needleLen, 0x1f))) } 1 {} {
let t := mload(i)
// Whether the first `needleLen % 32` bytes of `subject` and `needle` matches.
if iszero(shr(m, xor(t, s))) {
if h {
if iszero(eq(keccak256(i, needleLen), h)) {
mstore(add(i, d), t)
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
// Copy the `replacement` one word at a time.
for { let j := 0 } 1 {} {
mstore(add(add(i, d), j), mload(add(add(replacement, 0x20), j)))
j := add(j, 0x20)
if iszero(lt(j, replacementLen)) { break }
}
d := sub(add(d, replacementLen), needleLen)
if needleLen {
i := add(i, needleLen)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
mstore(add(i, d), t)
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
}
}
let end := mload(0x00)
let n := add(sub(d, add(result, 0x20)), end)
// Copy the rest of the bytes one word at a time.
for {} lt(i, end) { i := add(i, 0x20) } { mstore(add(i, d), mload(i)) }
let o := add(i, d)
mstore(o, 0) // Zeroize the slot after the bytes.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(bytes memory subject, bytes memory needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
result := not(0) // Initialize to `NOT_FOUND`.
for { let subjectLen := mload(subject) } 1 {} {
if iszero(mload(needle)) {
result := from
if iszero(gt(from, subjectLen)) { break }
result := subjectLen
break
}
let needleLen := mload(needle)
let subjectStart := add(subject, 0x20)
subject := add(subjectStart, from)
let end := add(sub(add(subjectStart, subjectLen), needleLen), 1)
let m := shl(3, sub(0x20, and(needleLen, 0x1f)))
let s := mload(add(needle, 0x20))
if iszero(and(lt(subject, end), lt(from, subjectLen))) { break }
if iszero(lt(needleLen, 0x20)) {
for { let h := keccak256(add(needle, 0x20), needleLen) } 1 {} {
if iszero(shr(m, xor(mload(subject), s))) {
if eq(keccak256(subject, needleLen), h) {
result := sub(subject, subjectStart)
break
}
}
subject := add(subject, 1)
if iszero(lt(subject, end)) { break }
}
break
}
for {} 1 {} {
if iszero(shr(m, xor(mload(subject), s))) {
result := sub(subject, subjectStart)
break
}
subject := add(subject, 1)
if iszero(lt(subject, end)) { break }
}
break
}
}
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right, starting from `from`. Optimized for byte needles.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOfByte(bytes memory subject, bytes1 needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
result := not(0) // Initialize to `NOT_FOUND`.
if gt(mload(subject), from) {
let start := add(subject, 0x20)
let end := add(start, mload(subject))
let m := div(not(0), 255) // `0x0101 ... `.
let h := mul(byte(0, needle), m) // Replicating needle mask.
m := not(shl(7, m)) // `0x7f7f ... `.
for { let i := add(start, from) } 1 {} {
let c := xor(mload(i), h) // Load 32-byte chunk and xor with mask.
c := not(or(or(add(and(c, m), m), c), m)) // Each needle byte will be `0x80`.
if c {
c := and(not(shr(shl(3, sub(end, i)), not(0))), c) // Truncate bytes past the end.
if c {
let r := shl(7, lt(0x8421084210842108cc6318c6db6d54be, c)) // Save bytecode.
r := or(shl(6, lt(0xffffffffffffffff, shr(r, c))), r)
// forgefmt: disable-next-item
result := add(sub(i, start), shr(3, xor(byte(and(0x1f, shr(byte(24,
mul(0x02040810204081, shr(r, c))), 0x8421084210842108cc6318c6db6d54be)),
0xc0c8c8d0c8e8d0d8c8e8e0e8d0d8e0f0c8d0e8d0e0e0d8f0d0d0e0d8f8f8f8f8), r)))
break
}
}
i := add(i, 0x20)
if iszero(lt(i, end)) { break }
}
}
}
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right. Optimized for byte needles.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOfByte(bytes memory subject, bytes1 needle)
internal
pure
returns (uint256 result)
{
return indexOfByte(subject, needle, 0);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(bytes memory subject, bytes memory needle) internal pure returns (uint256) {
return indexOf(subject, needle, 0);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from right to left, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(bytes memory subject, bytes memory needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
for {} 1 {} {
result := not(0) // Initialize to `NOT_FOUND`.
let needleLen := mload(needle)
if gt(needleLen, mload(subject)) { break }
let w := result
let fromMax := sub(mload(subject), needleLen)
if iszero(gt(fromMax, from)) { from := fromMax }
let end := add(add(subject, 0x20), w)
subject := add(add(subject, 0x20), from)
if iszero(gt(subject, end)) { break }
// As this function is not too often used,
// we shall simply use keccak256 for smaller bytecode size.
for { let h := keccak256(add(needle, 0x20), needleLen) } 1 {} {
if eq(keccak256(subject, needleLen), h) {
result := sub(subject, add(end, 1))
break
}
subject := add(subject, w) // `sub(subject, 1)`.
if iszero(gt(subject, end)) { break }
}
break
}
}
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from right to left.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(bytes memory subject, bytes memory needle)
internal
pure
returns (uint256)
{
return lastIndexOf(subject, needle, type(uint256).max);
}
/// @dev Returns true if `needle` is found in `subject`, false otherwise.
function contains(bytes memory subject, bytes memory needle) internal pure returns (bool) {
return indexOf(subject, needle) != NOT_FOUND;
}
/// @dev Returns whether `subject` starts with `needle`.
function startsWith(bytes memory subject, bytes memory needle)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(needle)
// Just using keccak256 directly is actually cheaper.
let t := eq(keccak256(add(subject, 0x20), n), keccak256(add(needle, 0x20), n))
result := lt(gt(n, mload(subject)), t)
}
}
/// @dev Returns whether `subject` ends with `needle`.
function endsWith(bytes memory subject, bytes memory needle)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(needle)
let notInRange := gt(n, mload(subject))
// `subject + 0x20 + max(subject.length - needle.length, 0)`.
let t := add(add(subject, 0x20), mul(iszero(notInRange), sub(mload(subject), n)))
// Just using keccak256 directly is actually cheaper.
result := gt(eq(keccak256(t, n), keccak256(add(needle, 0x20), n)), notInRange)
}
}
/// @dev Returns `subject` repeated `times`.
function repeat(bytes memory subject, uint256 times)
internal
pure
returns (bytes memory result)
{
/// @solidity memory-safe-assembly
assembly {
let l := mload(subject) // Subject length.
if iszero(or(iszero(times), iszero(l))) {
result := mload(0x40)
subject := add(subject, 0x20)
let o := add(result, 0x20)
for {} 1 {} {
// Copy the `subject` one word at a time.
for { let j := 0 } 1 {} {
mstore(add(o, j), mload(add(subject, j)))
j := add(j, 0x20)
if iszero(lt(j, l)) { break }
}
o := add(o, l)
times := sub(times, 1)
if iszero(times) { break }
}
mstore(o, 0) // Zeroize the slot after the bytes.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
}
}
}
/// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function slice(bytes memory subject, uint256 start, uint256 end)
internal
pure
returns (bytes memory result)
{
/// @solidity memory-safe-assembly
assembly {
let l := mload(subject) // Subject length.
if iszero(gt(l, end)) { end := l }
if iszero(gt(l, start)) { start := l }
if lt(start, end) {
result := mload(0x40)
let n := sub(end, start)
let i := add(subject, start)
let w := not(0x1f)
// Copy the `subject` one word at a time, backwards.
for { let j := and(add(n, 0x1f), w) } 1 {} {
mstore(add(result, j), mload(add(i, j)))
j := add(j, w) // `sub(j, 0x20)`.
if iszero(j) { break }
}
let o := add(add(result, 0x20), n)
mstore(o, 0) // Zeroize the slot after the bytes.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, n) // Store the length.
}
}
}
/// @dev Returns a copy of `subject` sliced from `start` to the end of the bytes.
/// `start` is a byte offset.
function slice(bytes memory subject, uint256 start)
internal
pure
returns (bytes memory result)
{
result = slice(subject, start, type(uint256).max);
}
/// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets. Faster than Solidity's native slicing.
function sliceCalldata(bytes calldata subject, uint256 start, uint256 end)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
end := xor(end, mul(xor(end, subject.length), lt(subject.length, end)))
start := xor(start, mul(xor(start, subject.length), lt(subject.length, start)))
result.offset := add(subject.offset, start)
result.length := mul(lt(start, end), sub(end, start))
}
}
/// @dev Returns a copy of `subject` sliced from `start` to the end of the bytes.
/// `start` is a byte offset. Faster than Solidity's native slicing.
function sliceCalldata(bytes calldata subject, uint256 start)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
start := xor(start, mul(xor(start, subject.length), lt(subject.length, start)))
result.offset := add(subject.offset, start)
result.length := mul(lt(start, subject.length), sub(subject.length, start))
}
}
/// @dev Reduces the size of `subject` to `n`.
/// If `n` is greater than the size of `subject`, this will be a no-op.
function truncate(bytes memory subject, uint256 n) internal pure returns (bytes memory result) {
/// @solidity memory-safe-assembly
assembly {
result := subject
mstore(mul(lt(n, mload(result)), result), n)
}
}
/// @dev Returns a copy of `subject`, with the length reduced to `n`.
/// If `n` is greater than the size of `subject`, this will be a no-op.
function truncatedCalldata(bytes calldata subject, uint256 n)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
result.offset := subject.offset
result.length := xor(n, mul(xor(n, subject.length), lt(subject.length, n)))
}
}
/// @dev Returns all the indices of `needle` in `subject`.
/// The indices are byte offsets.
function indicesOf(bytes memory subject, bytes memory needle)
internal
pure
returns (uint256[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
let searchLen := mload(needle)
if iszero(gt(searchLen, mload(subject))) {
result := mload(0x40)
let i := add(subject, 0x20)
let o := add(result, 0x20)
let subjectSearchEnd := add(sub(add(i, mload(subject)), searchLen), 1)
let h := 0 // The hash of `needle`.
if iszero(lt(searchLen, 0x20)) {
h := keccak256(add(needle, 0x20), searchLen)
}
let s := mload(add(needle, 0x20))
for { let m := shl(3, sub(0x20, and(searchLen, 0x1f))) } 1 {} {
let t := mload(i)
// Whether the first `searchLen % 32` bytes of `subject` and `needle` matches.
if iszero(shr(m, xor(t, s))) {
if h {
if iszero(eq(keccak256(i, searchLen), h)) {
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
mstore(o, sub(i, add(subject, 0x20))) // Append to `result`.
o := add(o, 0x20)
i := add(i, searchLen) // Advance `i` by `searchLen`.
if searchLen {
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
}
mstore(result, shr(5, sub(o, add(result, 0x20)))) // Store the length of `result`.
// Allocate memory for result.
// We allocate one more word, so this array can be recycled for {split}.
mstore(0x40, add(o, 0x20))
}
}
}
/// @dev Returns an arrays of bytess based on the `delimiter` inside of the `subject` bytes.
function split(bytes memory subject, bytes memory delimiter)
internal
pure
returns (bytes[] memory result)
{
uint256[] memory indices = indicesOf(subject, delimiter);
/// @solidity memory-safe-assembly
assembly {
let w := not(0x1f)
let indexPtr := add(indices, 0x20)
let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1)))
mstore(add(indicesEnd, w), mload(subject))
mstore(indices, add(mload(indices), 1))
for { let prevIndex := 0 } 1 {} {
let index := mload(indexPtr)
mstore(indexPtr, 0x60)
if iszero(eq(index, prevIndex)) {
let element := mload(0x40)
let l := sub(index, prevIndex)
mstore(element, l) // Store the length of the element.
// Copy the `subject` one word at a time, backwards.
for { let o := and(add(l, 0x1f), w) } 1 {} {
mstore(add(element, o), mload(add(add(subject, prevIndex), o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
mstore(add(add(element, 0x20), l), 0) // Zeroize the slot after the bytes.
// Allocate memory for the length and the bytes, rounded up to a multiple of 32.
mstore(0x40, add(element, and(add(l, 0x3f), w)))
mstore(indexPtr, element) // Store the `element` into the array.
}
prevIndex := add(index, mload(delimiter))
indexPtr := add(indexPtr, 0x20)
if iszero(lt(indexPtr, indicesEnd)) { break }
}
result := indices
if iszero(mload(delimiter)) {
result := add(indices, 0x20)
mstore(result, sub(mload(indices), 2))
}
}
}
/// @dev Returns a concatenated bytes of `a` and `b`.
/// Cheaper than `bytes.concat()` and does not de-align the free memory pointer.
function concat(bytes memory a, bytes memory b) internal pure returns (bytes memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let w := not(0x1f)
let aLen := mload(a)
// Copy `a` one word at a time, backwards.
for { let o := and(add(aLen, 0x20), w) } 1 {} {
mstore(add(result, o), mload(add(a, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
let bLen := mload(b)
let output := add(result, aLen)
// Copy `b` one word at a time, backwards.
for { let o := and(add(bLen, 0x20), w) } 1 {} {
mstore(add(output, o), mload(add(b, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
let totalLen := add(aLen, bLen)
let last := add(add(result, 0x20), totalLen)
mstore(last, 0) // Zeroize the slot after the bytes.
mstore(result, totalLen) // Store the length.
mstore(0x40, add(last, 0x20)) // Allocate memory.
}
}
/// @dev Returns whether `a` equals `b`.
function eq(bytes memory a, bytes memory b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b)))
}
}
/// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small bytes.
function eqs(bytes memory a, bytes32 b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
// These should be evaluated on compile time, as far as possible.
let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`.
let x := not(or(m, or(b, add(m, and(b, m)))))
let r := shl(7, iszero(iszero(shr(128, x))))
r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x))))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))),
xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20)))))
}
}
/// @dev Returns 0 if `a == b`, -1 if `a < b`, +1 if `a > b`.
/// If `a` == b[:a.length]`, and `a.length < b.length`, returns -1.
function cmp(bytes memory a, bytes memory b) internal pure returns (int256 result) {
/// @solidity memory-safe-assembly
assembly {
let aLen := mload(a)
let bLen := mload(b)
let n := and(xor(aLen, mul(xor(aLen, bLen), lt(bLen, aLen))), not(0x1f))
if n {
for { let i := 0x20 } 1 {} {
let x := mload(add(a, i))
let y := mload(add(b, i))
if iszero(or(xor(x, y), eq(i, n))) {
i := add(i, 0x20)
continue
}
result := sub(gt(x, y), lt(x, y))
break
}
}
// forgefmt: disable-next-item
if iszero(result) {
let l := 0x201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201
let x := and(mload(add(add(a, 0x20), n)), shl(shl(3, byte(sub(aLen, n), l)), not(0)))
let y := and(mload(add(add(b, 0x20), n)), shl(shl(3, byte(sub(bLen, n), l)), not(0)))
result := sub(gt(x, y), lt(x, y))
if iszero(result) { result := sub(gt(aLen, bLen), lt(aLen, bLen)) }
}
}
}
/// @dev Directly returns `a` without copying.
function directReturn(bytes memory a) internal pure {
/// @solidity memory-safe-assembly
assembly {
// Assumes that the bytes does not start from the scratch space.
let retStart := sub(a, 0x20)
let retUnpaddedSize := add(mload(a), 0x40)
// Right pad with zeroes. Just in case the bytes is produced
// by a method that doesn't zero right pad.
mstore(add(retStart, retUnpaddedSize), 0)
mstore(retStart, 0x20) // Store the return offset.
// End the transaction, returning the bytes.
return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize)))
}
}
/// @dev Directly returns `a` with minimal copying.
function directReturn(bytes[] memory a) internal pure {
/// @solidity memory-safe-assembly
assembly {
let n := mload(a) // `a.length`.
let o := add(a, 0x20) // Start of elements in `a`.
let u := a // Highest memory slot.
let w := not(0x1f)
for { let i := 0 } iszero(eq(i, n)) { i := add(i, 1) } {
let c := add(o, shl(5, i)) // Location of pointer to `a[i]`.
let s := mload(c) // `a[i]`.
let l := mload(s) // `a[i].length`.
let r := and(l, 0x1f) // `a[i].length % 32`.
let z := add(0x20, and(l, w)) // Offset of last word in `a[i]` from `s`.
// If `s` comes before `o`, or `s` is not zero right padded.
if iszero(lt(lt(s, o), or(iszero(r), iszero(shl(shl(3, r), mload(add(s, z))))))) {
let m := mload(0x40)
mstore(m, l) // Copy `a[i].length`.
for {} 1 {} {
mstore(add(m, z), mload(add(s, z))) // Copy `a[i]`, backwards.
z := add(z, w) // `sub(z, 0x20)`.
if iszero(z) { break }
}
let e := add(add(m, 0x20), l)
mstore(e, 0) // Zeroize the slot after the copied bytes.
mstore(0x40, add(e, 0x20)) // Allocate memory.
s := m
}
mstore(c, sub(s, o)) // Convert to calldata offset.
let t := add(l, add(s, 0x20))
if iszero(lt(t, u)) { u := t }
}
let retStart := add(a, w) // Assumes `a` doesn't start from scratch space.
mstore(retStart, 0x20) // Store the return offset.
return(retStart, add(0x40, sub(u, retStart))) // End the transaction.
}
}
/// @dev Returns the word at `offset`, without any bounds checks.
function load(bytes memory a, uint256 offset) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), offset))
}
}
/// @dev Returns the word at `offset`, without any bounds checks.
function loadCalldata(bytes calldata a, uint256 offset) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := calldataload(add(a.offset, offset))
}
}
/// @dev Returns a slice representing a static struct in the calldata. Performs bounds checks.
function staticStructInCalldata(bytes calldata a, uint256 offset)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
let l := sub(a.length, 0x20)
result.offset := add(a.offset, offset)
result.length := sub(a.length, offset)
if or(shr(64, or(l, a.offset)), gt(offset, l)) { revert(l, 0x00) }
}
}
/// @dev Returns a slice representing a dynamic struct in the calldata. Performs bounds checks.
function dynamicStructInCalldata(bytes calldata a, uint256 offset)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
let l := sub(a.length, 0x20)
let s := calldataload(add(a.offset, offset)) // Relative offset of `result` from `a.offset`.
result.offset := add(a.offset, s)
result.length := sub(a.length, s)
if or(shr(64, or(s, or(l, a.offset))), gt(offset, l)) { revert(l, 0x00) }
}
}
/// @dev Returns bytes in calldata. Performs bounds checks.
function bytesInCalldata(bytes calldata a, uint256 offset)
internal
pure
returns (bytes calldata result)
{
/// @solidity memory-safe-assembly
assembly {
let l := sub(a.length, 0x20)
let s := calldataload(add(a.offset, offset)) // Relative offset of `result` from `a.offset`.
result.offset := add(add(a.offset, s), 0x20)
result.length := calldataload(add(a.offset, s))
// forgefmt: disable-next-item
if or(shr(64, or(result.length, or(s, or(l, a.offset)))),
or(gt(add(s, result.length), l), gt(offset, l))) { revert(l, 0x00) }
}
}
/// @dev Checks if `x` is in `a`. Assumes `a` has been checked.
function checkInCalldata(bytes calldata x, bytes calldata a) internal pure {
/// @solidity memory-safe-assembly
assembly {
if or(
or(lt(x.offset, a.offset), gt(add(x.offset, x.length), add(a.length, a.offset))),
shr(64, or(x.length, x.offset))
) { revert(0x00, 0x00) }
}
}
/// @dev Checks if `x` is in `a`. Assumes `a` has been checked.
function checkInCalldata(bytes[] calldata x, bytes calldata a) internal pure {
/// @solidity memory-safe-assembly
assembly {
let e := sub(add(a.length, a.offset), 0x20)
if or(lt(x.offset, a.offset), shr(64, x.offset)) { revert(0x00, 0x00) }
for { let i := 0 } iszero(eq(x.length, i)) { i := add(i, 1) } {
let o := calldataload(add(x.offset, shl(5, i)))
let t := add(o, x.offset)
let l := calldataload(t)
if or(shr(64, or(l, o)), gt(add(t, l), e)) { revert(0x00, 0x00) }
}
}
}
/// @dev Returns empty calldata bytes. For silencing the compiler.
function emptyCalldata() internal pure returns (bytes calldata result) {
/// @solidity memory-safe-assembly
assembly {
result.length := 0
}
}
/// @dev Returns the most significant 20 bytes as an address.
function msbToAddress(bytes32 x) internal pure returns (address) {
return address(bytes20(x));
}
/// @dev Returns the least significant 20 bytes as an address.
function lsbToAddress(bytes32 x) internal pure returns (address) {
return address(uint160(uint256(x)));
}
}
Read Contract
SCOREBOARD_TOKEN 0x313c9846 → uint256
SCORE_TYPEHASH 0x944303a8 → bytes32
cities 0x38525d85 → string, uint8, uint8, uint8, uint8, uint8
cityCount 0x5cda2c5e → uint8
coreCompressed 0x210dfeb1 → bool
dataCompressed 0x50073468 → bool
eip712Domain 0x84b0196e → bytes1, string, string, uint256, address, bytes32, uint256[]
getTopScores 0xee5c4e5d → tuple[5]
gunzipPointer 0x39451251 → address
highScores 0xb378ac40 → uint256
imageRenderer 0xc550ca5d → address
landmarkCount 0x90f5dd53 → uint8
landmarks 0xd27b0afc → string
nftContract 0xd56d229d → address
owner 0x8da5cb5b → address
ownershipHandoverExpiresAt 0xfee81cf4 → uint256
scoreAPI 0x6fb9ec5d → string
scoreEnabled 0x3ac0800b → bool
scoreHolders 0xcd8686a9 → address
signer 0x238ac933 → address
skinCompressed 0x30f84818 → bool
stateCount 0x518108d6 → uint8
states 0xd6e58ca4 → string
tokenConfigs 0xc01bd0e9 → bytes32
tokenURI 0xc87b56dd → string
topScores 0x5112711a → uint16, uint48, address
truckCount 0x1676ac72 → uint8
trucks 0x162a863a → string
usedNonces 0xfeb61724 → bool
Write Contract 29 functions
These functions modify contract state and require a wallet transaction to execute.
cancelOwnershipHandover 0x54d1f13d
No parameters
completeOwnershipHandover 0xf04e283e
address pendingOwner
renounceOwnership 0x715018a6
No parameters
requestOwnershipHandover 0x25692962
No parameters
resetCoreChunks 0xd972a9af
No parameters
resetDataChunks 0x388dd691
No parameters
resetSkinChunks 0x2ebc4a11
No parameters
setCities 0xc2fa7c85
string[] names
bytes[] packed
setCoreCompressed 0x33fcbca7
bool compressed
setDataCompressed 0x21ceb8d5
bool compressed
setGunzip 0xbdf39f6f
bytes data
setImageRenderer 0x8165fd8b
address renderer
setLandmarks 0x8360b35e
string[] names
setNftContract 0x52f5ad77
address nft_
setScoreAPI 0xecebf3d8
string url
setScoreEnabled 0x3939726e
bool enabled
setSigner 0x6c19e783
address newSigner
setSkinCompressed 0x89d8aeca
bool compressed
setStates 0x870d3ca1
string[] names
setTokenConfigs 0xbf43db8b
uint256[] tokenIds
bytes32[] configs
setTrucks 0xb94281f4
string[] names
storeCoreChunk 0x426c7453
bytes data
storeCoreChunks 0xd846782b
bytes[] chunks
storeDataChunk 0x99b18394
bytes data
storeDataChunks 0xa764fc77
bytes[] chunks
storeSkinChunk 0x9d9af4b4
bytes data
storeSkinChunks 0x6b971ec9
bytes[] chunks
submitScore 0x600eb4d0
uint256 tokenId
uint256 score
string weather
bytes32 nonce
uint256 deadline
bytes signature
transferOwnership 0xf2fde38b
address newOwner
Recent Transactions
No transactions found for this address