Swap
Swap functionality is described in RestrictedSwap.sol
.
RestrictedSwap provides a secure means of swapping tokens between known holders of the primary Restricted token and any payment ERC-20 tokens (ie USDC, DAI, etc). Administrative permissions are checked via an external AccessControl
contract that manages roles for the ecosystem.
Note: Swap is not intended between two Restricted tokens. Rather, it is intended as a purchase of Restricted tokens using ERC-20 tokens (AKA payment token or quote token). This is enforced in the swap contract itself, by preventing ERC-1404 compatible tokens (checked via ERC-165 interface support) from being used as payment. However, other types of Restricted tokens may not explicitly support the ERC-1404 interface and thus cannot be checked programatically; therefore, this functionality should be used with caution and payment token types should always be verified first.
How It Works
As a prerequisite, users of the swap functionality are assumed to have passed any necessary off-chain AML/KYC and deemed valid holders. Contracts are also assumed to have been configured properly with admin-granted roles and transfer restrictions in place. In particular, transfers must be allowed between the groups of Seller
(of Restricted token) and Buyer
.
Configuring a Purchase of Restricted Token
As a holder (Buyer
) of an ERC-20 payment token (ie USDC, DAI, etc), one can configure a purchase order for a specified amount of Restricted token with a known party (Seller
). Here is an example involving USDC:
Buyer
must know in advance specifically how much Restricted token they'd like to receive, how much USDC they are willing to pay, and theSeller
on the other end.Buyer
must approve the Swap contract itself to handle their USDC in the purchase amount required.Buyer
then configures an open purchase order by callingconfigureBuy
with the following parameters. A Swap ID is emitted in an event.- amount of Restricted token desired
- address of
Seller
- amount of payment token (USDC) willing to swap
- address of payment token contract
Seller
must approve the Swap contract itself to handle their Restricted token in the sell amount required by the configured swap.Seller
can complete this order by callingcompleteSwapWithRestrictedToken
with the emitted Swap ID.
When transfer restrictions are validated between Buyer
and Seller
, the swap is completed and assets are actually transferred between transacting parties.
Note: Role checks (e.g., pausing, admin-only operations) are resolved through the pre-deployed AccessControl
contract referenced by the Restricted token and ancillary contracts.
Configuring a Sale of Restricted Token
As a holder of the Restricted token, one can also configure a sell order for a specified amount of desired payment ERC-20 token. It is extremely similar to the example above, except terms of the sale must be specified in advance. Here is an example involving USDC:
Seller
must know in advance specifically how much Restricted token they'd like to sell, how much USDC they require, and theBuyer
on the other end.Seller
must approve the Swap contract itself to handle their Restricted token in the sell amount desired.Seller
then configures an open sell order by callingconfigureSell
with the following parameters. A Swap ID is emitted in an event.- amount of Restricted token to sell
- address of
Buyer
- amount of payment token (USDC) required
- address of payment token contract
Buyer
must approve the Swap contract itself to handle their USDC in the amount specified by the configured swap.Buyer
can complete this order by callingcompleteSwapWithQuoteToken
with the emitted Swap ID.
When transfer restrictions are validated between Buyer
and Seller
, the swap is completed and assets are actually transferred between transacting parties.