Skip to content

Instantly share code, notes, and snippets.

@MASDXI
MASDXI / README.md
Created August 7, 2025 06:46
You should known your app well before write to evm storage

Traditional loyalty program

Customer starts with 0 points

  1. Customer earns 500 points from purchases
    points[customer] = 500; // 20,000 gas (cold storage)
  2. Customer spends all 500 points on rewards
    points[customer] = 0; // 5,000 gas - 4,800 refund = net 200 gas
  3. Customer earns 300 more points
    points[customer] = 300; // 20,000 gas (cold storage again)
  4. Customer spends all 300 points
@MASDXI
MASDXI / README.md
Created August 5, 2025 04:42
CAMARA BlockchainPublicAddress
@MASDXI
MASDXI / ReSET.md
Last active June 4, 2025 06:51
Loyalty Point

It's call Reverse Side Earning Touchpoint (ReSET) What it is: Imagine earning loyalty points from the supplier of an ingredient, not just the place where you bought the finished dish.

How it works (The Betagro Example):

When you enjoy a bowl of roasted red pork noodle at a local restaurant, you'd typically expect to earn loyalty points from that restaurant. With ReSET, you'd actually get Betagro points instead. Why? Because Betagro is the company that supplied the delicious, high-quality S-Pure pork used in your noodles, and they're the ones sponsoring these special loyalty points. You collect these Betagro points and can then use them directly at any Betagro shop for discounts or coupons on their products.

@MASDXI
MASDXI / xor128.sol
Last active December 10, 2024 09:16
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @title Sorted List Library
/// @dev stores two 128-bit pointers `next` and `previous` in a single 256-bit storage slot to reduce storage accesses costs.
/// @author sirawt (@MASDXI)
/// @notice This library is still under development and is not suitable for production.
/// It requires fuzz testing to ensure that the storage slot usage is diversified and avoids collisions.
library xort128 {
@MASDXI
MASDXI / draft-IERC7818.sol
Last active December 12, 2024 08:27
ERC-7818 for ERC1155 and ERC721
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0 <0.9.0;
/**
* @title ERC-7818: Expirable ERC1155 or ERC721
* @author sirawt (@MASDXI), ADISAKBOONMARK (@ADISAKBOONMARK)
* @dev Interface for ERC1155 or ERC721 tokens with expiration functionality.
* @notice for {ERC-721} please see {ERC-5007} https://eips.ethereum.org/EIPS/eip-5007
*/
@MASDXI
MASDXI / TestCompress.sol
Last active October 7, 2024 01:57
Utilizing single uint256 for four uint64
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Utilizing single uint256 for four uint64
/// @author sirawt (@MASDXI)
library Compressed {
function pack(uint64 arg0, uint64 arg1, uint64 arg2, uint64 arg3) internal pure returns (uint256 result) {
assembly {
result := or(or(shl(192, arg3), shl(128, arg2)), or(shl(64, arg1), arg0))
@MASDXI
MASDXI / Stateful.sol
Last active August 14, 2024 03:20
Stateful pre-compiled contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title Example Simple Storage with Stateful Precompiled Contract.
/// @author https://github.com/MASDXI
interface ISimpleStorageStateful {
function get() external view returns (uint256);
function set(uint256) external;
}
@MASDXI
MASDXI / LoopPerformance.sol
Last active August 23, 2024 15:37
Many style of 'Loop' in Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 <0.9.0;
// @author sirawt
contract LoopPerformance {
uint256 public sum;
function clear() public {
// SPDX-License-Identifier: NONE
pragma solidity =0.7.5;
/*
* @author Shahar Zini
* conference see: https://youtu.be/P_Mtd5Fc_3E
*/
contract GuessTheNumber {
uint256 _secretNumber;
@MASDXI
MASDXI / Calculator.sol
Last active April 4, 2022 11:52
RTLO smart contract
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;
contract Calculator {
function add(uint256 x, uint256 y) public pure returns (uint256) {
/* start function*/
require(x + y >= x);
return /*first number*/x + y/*second number*/
/* end function*/;