Giter Site home page Giter Site logo

puzzleswap-contracts's Introduction

PuzzleSwap

Smart contract base for PuzzleSwap.org - Decentralized Exchange built on the Waves blockchain.

The repository contains:

  • megapools folder with a megapool script together with layer2 and boostings,
  • staking folder with PUZZLE staking service and ultrastaking,
  • aggregator folder with aggregator smart contract and REX (SDK to call aggregator onchain),
  • limits with limit orders smart contract,
  • legacy with unused smart contracts,
  • scatches with smart contracts and snippets, which might be used in future.

Special thanks for contributions to:

  • deemru
  • romalf
  • isgeny
  • blahdieblah

Telegram chat: t.me/puzzle_network.

puzzleswap-contracts's People

Contributors

alf1303 avatar blahdieblah avatar deemru avatar roro1303 avatar vlzhr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

puzzleswap-contracts's Issues

Brief audit of `puzzle-custompool.ride`

Only watched swap() function as the most important one:

  • LOW. Strange else construction.
    let feeAssetOutChange = if (newBalanceFeeAsset != unit) then {IntegerEntry("global_"+feeAssetOut.getAssetString()+"_balance", feeAssetOutBalance)} else {StringEntry("hello", "world")}

✅ LOW: No check for payments size == 1.

let pmt = i.payments[0].value()

✅ HIGH: Logic flaw. (see below)

if (IndexIn == IndexOut) then { AmountIn }

✅ CRITICAL: Unexpected key-value overwrites (same assetId possible as stated above)

assetInChange,
assetOutChange,

✅ MEDIUM: Performance. You should throw() as soon as possible to bypass failed transaction status for a user. Not after your service invoke. The best place is just after let AmountOut = ....

let AmountOut = calculateOutAmount(cleanAmountIn, AssetIn, AssetOut, AssetInBalance, AssetOutBalance)
let feeAmountOut = calculateOutAmount(feeAmountIn, AssetIn, feeAssetOut, AssetInBalance, feeAssetOutBalance)
# top up protocol fee
# TODO: top up if feeAsset = PUZZLE
let creatorFee = fraction(feeAmountOut, 1, 10)
let protocolFee = fraction(feeAmountOut, 4, 10)
strict stakingTopUp = reentrantInvoke(Address(base58'3PFTbywqxtFfukX3HyT881g4iW5K4QL3FAS'), "topUpReward", [], [AttachedPayment(feeAssetOut, protocolFee)])
# do all the verifications
# TODO: verification that realPrice <= marketPrice (just in case)
if (AmountOut < minimum) then {
throw("amount to recieve is lower than given one: " + AmountOut.toString())
}

✅ MEDIUM: Performance. Same as above.

else if (isShutdown()) then {
throw("contract is on stop")

✅ TRIVIAL: Unused variables.

let puzzleAssetId = base58'HEB8Qaw9xrWpWs8tHsiATYGBWDBtP2S7kcPALrMu43AS'
let feeAssetIn = AssetIn

✅ HIGH: Wrong calculations. AssetInBalance and feeAssetOutBalance could be changed after first calculateOutAmount(virtual swap happened)

let AmountOut = calculateOutAmount(cleanAmountIn, AssetIn, AssetOut, AssetInBalance, AssetOutBalance)
let feeAmountOut = calculateOutAmount(feeAmountIn, AssetIn, feeAssetOut, AssetInBalance, feeAssetOutBalance)

✅ HIGH: Wrong calculations. If feeAssetOut equals AssetIn or AssetOut (basically one of the assets is USDN) its still MUST be accounted or it will lead to wrong higher interest rates (for USDN).

let newBalanceFeeAsset = if (feeAssetOut != AssetIn && feeAssetOut != AssetOut) then {feeAssetOutBalance - feeAmountOut} else {unit}

  • HIGH: The main idea of fees in specific asset leads to interest rates for LPs only in this specific asset, other assets will not grow at all. But if it is intended, it is ok, but its still RECOMMENDED to document it for users.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.