airswap-aips icon indicating copy to clipboard operation
airswap-aips copied to clipboard

AIP 12: SupportedTokenRegistry

Open wjmelements opened this issue 4 years ago • 3 comments

Summary

This proposal sets to decrease the cost of supporting additional token pairs by allowing market makers to announce a set of tokens they can quote.

Specification

Smart Contract

There is to be a secondary locator registry with the following interface:

addTokens(address[])
removeTokens(uint256[])
removeAllTokens()
setProtocol(bytes4, bytes32)
protocols(address[])->((bytes4,bytes32)[])
stakers(address)->address[]
tokens(address)->address[]

Stake

Unlike the pairwise locator, staking in this registry is mandatory. A staker's obligation is 100,000 AST, plus 100 AST per token, and stake is deposited or withdrawn automatically when stakers addTokens(address[]), removeTokens(uint256[]), or removeAllTokens().

Staked AST should still be able to participate in governance via authorizedSigners and receive the same community benefits as AST staked elsewhere.

Client

To find a list of market makers for a pair, the client queries stakers(address) on both tokens, and then intersects the lists. They then query protocols(address[]) on those makers to get their server addresses, which they should cache but refresh at least daily. This should be done in addition to the pairwise locators until a future AIP deprecates that system.

Server

Makers should only announce tokens if they support all of their pairwise markets. The maker sets their protocol as they do in setIntent. Makers can remove tokens individually or all at once. Makers are responsible for not adding a token twice, and if they do they can correct the issue by removing all duplicates and then re-adding.

Motivation

The current locator design has a quadratic cost to creating new pairs, and the gas cost per pair is 975,448. Further, each pair has to be indexed in both directions. Between 38 tokens there are 1406 pairs, and that many createIndex would cost over a billion gas, which is 21 ETH at 15 gwei.

The staking means demand for AST, while discouraging spam that would clutter client software; when makers unstake they cleanup the registry on their way out.

Copyright

Copyright and related rights waived via CC0.

wjmelements avatar Nov 19 '20 06:11 wjmelements

We really like this AIP and think it would be a good addition to the AirSwap protocol. This AIP increases general liquidity on the network by expanding the number of available paths and tokens - instead of the indexer’s current unidirectional pathing. The cost associated with supporting additional tokens is significantly cheaper than the current method of creating two indexes for every token pair. This would likely result in improved liquidity provider onboarding, and be appreciated by existing liquidity providers.

Overall we’ll be looking forward to adding this to our roadmap once voted upon by the community.

ejwessel avatar Dec 04 '20 19:12 ejwessel

Updated proposed spec to use uint256 for removeTokens, to reduce removal gas.

wjmelements avatar Dec 16 '20 22:12 wjmelements

Updated proposed spec to use uint256 for removeTokens, to reduce removal gas.

EnumerableSet.AddressSet makes this unnecessary. address is the better spec if there is no extra gas overhead.

wjmelements avatar Mar 22 '21 21:03 wjmelements