Code Monkey home page Code Monkey logo

waves-exchange-anystakeprotocol's Introduction

AnyStakeProtocol

Any Stake Protocol is designed to unify callable methods and data state between different 'staking-like' dapps

Table of contents

AnyStake Interface

@Callable(i)
func adminRegisterAsset() = {}
 
# payment in $baseAssetId
@Callable(i)
func submitPut() = {}
 
# payment in $shareAssetId
@Callable(i)
func submitGet() = {}
 
@Callable(i)
func executePut(baseTokenStr: String, userAddressStr: String, txId: String) = {}
 
@Callable(i)
func executeGet(baseTokenStr: String, userAddressStr: String, txId: String) = {}
 
# if amount > 0 then payment in $baseAssetId
# if amount < 0 then empty payments
# if amount = 0 then error
@Callable(i)
func topUpBalance(baseAssetId: String, amount: Int) = {}
 
@Callable(i)
func currentSysParamsREST(baseTokenId: String)={}
# includes current price

AnyStake Data State Specification

Internal Asset Id

Because of key length restriction (max 100 symbols) we need to introduce $internalBaseAssetId and bidirectional mappings between it and real assetId

Num Key Type Optional? Format and Description
1 %s%s%d__mappings__internal2baseAssetId__${internalBaseAssetId} String No Simple
2 %s%s%s__mappings__baseAsset2internalId__${baseAssetId} String No Simple

Config V_01

Type Format
Key %s%s%s__config__asset__${realBaseAssetId}
Value %s%d%d%d%d__${shareAssetId}__${internalBaseAssetId}__${decimalsMultBothTokens}__${decimalsMultPrice}__${getDelayBlocks}__...dataExtensions...

Extensions:

submitPut operation V_01

Type Format
Key %s%d%s%s__P__${internalBaseAssetId}__${userAddress}__${txId}
Value %s%d%d%d%d%d%d%d__${status}__${inBaseTokensAmount}__${price}__${outShareTokensAmount}__${startHeight}__${startTimestamp}__${endHeight}__${endTimestamp}...dataExtensions...

Extensions:

submitGet operation V_01

Type Format
Key %s%d%s%s__G__${internalBaseAssetId}__${userAddress}__${txId}
Value %s%d%d%d%d%d%d%d__${status}__${inShareTokensAmount}__${price}__${outBaseTokensAmount}__${startHeight}__${startTimestamp}__${endHeight}__${endTimestamp}...dataExtensions...

Extensions:

Other information

Num Key Type Optional? Format Description
1 %s%s%s__mappings__share2baseAssetId__${shareAssetId} String NO Simple mapping between ${shareAssetId} and real ${baseAssetId}
2 %s%s%s__mappings__baseAsset2shareId__${baseAssetId} String NO Simple mapping between ${baseAssetId} and real ${shareAssetId}
3 %s%s%d%s__total__locked__${internalBaseAssetId}__${userAddress} String YES %d%d__${sharedTokenAmount}__${baseTokenAmount}
4 %s%s%d__total__locked__${internalBaseAssetId} String NO %d%d__${sharedTokenAmount}__${baseTokenAmount}
5 %s%s%d%d%d__price__history__${intrenalBaseAssetId}__${height}__${timestamp} Integer YES Simple It is difficult to use ${decimalsMult} from asset config because assets with 0 decimals will have bad price (300/200=1.5 ~ 1) ${decimalsMultPrice} has been introduce to resolve this problem
6 %s%s%d__price__last__${internalBaseAssetId} Integer NO Simple
7 %s%s%d__shutdown__put__${internalBaseAssetId} Boolean Yes Simple. If true then put operation is blocked

LP Product Implementation

Mainnet Contract

Testnet Contract

LP submitPut and submitGet

Data State Extensions

No extensions, see corresponding

Assumptions

  • both one step operations (No need to send claim/execute/withdraw by user)
  • ${status} - always FINISHED
  • ${startHeight} == ${endHeight}
  • ${startTimestamp} == ${endTimestamp}

ALGO Medium Product Implementation

Mainnet Contract

Testnet Contract

ALGO config

Data State Extensions

Type Format
Key Config V_01.key
Value Config V_01.val __${TopupIntervalInBlocks}__${TopupMaxNegativePart}__${TopupManagerAddress}__${SubmitLimitsBaseMax}__${SubmitLimitsBaseReset}__${SubmitLimitsShareMax}__${SubmitLimitsShareReset}

ALGO submitPut

Data State Extensions

Type Format
Key submitPut V_01.key
Value submitPut V_01.val__${topUpIdxUnlock}

Assumptions

  • two step operation
  • the following data is available only after corresponding executeXxx call
    • ${endHeight}
    • ${endTimestamp}
    • ${price}
    • ${outShareTokensAmount}

ALGO submitGet

Data State Extensions

Type Format
Key submitGet V_01.key
Value submitGet V_01.val__${topUpIdxUnlock}

Assumptions

  • two step operation
  • the following data is available only after corresponding executeXxx call
    • ${endHeight}
    • ${endTimestamp}
    • ${price}
    • ${outBaseTokensAmount}

ALGO Aggressive Product Implementation

Same logic as ALGO Medium but more risks

Mainnet Contract

Testnet Contract

LAMBO Product Implementation

Mainnet Contract

Testnet Contract

LAMBO config

same as ALGO config

LAMBO submitPut

same as ALGO submitPut

LAMBO submitGet

with one exception as ALGO submitGet:

  • ${endHeight} is available right away after submitGet and calculated as ${currentBlockchainHeight} + .${getDelayBlocks} (see Config V_01). It is used to block operation till this height.

ALGO Conservative Product Implementation

Similar logic as ALGO Medium

Mainnet Contract

Testnet Contract

waves-exchange-anystakeprotocol's People

Contributors

amurdev avatar cringe013 avatar

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.