Uniswap-enabled payments. Allow payment to be made with any ERC-20 token while receiving payment in your token of choice using pooled liquidity.
Unipay accepts tokens and ether, converts these to the desired token, and
makes approve
calls to allow the payment recipient to transfer those tokens
from the contract.
Authored by Vic Woeltjen for The Bee Token 🐝
npm i
npm run compile
Compiled contracts will be written to the build
directory as
Truffle
build artifacts.
A Unipay contract is deployed with the following configuration parameters:
address factory
: The address of the Uniswap factory contract to use to access swappable liquidity.address recipient
: The address of the recipient for payments made via this contract.address token
: The address of the token used to represent the payment, as received by the recipient.
Unipay exposes the following methods:
price(address token, uint256 value)
: Get the cost, in units of the identifiedtoken
, of making a payment of the specifiedvalue
in this contract's configured payment token.price(uint256 value)
: Get the cost, in wei, of making a payment of the specifiedvalue
in this contract's configured payment token.collect(address from, address token, uint256 value, uint256 deadline)
: Collect payment in the specifiedtoken
from thefrom
address and swap forvalue
of the configured payment token, with a transactiondeadline
specified in seconds since the start of 1970. Thefrom
address must previouslyapprove
this contract to transfer a sufficient amount to complete the swap; user code should callprice
to determine an appropriate approval amount.pay(uint256 value, uint256 deadline) payable
: Deliver payment as ether and swap forvalue
of the configured payment token, with a transactiondeadline
specified in seconds since the start of 1970. Any excess ether sent with this call will be returned to the caller.