Skip to content

grassrootseconomics/go-calibur

Repository files navigation

go-calibur

A Go library for interacting with the Uniswap/Calibur EIP-7702 implementation. Provides core types, encoding, and signature handling for batched contract calls.

Installation

go get github.com/grassrootseconomics/go-calibur

Usage

package main

import (
    "fmt"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/crypto"
    gocalibur "github.com/grassrootseconomics/go-calibur"
    "github.com/lmittmann/w3"
)

func main() {
    // Load keys
    userKey, _ := crypto.HexToECDSA("USER_PRIVATE_KEY")
    userAddr := crypto.PubkeyToAddress(userKey.PublicKey)

    relayerAddr := common.HexToAddress("0xRELAYER")
    caliburAddr := gocalibur.CaliburAddress
    chainID := big.NewInt(gocalibur.ChainCeloMainnet)

    // Build a batch of calls
    funcTransfer := w3.MustNewFunc("transfer(address,uint256)", "bool")
    tokenAddr := common.HexToAddress("0xTOKEN")
    recipient := common.HexToAddress("0xRECIPIENT")
    calldata, _ := funcTransfer.EncodeArgs(recipient, big.NewInt(1000000))

    batch := gocalibur.BatchedCall{
        Calls: []gocalibur.Call{
            {To: tokenAddr, Data: calldata},
        },
        RevertOnFailure: true,
    }

    // Create signed batched call
    signedCall := gocalibur.SignedBatchedCall{
        BatchedCall: batch,
        Nonce:       big.NewInt(0),
        Executor:    relayerAddr,
        Deadline:    big.NewInt(0),
    }

    // Sign with EIP-712
    domain := gocalibur.CaliburDomain(chainID, userAddr, caliburAddr)
    digest := gocalibur.ComputeDigest(domain, signedCall)
    sig, _ := crypto.Sign(digest[:], userKey)
    wrapped := gocalibur.WrapSignature(sig, nil)

    // Encode for relayed execution
    txData, _ := gocalibur.EncodeRelayedCalldata(signedCall, wrapped)

    fmt.Printf("Calldata ready: %x\n", txData)
}

Links

About

Go library to interact with Uniswap Calibur smart wallet contract and other EIP 7702 utils

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages