Coder Social home page Coder Social logo

sponsor's Introduction

Sponsor

Simple sponsored transactions framework using Permit2 for batch token transfers and signature verification.

Execution specification

Users specify their sponsored execution using the following parameters:

struct Execution {
    ISignatureTransfer.TokenPermissions[] tokens;
    ISignatureTransfer.TokenPermissions payment;
    Operation[] operations;
    Condition[] conditions;
    address sender;
    uint256 nonce;
    uint256 deadline;
    bytes signature;
}

tokens

The ERC20 tokens and amounts that will be used for the execution. These are transferred from the user using permit2 into the sponsor contract to be used for any operations.

payment

The ERC20 token and amount that the user is willing to pay the sponsor operator in return for execution. This should generally cover gas costs and a tip for the service. Payment can also be made in ETH using address(0) as token, though the ETH must be acquired through operations.

Any payment is transferred directly from the sponsor contract, so the payment assets must be included in token, or acquired through operations.

operations

The operations that will be executed. These are made as external calls to the specified address with the specified data. I.e. user can specify simple transfers of tokens, swaps on AMMS, deposits into lending markets etc.

There are some built-in operations to simplify common flows:

  • sweep: sweep the full balance of a given token to the given recipient
  • sweepETH: sweep the full balance of ETH to the given recipient

conditions

Any conditions that the user wants to check after all operations are finished. I.e. check to ensure the user balances of a given token exceed a certain amount. A simple scripting language is used for defining conditions.

  • conditionType: enum of the type of check to perform
  • toCall: the contract to staticcall for a value to condition against
  • data: the data to call the given contract with
  • check: the value to check against

ex: assert(tokenA.balanceOf(user) >= 1000) would be defined as:

  • condition: ConditionType.GREATER_THAN_OR_EQUAL
  • toCall: tokenA
  • data: abi.encodeWithSignature("balanceOf(address)", user)
  • check: abi.encode(1000)

sender

The address of the signer

nonce

The nonce of the signer using the permit2 unordered nonce scheme

deadline

The timestamp deadline for the signature validity

signature

The sender signature in joined signature format, or EIP-1271 signature data

THIS IS EXPERIMENTAL, UNAUDITED CODE -- DO NOT USE IN PRODUCTION

sponsor's People

Contributors

marktoda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.