Skip to content

Instantly share code, notes, and snippets.

View jac18281828's full-sized avatar
🦌

John Cairns jac18281828

🦌
View GitHub Profile
@jac18281828
jac18281828 / PermissionedNodeRegistry.sol
Created July 2, 2024 19:11
PermissionedNodeRegistry with counting tabultation
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { UtilLib } from "./library/UtilLib.sol";
@jac18281828
jac18281828 / UpdateRate.md
Last active June 28, 2024 18:04
How to call 'updateRate()' on ETHxRateProvider

UpdateRate must be called from time to time on Stader ETHxRateProvider, an L2 Rate Oracle for ETHx. The following steps demonstrate how to do this.

Deployment address – Ethereum mainnet:

ETHX_RATE_PROVIDER=0x0B2fAadfe75fE6507Dc8F81f8331198C65cA2C24

1. Check LayerZero fee for sending rate information.

@jac18281828
jac18281828 / QuoteSend.sol
Created June 18, 2024 19:35
Remix Quote Send for OFT
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;
struct SendParam {
uint32 dstEid; // Destination endpoint ID.
bytes32 to; // Recipient address.
uint256 amountLD; // Amount to send in local decimals.
uint256 minAmountLD; // Minimum amount to send in local decimals.
bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
bytes composeMsg; // The composed message for the send() operation.
// SPDX-License-Identifier: GNU-3.0-or-later
pragma solidity ^0.8.22;
import { Script, console } from "forge-std/Script.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol"; // OFT imports
import {
SendParam,
OFTReceipt,
OFTLimit,
@jac18281828
jac18281828 / Dockerfile
Last active May 9, 2024 23:19
Dockerfile for Node 14, smart contract development with Python 3.8
FROM ghcr.io/collectivexyz/foundry:latest
RUN sudo apt update -y && sudo apt upgrade -y
RUN sudo apt remove python3 -y
RUN sudo apt autoremove -y
RUN sudo apt install -y wget build-essential checkinstall libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
RUN mkdir -p /usr/local/src
RUN sudo chown -R foundry:foundry /usr/local/src
WORKDIR /usr/local/src
RUN wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;
// Mock imports
import { OFTMock } from "./mocks/OFTMock.sol";
import { ERC20Mock } from "./mocks/ERC20Mock.sol";
import { OFTComposerMock } from "./mocks/OFTComposerMock.sol";
// OApp imports
import {
@jac18281828
jac18281828 / ETHx_OFTAdapter.sol
Created May 1, 2024 21:38
ETHx_OFTAdapter example with message sending
// SPDX-License-Identifier: GNU-3.0-or-later
pragma solidity 0.8.22;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { OFTAdapter } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTAdapter.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";
import { MessagingFee } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { IPausable } from "./IPausable.sol";
@jac18281828
jac18281828 / MyOFT.t.sol
Created April 22, 2024 15:38
LayerZero Example OFT Test
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
// Mock imports
import { OFTMock } from "./mocks/OFTMock.sol";
import { ERC20Mock } from "./mocks/ERC20Mock.sol";
import { OFTComposerMock } from "./mocks/OFTComposerMock.sol";
// OApp imports
import {
@jac18281828
jac18281828 / spsc.h
Created February 29, 2024 17:39
single producer single consumer fifo
#pragma once
#include <cstdlib>
#include <memory>
#include <atomic>
#include <new>
template <typename T, typename Alloc = std::allocator<T>>
class spsc : private Alloc
{
@jac18281828
jac18281828 / adminrole.md
Last active February 9, 2024 19:45
Contract Admin Role Flowchart Mermaid
flowchart TD;
    A[Contract Deployment] -->|Establish DEFAULT_ADMIN_ROLE as Deployer| B(Add Additional ADMIN_ROLE as needed)
    B --> C(DEFAULT_ADMIN_ROLE builds REGISTRY_ADMIN_ROLE)
    C -->|Continuous| D[REGISTRY ADMIN performs upgrade]
    C -->|As Needed| E[DEFAULT ROLE assigned or removed]
    C -->|As Needed| F[REGISTRY ROLE assigned or removed]