Superposition contracts

Security

Security instructions

Contributors

Contributors

Deployments

Superposition Mainnet

Superposition RPC

AMM contract deployments

Deployment nameDeployment address
Longtail AMM0xF3334049A3ce7e890bd4f8C6a0FBC70e38fd3746
Longtail NFT manager0xdD193817F66276d1EAd064dF8F3112b553A50d10
Position Handler0x7C70a15Fee9Db2aFf632cc378D8f11bcac0d516d
Permit2 router0x244517Dc59943E8CdFbD424Bdb3262c5f04a1387
Swaps A implementation0x5ad9286c0f0f306022d172d32b27f1b28a8ffc3a
Swaps B implementation0x7d0d7d04b2ac05c159972612ef5bf384116c4cf7
Swaps permit2 A implementation0x0000000000000000000000000000000000000000
Quotes A implementation0xcb937ecaf8cf29dd9bdb45418d17cfee74673535
Quotes B implementation0x0314353a14099895d2510483b18b52e7bd1a2528
Positions implementation0x206ded2b8c44a0aa08a09845da274059544b23d4
Update position implementation0xfd066c8a3dfc1626473aa86a793e6bd73963ce4c
Admin implementation0x1292733b7936ed63b4aec201f9fd4c68be2d7c71
Adjust position A impl0xc2311bef0c737d658a4cf3a8022bd907eb584592
Swaps permit2 B implementation0x0000000000000000000000000000000000000000
Adjust position B impl0xffb57bb85e00c8ddd80cf45a91e11628ceabab89

Administrative deployments

Deployment nameDeployment address
Proxy admin for Leo

Leo contract deployments

Deployment nameDeployment address
Leo proxy0xC5a5bB74e41A01927d29dbffA8Ab796c784bCBA8

Token deployments

Deployment nameDeployment address
USDC (base asset)0x6c030c5CC283F791B26816f325b9C632d964F8A1
WETH (native)0x1fB719f10b56d7a85DCD32f27f897375fB21cfdd
ARB0xA2555701754464d32D9624149E3fDb459F3c8DE4
FLY0x80eFAD50D395671C13C4b1FA2969f7a7Aa9EF7b3
USDT
WBTC

Superposition Testnet

Superposition RPC

AMM contract deployments

Deployment nameDeployment address
Longtail AMM0xAe86141e3f1C9168cE6c948FDC884F2A5f45d7B6
Longtail NFT manager0x8aa3750A7e8c98830e3421a89bFf80Fc175e4C98
Position Handler0x73387E7E4DF41f58Be13cdE4Dd4EAf3675c1C44c
Permit2 router0x2246431582087b930F2CE561c34deb8E7e5c44bE
Swaps A implementation0x0dc55b20bdf11fb0ea39e61743532711cda5436c
Swaps B implementation0xea0edbb819bcf094590000e36f19a5285c6457c3
Swaps permit2 A implementation0x0000000000000000000000000000000000000000
Quotes A implementation0xb5fb8fae334286f992a697e75f0c5d68d845415b
Quotes B implementation0xd8d7f75988556fb2dd1b971a4848f7b56cbcfd39
Positions implementation0xc9328bb8cdc2a890d428709b781f5f5932addb99
Update position implementation0xe6474ec944b35a914f915ce7686cd0003ca5b695
Admin implementation0x60c8d4ef56fd56967fcc123fe6b677bf41105180
Adjust position A impl0xc0111b0fae58f58451ba64dabfc5a2d5aaa0d5d3
Swaps permit2 B implementation0x0000000000000000000000000000000000000000
Adjust position B impl0xe96e51ced07a09d99c5b4c6068d274fdb12f9264

Leo contract deployments

Deployment nameDeployment address
Leo0xADA1629b77A4864340b7b9Dc4B9874068E844b08
Collect implementation0xcc76d4d1e7e021bd2309bfe236b345d95b8526c5
Extras implementation0x50bdc4ea3f3003099f936f2fc6f8cee0b730c168

Useful testing token deployments

Deployment nameDeployment address
fUSDC0xA8EA92c819463EFbEdDFB670FEfC881A480f0115
WETH0xde104342B32BCa03ec995f999181f7Cf1fFc04d7
USDC0x6437fdc89cED41941b97A9f1f8992D88718C81c5
WSPN0x22b9fa698b68bBA071B513959794E9a47d19214c
CATBUX0x36c116a8851869cf8a99b3Bda0Fad42453D32B99

Errors

Currently, to save on space, errors generated by the contract are terse. Decode the hex to the appropriate error in this table:

NoHexExplanation
00x00Denominator is 0
10x01Result is U256::MAX
20x02Sqrt price is 0
30x03Sqrt price is less than or equal to quotient
40x04Can not get most significant bit or least significant bit on zero value
50x05Liquidity is 0
60x06require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product);
70x07Denominator is less than or equal to prod_1
80x08Liquidity Sub
90x09Liquidity Add
100x0aThe given tick must be less than, or equal to, the maximum tick
110x0bSecond inequality must be < because the price can never reach the price at the max tick
120x0cOverflow when casting to U160
130x0dLiquidity higher than max
140x0eFee growth sub overflow
150x0fERC20 call reverted
160x10ERC20 call reverted with no data
170x11Pool is already initialised
180x12Contract is already initialised
190x13Price limit too high
200x14Price limit too low
210x15Checked abs called on an unexpected positive number
220x16Checked abs called on an unexpected negative number
230x17Checked abs called on uint.min
240x18Fee result too high
250x19Swap result too high
260x1aInternal swap amounts not matched
270x1bInternal swap result was positive
280x1cMinimum out not reached
290x1dOnly the position owner can use this
300x1eOnly the NFT manager can use this
310x1fOnly the Seawater admin can use this
320x20Operation unavailable when the pool is disabled
330x21Invalid tick spacing
340x22Swap result too low
350x23Liquidity too low or high to be a int128
360x24Invalid tick
370x25Pool enabled when it should be disabled for this action
380x26Position is empty when it shouldn't be
390x27Liquidity that was almost taken was too low when it didn't need to be
400x28Fee growth that tried to be calculated was bad internally for a tick

If more bytes are in the error, then the issue was produced by the ERC20 token. Convert any error types to their selector form to see.

Access graph

A publicly available graph for Longtail is available. It includes documentation. https://testnet-graph.long.so.

Building

Longtail ("Seawater") is a diamond-like contract, with the frontend to access the Stylus diamond facets implemented in Solidity. So, Stylus is needed with Rust for the implementation contracts, and Foundry is needed to compile the contract.

To save on contract size, and to reduce gas overhead, this contract stores the addresses of the swap router, and the admin address, at compile-time.

So these variables must set at compile-time, like so:

Build variables

NameDescription
FLU_SEAWATER_PERMIT2_ADDRUniswap Permit2 router
FLU_SEAWATER_FUSDC_ADDRUSDC Super Asset to route every trade through

Build dependencies

NameSource
Rust (nightly version)Installer
Cargo Stylus subcommandRepo
FoundryInstaller
Makebuild-essentials if you're on Linux

Build process

make build

Testing

Testing is done with via a hosted test using cargo features with the testing flag. tests.sh is provided to run both test suites.

End to end testing is currently unavailable due to issues with the deployment toolchain.

Testing process

./tests.sh

Cargo test tracing

Some of the cargo tests have optional logging, which might help with debugging. To see these logs, enable the testing-dbg-<test> feature and run the tests without capturing stdout, ie cargo test --features=testing,testing-dbg-erc20 -- --nocapture.

Testing tools are available with the with_storage macro, which lets you set slots and maximum balances for ERC20 transfers. Reproducing on-chain transactions is possible by using a tracer on the chain the transaciton took place, then examining the storage slots that were accessed (perhaps by looking at SLOADs), and setting it explicitly with the macro.

Deployment

You can deploy the contracts using the deploy.sh script.

Test deployments

Deployments on a local node can be done with ./test-deploy.sh for simplicity.

Deployment variables

NameDescription
SEAWATER_PROXY_ADMINAddress that's permitted to administrate the code, including deploying updates, and creating pools.
STYLUS_ENDPOINTURL to access the Stylus node.
STYLUS_PRIVATE_KEYPrivate key to use for deployment.
FLU_SEAWATER_FUSDC_ADDRSuper USDC address to use as the base asset for each pool.