Long Tail contracts

Long Tail is Arbitrum's cheapest and most rewarding AMM.

Deployments

Superposition Testnet

Superposition RPC

AMM contract deployments

Deployment nameDeployment address
Long Tail AMM0x839c5cf32d9Bc2CD46027691d2941410251ED557
Long Tail NFT manager0xC96F6A050382d4aA73fd91f7A4D02aB8E5654338

Useful testing token deployments

Deployment nameDeployment address
fUSDC0xA8EA92c819463EFbEdDFB670FEfC881A480f0115
WETH0xde104342B32BCa03ec995f999181f7Cf1fFc04d7
USDC0x6437fdc89cED41941b97A9f1f8992D88718C81c5
WSPN0x22b9fa698b68bBA071B513959794E9a47d19214c
Access graph

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

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

If more bytes are in the error, then the issue was produced by the ERC20 token. Convert any error types to their keccak form to see. For example, an allowance error might be hard to unpack, and it'll be several bytes.g

Security

Security instructions

Contributors

Contributors

Building

Superposition AMM 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 either on-chain with the live Ethers-powered environment (at the time of writing, there is no native on-chain testing with a forking suite), or via a hosted test using cargo features with the testing flag.

Testing dependencies

NameSource
NodeWebsite
NPMWebsite
Nitro testnodeRepo

Testing the local environment using Ethers is the process of:

  1. Deploying a local Stylus testnode.
  2. Running the ethers test suite.

Running the Ethers test suite is as simple as running ./tests.sh, which will also run tests on the host environment with stubbed out ERC20.

Running a local testnode

  1. Clone the Nitro repo with submodules on the stylus branch.
  2. Run the testing script ./test-node.bash --init. This will run the Stylus suite using Docker Compose, and make it available locally.

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.