Code Monkey home page Code Monkey logo

delegated-execution-subscriptions's Introduction

πŸ•°οΈβš™οΈ Delegated Execution Subscriptions [EIP1337/EIP948]

Recurring Ethereum transactions executed through an identity proxy using a single, replayed meta transaction.

A subscriber deploys and funds a proxy (identity) contract. Then, any whitelisted etherless account signs a single off-chain meta transaction that will be periodically sent on-chain to trigger an Ethereum transaction. This transaction can be sending ETH, interacting with a contract, or even deploying a new contract.

This project is the culmination of months of research and two previous POCs:

Bouncer Proxy The bouncer-proxy POC demonstrated how an identity contract could be deployed as a proxy and then interacted with using meta transactions. Etherless accounts could be whitelisted and sign off-chain transactions which are then submitted on-chain by incentivized relayers, cryptographically proven, and used to execute typical Ethereum transactions.

Token Subscriptions Token subscriptions are a bare minimum POC to demonstrate how meta transactions can be used with a timestamp nonce trick to replay a single transaction on a periodic basis. We used the ERC20 approve/allowance to control the flow of tokens without the need of other complicated mechanics.

Delegated Execution Subscriptions bring these two concepts together.

An identity contract is controlled by whitelisted, etherless accounts to periodically interact with the blockchain signaled by a single meta transaction. A set it and forget it subscription periodically executes standard Ethereum transactions powered by an incentivized layer of meta transaction relayers.

Demo

screencast.png

https://byoc.metatx.io

Development

See full development history on this byoc branch.

Abstract

A subscriber can deploy a subscription contract to act as their identity and proxy their meta transactions. The subscriber must only sign a single, off-chain meta transaction to start the flow of recurring Ethereum transactions. This meta transaction is periodically sent to the subscription contract via an incentivized relayer network.

The single meta transaction becomes valid using a timestamp nonce (instead of a traditional replay attack nonce). The meta transaction can be submitted, proven valid through ecrecover(), and then a call(), delegateCall(), or create() is executed by the subscription contract.

The subscriber is in full control of the subscription contract but any account they whitelist can also create new subscriptions or pause existing ones without having to hold any ETH. Further, the terms of each subscription is explicitly signed in the meta transaction and can't be manipulated.

Meta transactions can be submitted by any relayer and the relayer can be incentivized with a gasToken. This token can be paid by the publisher, the subscriber, or the subscription contract. The subscription contract can also reimburse the relayers directly with Ethereum.

 β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•—β•šβ•β•β•β•β–ˆβ–ˆβ•—β•šβ•β•β•β•β–ˆβ–ˆβ•‘
β•šβ–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•    β–ˆβ–ˆβ•”β•
 β–ˆβ–ˆβ•‘ β•šβ•β•β•β–ˆβ–ˆβ•— β•šβ•β•β•β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•”β•
 β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•   β–ˆβ–ˆβ•‘  
 β•šβ•β•β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•    β•šβ•β•  -EIP-

ethereum/EIPs#1337

Standard

    enum SubscriptionStatus {
        ACTIVE,
        PAUSED,
        CANCELLED,
        EXPIRED
    }
    enum Operation {
        Call,
        DelegateCall,
        Create
    }
  event ExecuteSubscription(
      address from, //the subscriber
      address to, //the target contract or account
      uint256 value, //amount in wei of ether sent from this contract to the to address
      bytes data, //the encoded transaction data (first four bytes of fn plus args, etc)
      Operation operation, //ENUM of operation
      uint256 periodSeconds, //the period in seconds between payments
      address gasToken, //the address of the token to pay relayer (0 for eth)
      uint256 gasPrice, //the amount of tokens or eth to pay relayer (0 for free)
      address gasPayer //the address that will pay the tokens to the relayer
  );
    function updateWhitelist(
        address _account,
        bool _value
    )
        public
        onlyOwner
        returns (bool)
    function isSubscriptionPaid(
        bytes32 subscriptionHash,
        uint256 gracePeriodSeconds
    )
        external
        view
        returns (bool)
    function getSubscriptionStatus(
        bytes32 subscriptionHash
    )
        public
        view
        returns  (uint256)
    function getSubscriptionHash(
        address from, //the subscriber
        address to, //the target contract or account
        uint256 value, //amount in wei of ether sent from this contract to the to address
        bytes data, //the encoded transaction data (first four bytes of fn plus args, etc)
        Operation operation, //ENUM of operation
        uint256 periodSeconds, //the period in seconds between payments
        address gasToken, //the address of the token to pay relayer (0 for eth)
        uint256 gasPrice, //the amount of tokens or eth to pay relayer (0 for free)
        address gasPayer //the address that will pay the tokens to the relayer
    )
        public
        view
        returns (bytes32)
    function getSubscriptionSigner(
        bytes32 subscriptionHash, //hash of subscription
        bytes signature //proof the subscriber signed the meta trasaction
    )
        public
        pure
        returns (address)
    function isSubscriptionReady(
        address from, //the subscriber
        address to, //the publisher
        uint256 value, //amount in wei of ether sent from this contract to the to address
        bytes data, //the encoded transaction data (first four bytes of fn plus args, etc)
        Operation operation, //ENUM of operation
        uint256 periodSeconds, //the period in seconds between payments
        address gasToken, //the address of the token to pay relayer (0 for eth)
        uint256 gasPrice, //the amount of tokens or eth to pay relayer (0 for free)
        address gasPayer, //the address that will pay the tokens to the relayer
        bytes signature //proof the subscriber signed the meta trasaction
    )
        public
        view
        returns (bool)
    function isValidSignerTimestampAndStatus(
        address from,
        address signer,
        bytes32 subscriptionHash
    )
        public
        view
        returns (bool)
    function getModifyStatusHash(
        bytes32 subscriptionHash,
        SubscriptionStatus status
    )
        public
        view
        returns (bytes32)
    function isValidModifyStatusSigner(
        bytes32 subscriptionHash,
        SubscriptionStatus status,
        bytes signature
    )
        public
        view
        returns (bool)
    function modifyStatus(
        bytes32 subscriptionHash,
        SubscriptionStatus status,
        bytes signature
    )
        public
        returns (bool)
    function executeSubscription(
        address from, //the subscriber
        address to, //the target contract or account
        uint256 value, //amount in wei of ether sent from this contract to the to address
        bytes data, //the encoded transaction data (first four bytes of fn plus args, etc)
        Operation operation, //ENUM of operation
        uint256 periodSeconds, //the period in seconds between payments
        address gasToken, //the address of the token to pay relayer (0 for eth)
        uint256 gasPrice, //the amount of tokens or eth to pay relayer (0 for free)
        address gasPayer, //the address that will pay the tokens to the relayer
        bytes signature //proof the subscriber signed the meta trasaction
    )
        public
        returns (bool)

Acknowledgments

Original Proposal: https://gist.github.com/androolloyd/0a62ef48887be00a5eff5c17f2be849a

Directly extended from: https://github.com/austintgriffith/token-subscription

Huge thanks to Owocki & Seagraves of Gitcoin and Andrew Redden of Groundhog for the guidance!!!

delegated-execution-subscriptions's People

Contributors

austintgriffith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

delegated-execution-subscriptions's Issues

BYOC - Deploy Subscription Contract : Even with Insanely High Gas it does this :

ALERT: [ethjs-rpc] rpc error with payload {"id":7241966932364,"jsonrpc":"2.0","params":["0xf91a04808488fe9a99830222e08080b919b260e0604052603560808190527f44656c65676174656420457865637574696f6e20537562736372697074696f6e60a09081527f732028504f4329205b454950313333372f3934385d000000000000000000000060c052620000649160019190620000fa565b506040805160608101825260338082527f41757374696e2054686f6d6173204772696666697468202d2068747470733a2f602083019081527f2f61757374696e67726966666974682e636f6d000000000000000000000000009290930191909152620000d391600291620000fa565b50348015620000e157600080fd5b5060008054600160a060020a031916331790556200019f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200013d57805160ff19168380011785556200016d565b828001600101855582156200016d579182015b828111156200016d57825182559160200191906001019062000150565b506200017b9291506200017f565b5090565b6200019c91905b808211156200017b576000815560010162000186565b90565b61180380620001af6000396000f3006080604052600436106101115763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630d392cd981146101495780630e792ed114610183578063103fc47f146101ad57806316d121901461028357806318f321a3146102ad578063192cdcd0146103275780632b1351661461034257806349c7ef621461037e57806370740aab146103e1578063715018a61461046b57806378d1899e146104825780638da5cb5b146104a057806397c43948146104b55780639b19251a146104cd578063a4b9a817146104ee578063a6c3e6b9146105c4578063bd646433146105d9578063c77ddd1e1461063c578063f2fde38b146106d1578063ff59bff8146106f2575b60408051348152905133917f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f88525874919081900360200190a2005b34801561015557600080fd5b5061016f600160a060020a0360043516602435151561070a565b604080519115158252519081900360200190f35b34801561018f57600080fd5b5061016f600160a060020a036004358116906024351660443561078f565b3480156101b957600080fd5b50604080516020601f60643560048181013592830184900484028501840190955281845261016f94600160a060020a03813581169560248035909216956044359536956084940191819084018382808284375050604080516020601f60a08a01358b0180359182018390048302840183018552818452989b60ff8b35169b838c01359b600160a060020a039681013587169b60608201359b5060808201359097169950919750955060c0019382019181908401838280828437509497506108299650505050505050565b34801561028f57600080fd5b5061029b600435610d94565b60408051918252519081900360200190f35b3480156102b957600080fd5b5060408051602060046024803582810135601f810185900485028601850190965285855261030b958335953695604494919390910191908190840183828082843750949750610db79650505050505050565b60408051600160a060020a039092168252519081900360200190f35b34801561033357600080fd5b5061016f600435602435610dd9565b34801561034e57600080fd5b5061035a600435610e02565b6040518082600381111561036a57fe5b60ff16815260200191505060405180910390f35b34801561038a57600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261016f948235946024803560ff1695369594606494920191908190840183828082843750949750610e179650505050505050565b3480156103ed57600080fd5b506103f6610ebc565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610430578181015183820152602001610418565b50505050905090810190601f16801561045d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561047757600080fd5b50610480610f49565b005b34801561048e57600080fd5b5061029b60043560ff60243516610fb5565b3480156104ac57600080fd5b5061030b6110b9565b3480156104c157600080fd5b5061029b6004356110c8565b3480156104d957600080fd5b5061016f600160a060020a03600435166110da565b3480156104fa57600080fd5b50604080516020601f60643560048181013592830184900484028501840190955281845261016f94600160a060020a03813581169560248035909216956044359536956084940191819084018382808284375050604080516020601f60a08a01358b0180359182018390048302840183018552818452989b60ff8b35169b838c01359b600160a060020a039681013587169b60608201359b5060808201359097169950919750955060c0019382019181908401838280828437509497506110ef9650505050505050565b3480156105d057600080fd5b506103f661112f565b3480156105e557600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261016f948235946024803560ff16953695946064949201919081908401838280828437509497506111879650505050505050565b34801561064857600080fd5b50604080516020601f60643560048181013592830184900484028501840190955281845261029b94600160a060020a0381358116956024803590921695604435953695608494019181908401838280828437509497505050833560ff16945050506020820135916040810135600160a060020a039081169250606082013591608001351661129b565b3480156106dd57600080fd5b50610480600160a060020a03600435166114b4565b3480156106fe57600080fd5b5061029b6004356114d7565b60008054600160a060020a0316331461072257600080fd5b600160a060020a038316600081815260066020908152604091829020805460ff19168615151790819055825193845260ff1615159083015280517f08b2c0469ecd1d7a21d7e1492f0fc75fc7e8e0fa4fdf4275949c90875f5ebdf59281900390910190a150600192915050565b600083600160a060020a031683600160a060020a03161480156107e15750600054600160a060020a03848116911614806107e15750600160a060020a03831660009081526006602052604090205460ff165b80156107fb57506000828152600360205260409020544210155b8015610821575060008281526004602052604081205460ff16600381111561081f57fe5b145b949350505050565b600080600061083f8d8d8d8d8d8d8d8d8d61129b565b915061084b8285610db7565b90506108588d828461078f565b15156108d4576040805160e560020a62461bcd02815260206004820152603860248201527f5369676e61747572652c2046726f6d204163636f756e742c2054696d6573746160448201527f6d702c206f722073746174757320697320696e76616c69640000000000000000606482015290519081900360840190fd5b600082815260036020526040812054116109005760008281526003602052604090204289019055610915565b60008281526003602052604090208054890190555b6000861115610bef57600160a060020a03871615156109c8576040513290618ca09088906000818181858888f1935050505015156109c3576040805160e560020a62461bcd02815260206004820152603460248201527f537562736372697074696f6e20636f6e7472616374206661696c656420746f2060448201527f70617920657468657220746f2072656c61796572000000000000000000000000606482015290519081900360840190fd5b610bef565b600160a060020a0385163014806109e65750600160a060020a038516155b15610ad557604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152326004820152602481018890529051600160a060020a0389169163a9059cbb9160448083019260209291908290030181600087803b158015610a5357600080fd5b505af1158015610a67573d6000803e3d6000fd5b505050506040513d6020811015610a7d57600080fd5b505115156109c3576040805160e560020a62461bcd02815260206004820152601d60248201527f4661696c656420746f207061792067617320617320636f6e7472616374000000604482015290519081900360640190fd5b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a038781166004830152326024830152604482018990529151918916916323b872dd916064808201926020929091908290030181600087803b158015610b4757600080fd5b505af1158015610b5b573d6000803e3d6000fd5b505050506040513d6020811015610b7157600080fd5b50511515610bef576040805160e560020a62461bcd02815260206004820152603260248201527f4661696c656420746f207061792067617320696e20746f6b656e732066726f6d60448201527f20617070726f7665642067617350617965720000000000000000000000000000606482015290519081900360840190fd5b7ffdac006fe67c7e0026b6537260486d1f283dfbb0fb47680dba5b251980fd63e48d8d8d8d8d8d8d8d8d604051808a600160a060020a0316600160a060020a0316815260200189600160a060020a0316600160a060020a0316815260200188815260200180602001876002811115610c6357fe5b60ff16815260200186815260200185600160a060020a0316600160a060020a0316815260200184815260200183600160a060020a0316600160a060020a03168152602001828103825288818151815260200191508051906020019080838360005b83811015610cdc578181015183820152602001610cc4565b50505050905090810190601f168015610d095780820380516001836020036101000a031916815260200191505b509a505050505050505050505060405180910390a1610d2b8c8c8c8c5a6114e9565b1515610d81576040805160e560020a62461bcd02815260206004820152601e60248201527f4661696c656420746f206578656375746520737562736372697074696f6e0000604482015290519081900360640190fd5b5060019c9b505050505050505050505050565b60008181526004602052604081205460ff166003811115610db157fe5b92915050565b6000610dd282610dc68561158a565b9063ffffffff61163416565b9392505050565b600082815260036020526040812054610df8908363ffffffff61170916565b4210159392505050565b60046020526000908152604090205460ff1681565b600080610e3083610dc6610e2b8888610fb5565b61158a565b600054909150600160a060020a0380831691161480610e675750600160a060020a03811660009081526006602052604090205460ff165b8015610eb3575060008581526004602052604081205460ff166003811115610e8b57fe5b1480610eb35750600160008681526004602052604090205460ff166003811115610eb157fe5b145b95945050505050565b60018054604080516020600284861615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610f415780601f10610f1657610100808354040283529160200191610f41565b820191906000526020600020905b815481529060010190602001808311610f2457829003601f168201915b505050505081565b600054600160a060020a03163314610f6057600080fd5b60008054604051600160a060020a03909116917ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482091a26000805473ffffffffffffffffffffffffffffffffffffffff19169055565b60008281526005602090815260408083205490517f190000000000000000000000000000000000000000000000000000000000000092810183815260218201859052306c01000000000000000000000000810260228401526036830188905285939092889288929160560183600381111561102c57fe5b60ff1660f860020a02815260010182815260200196505050505050506040516020818303038152906040526040518082805190602001908083835b602083106110865780518252601f199092019160209182019101611067565b5181516020939093036101000a600019018019909116921691909117905260405192018290039091209695505050505050565b600054600160a060020a031681565b60056020526000908152604090205481565b60066020526000908152604090205460ff1681565b60008060006111058d8d8d8d8d8d8d8d8d61129b565b91506111118285610db7565b905061111e8d828461078f565b9d9c50505050505050505050505050565b6002805460408051602060018416156101000260001901909316849004601f81018490048402820184019092528181529291830182828015610f415780601f10610f1657610100808354040283529160200191610f41565b6000611194848484610e17565b15156111ea576040805160e560020a62461bcd02815260206004820152601f60248201527f496e76616c6964206d6f6469667920737461747573207369676e617475726500604482015290519081900360640190fd5b60008481526005602052604090208054600190810190915560008581526004602052604090205460ff16600381111561121f57fe5b1480156112375750600083600381111561123557fe5b145b8015611250575060008481526003602052604090205442115b156112675760008481526003602052604090204290555b6000848152600460205260409020805484919060ff1916600183600381111561128c57fe5b02179055506001949350505050565b6000601960f860020a02600060f860020a02308c8c8c8c8c8c8c8c8c604051602001808d600160f860020a031916600160f860020a03191681526001018c600160f860020a031916600160f860020a03191681526001018b600160a060020a0316600160a060020a03166c010000000000000000000000000281526014018a600160a060020a0316600160a060020a03166c0100000000000000000000000002815260140189600160a060020a0316600160a060020a03166c0100000000000000000000000002815260140188815260200187805190602001908083835b602083106113985780518252601f199092019160209182019101611379565b6001836020036101000a0380198251168184511680821785525050505050509050018660028111156113c657fe5b60ff1660f860020a02815260010185815260200184600160a060020a0316600160a060020a03166c0100000000000000000000000002815260140183815260200182600160a060020a0316600160a060020a03166c010000000000000000000000000281526014019c505050505050505050505050506040516020818303038152906040526040518082805190602001908083835b6020831061147a5780518252601f19909201916020918201910161145b565b5181516020939093036101000a600019018019909116921691909117905260405192018290039091209d9c50505050505050505050505050565b600054600160a060020a031633146114cb57600080fd5b6114d48161171b565b50565b60036020526000908152604090205481565b600080808460028111156114f957fe5b14156115125761150b87878786611798565b9150611580565b600184600281111561152057fe5b14156115315761150b8786856117b0565b61153a856117c6565b60408051600160a060020a038316808252915191151594509192507f4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b5119181900360200190a15b5095945050505050565b604080517f19457468657265756d205369676e6564204d6573736167653a0a333200000000602080830191909152603c80830185905283518084039091018152605c909201928390528151600093918291908401908083835b602083106116025780518252601f1990920191602091820191016115e3565b5181516020939093036101000a6000190180199091169216919091179052604051920182900390912095945050505050565b6000806000808451604114151561164e5760009350611700565b50505060208201516040830151606084015160001a601b60ff8216101561167357601b015b8060ff16601b1415801561168b57508060ff16601c14155b156116995760009350611700565b60408051600080825260208083018085528a905260ff8516838501526060830187905260808301869052925160019360a0808501949193601f19840193928390039091019190865af11580156116f3573d6000803e3d6000fd5b5050506020604051035193505b50505092915050565b600082820183811015610dd257600080fd5b600160a060020a038116151561173057600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000806000845160208601878987f195945050505050565b60008060008451602086018786f4949350505050565b60008151602083016000f0929150505600a165627a7a72305820afbbfb6a78e6dc346e9b72905035cf79ef43a73e42af5bf56cc67062445306d900292ba0a64d56925e4e0e60c3cd3d902b76018d016b4a37fca084581152c662f2d323fda05276b03d2916def38b2d429acc07740996a168d8a7289f3e733ae15a4b818afe"],"method":"eth_sendRawTransaction"} {"code":-32000,"message":"intrinsic gas too low"}

Hope this helps <3
screenshot 2019-02-02 at 12 25 57 pm

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.