Gasless decentralized token swaps
Systems and methods for gasless decentralized token swaps with MEV protection are disclosed herein. A user submits to a swap platform a signed limit order to swap an amount of input token for an output token using a Dutch auction approach. The order execution price depends on time of inclusion in a block and decreases over the duration of the Dutch auction. The user does not pay a gas fee for submitting this order. The swap platform provides the order details to whitelisted resolvers to evaluate if/when/how to fill the order. Once a resolver makes that determination, it can send instructions and fill data to smart contracts of the swap platform to fill the order and implement the swap. Input tokens are pulled from the user's wallet and transferred to the resolver, in exchange for output tokens which are pulled from the resolver and transferred to the user's wallet.
1 . A computer-implemented method performed by a swap platform, the method comprising:
receiving, from an application of a user device of a user, an order to swap an input token in exchange for an output token without the user paying a gas fee, wherein the order is received via a user interface of the application, wherein the application comprises a web-based application accessed by the user device via a browser, wherein the order comprises an off chain data structure digitally signed by the user and comprises:
a set of parameters;
an indication of a plurality of whitelisted resolvers, the indication cryptographically bound to an order hash;
a block-indexed grid curve function that defines auction price thresholds over a block window;
a signature that authorizes a settlement or limit-order contract to transfer a specified amount of the input token; and
an order identifier,
wherein the user interface is configured to receive the plurality of parameters comprising:
the input token;
the specified amount of the input token;
the output token;
a maximum swap threshold comprising a starting amount of the output token;
a minimum swap threshold;
a time threshold; and
a swap approval;
providing the order to the plurality of whitelisted resolvers to fulfill via a Dutch auction that reflects the plurality of parameters in the order, wherein the Dutch auction comprises an auction price that begins at the maximum swap threshold and decreases to the minimum swap threshold by the time threshold;
receiving, by a settlement smart contract and from a resolver of the plurality of resolvers, instructions for the settlement smart contract to fulfill the order at the auction price via a distributed blockchain network, wherein the resolver comprises a resolver worker address,
wherein the settlement smart contract:
verifies the resolver by validating a proof against the indication of the plurality of whitelisted resolvers in the order;
verifies that no prior user-originated on chain transaction exists for the order identifier;
computes a current-block auction price by combining the block-indexed grid curve function with a rate-bump value retrieved from an on chain quoter mapping keyed by the order identifier and current block number;
validates the signature and pulls the input token from a wallet of the user via an order protocol call; and
atomically debits a pre-funded balance of the resolver,
wherein the distributed blockchain network operates on a plurality of nodes forming a peer-to-peer computer network, wherein the settlement smart contract comprises autonomous code integrated into the distributed blockchain network and hosted on the plurality of nodes of the distributed blockchain network,
wherein fulfillment of the order comprises exchange of at least one cryptocurrency or token and occurs via execution on the distributed blockchain network,
wherein the swap platform is implemented across the plurality of nodes of the distributed blockchain network, and wherein the resolver pays a gas fee on behalf of the user for fulfilling the order; and
causing the amount of the input token in a wallet of the user to be swapped for an amount of the output token.
2 . The computer-implemented method of claim 1 , wherein the swap authorization permits a smart contract to retrieve tokens from and send tokens to the wallet of the user.
3 . The computer-implemented method of claim 1 , wherein the set of parameters specified by the order further comprises an execution approach.
4 . The computer-implemented method of claim 1 , wherein the set of parameters specified by the order further comprises an execution approach, and wherein the execution approach specifies how the auction price decays over time until the minimum swap threshold is reached.
5 . The computer-implemented method of claim 1 , wherein the set of parameters specified by the order are configured by the user through a frontend application operating on the user device.
6 . The computer-implemented method of claim 1 , wherein the Dutch auction provides a top resolver a priority right to fulfill the order before other resolvers in the plurality of resolvers.
7 . A computer system comprising:
one or more processing devices; and
one or more memory devices operably coupled to the one or more processing devices, the one or more memory devices storing executable code that, when executed by the one or more processing devices, causes the one or more processing devices to:
receive, from an application of a user device of a user, an order to swap an input token in exchange for an output token without the user paying a gas fee, wherein the order is received via a user interface of the application, wherein the application comprises a web- based application accessed by the user device via a browser, wherein the order comprises an off chain data structure digitally signed by the user and comprises:
a set of parameters;
an indication of a plurality of whitelisted resolvers, the indication cryptographically bound to an order hash;
a block-indexed grid curve function that defines auction price thresholds over a block window;
a signature that authorizes a settlement or limit-order contract to transfer a specified amount of the input token; and
an order identifier,
wherein the user interface is configured to receive the plurality of parameters comprising:
the input token;
the specified amount of the input token;
the output token;
a maximum swap threshold comprising a starting amount of the output token;
a minimum swap threshold;
a time threshold; and
a swap approval;
provide the order to the plurality of whitelisted resolvers to fulfill via a Dutch auction that reflects the plurality of parameters in the order, wherein the Dutch auction comprises an auction price that begins at the maximum swap threshold and decreases to the minimum swap threshold by the time threshold;
receive, by a settlement smart contract and from a resolver of the plurality of resolvers, instructions for the settlement smart contract to fulfill the order at the auction price via a distributed blockchain network, wherein the resolver comprises a resolver worker address, wherein the settlement smart contract:
verifies the resolver by validating a proof against the indication of the plurality of whitelisted resolvers in the order;
verifies that no prior user-originated on chain transaction exists for the order identifier;
computes a current-block auction price by combining the block-indexed grid curve function with a rate-bump value retrieved from an on chain quoter mapping keyed by the order identifier and current block number;
validates the signature and pulls the input token from a wallet of the user via an order protocol call; and
atomically debits a pre-funded balance of the resolver,
wherein the distributed blockchain network operates on a plurality of nodes forming a peer-to-peer computer network, wherein the settlement smart contract comprises autonomous code integrated into the distributed blockchain network and hosted on the plurality of nodes of the distributed blockchain network,
wherein fulfillment of the order comprises exchange of at least one cryptocurrency or token and occurs via execution on the distributed blockchain network,
wherein the swap platform is implemented across the plurality of nodes of the distributed blockchain network, and wherein the resolver pays a gas fee on behalf of the user for fulfilling the order; and
cause the amount of the input token in a wallet of the user to be swapped for an amount of the output token.
8 . The computer system of claim 7 , wherein the swap authorization permits a smart contract to retrieve tokens from and send tokens to the wallet of the user.
9 . The computer system of claim 7 , wherein the set of parameters specified by the order further comprises an execution approach.
10 . The computer system of claim 7 , wherein the set of parameters specified by the order further comprises an execution approach, and wherein the execution approach specifies how the auction price decays over time until the minimum swap threshold is reached.
11 . The computer system of claim 7 , wherein the set of parameters specified by the order are configured by the user through a frontend application operating on the user device.
12 . The computer system of claim 7 , wherein the Dutch auction provides a top resolver a priority right to fulfill the order before other resolvers in the plurality of resolvers.
13 . A non-transient computer readable medium containing program instructions for causing a computer system to perform the steps of:
receiving, from an application of a user device of a user, an order to swap an input token in exchange for an output token without the user paying a gas fee, wherein the order is received via a user interface of the application, wherein the application comprises a web-based application accessed by the user device via a browser, wherein the order comprises an off chain data structure digitally signed by the user and comprises:
a set of parameters;
an indication of a plurality of whitelisted resolvers, the indication cryptographically bound to an order hash;
a block-indexed grid curve function that defines auction price thresholds over a block window;
a signature that authorizes a settlement or limit-order contract to transfer a specified amount of the input token; and
an order identifier,
wherein the user interface is configured to receive the plurality of parameters comprising:
the input token;
the specified amount of the input token;
the output token;
a maximum swap threshold comprising a starting amount of the output token;
a minimum swap threshold;
a time threshold; and
a swap approval;
providing the order to the plurality of whitelisted resolvers to fulfill via a Dutch auction that reflects the plurality of parameters in the order, wherein the Dutch auction comprises an auction price that begins at the maximum swap threshold and decreases to the minimum swap threshold by the time threshold;
receiving, by a settlement smart contract and from a resolver of the plurality of resolvers, instructions for the settlement smart contract to fulfill the order at the auction price via a distributed blockchain network, wherein the resolver comprises a resolver worker address, wherein the settlement smart contract:
verifies the resolver by validating a proof against the indication of the plurality of whitelisted resolvers in the order;
verifies that no prior user-originated on chain transaction exists for the order identifier;
computes a current-block auction price by combining the block-indexed grid curve function with a rate-bump value retrieved from an on chain quoter mapping keyed by the order identifier and current block number;
validates the signature and pulls the input token from a wallet of the user via an order protocol call; and
atomically debits a pre-funded balance of the resolver,
wherein the distributed blockchain network operates on a plurality of nodes forming a peer-to-peer computer network, wherein the settlement smart contract comprises autonomous code integrated into the distributed blockchain network and hosted on the plurality of nodes of the distributed blockchain network
wherein fulfillment of the order comprises exchange of at least one cryptocurrency or token and occurs via execution on the distributed blockchain network,
wherein the swap platform is implemented across the plurality of nodes of the distributed blockchain network, and wherein the resolver pays a gas fee on behalf of the user for fulfilling the order; and
causing the amount of the input token in a wallet of the user to be swapped for an amount of the output token.
14 . The non-transient computer readable medium of claim 13 , wherein the swap authorization permits a smart contract to retrieve tokens from and send tokens to the wallet of the user.