DLUX Smarter Token and DEX

in #utopian-io6 years ago

Do I need a flowchart?

One of the challenges with starting your own Blockchain/Decentralized Autonomous Organization, "DAO", are entry points. How do you trade something you have... like bitcoin for something you want... like a DLUX token?

One of the cooler things about starting an organization on an established chain like Steem or Ethereum are the existing avenues of getting capital to the project. However, except for funding contracts directly you often have to wait to be listed on an external exchange before you can have a Decentralized Exchange, "DEX", or even an alternative centralized exchange like Blocktrades or Coinbase.

I programed a consensus algorithm for the Decentralized Limitless User eXperience, "DLUX", token and and DAO using @shredz7's STEEM-STATE.

This algorithm will keep track of each nodes API performance, and as such can do some pretty cool things externally. This enables these nodes to reach consensus among things like if a user has initiated a transaction. Which allows the network of nodes to keep track of escrow agent performance.

Which means we can host a decentralized exchange with out maintaining much counter party risk.

So here is how this works on this holographic chain:

Alice has 100 DLUX and wants to sell it for 10 STEEM. Alice signs a message(in reality presses confirm).

This is the extremely detailed version of the trust process and internal workings of the mechanism:

As a node is participating in consensus it is reading every transaction that happens on the blockchain. Several of these transactions will trigger a state change in a deterministic way. One of the transactions it's looking out for is a custom json transaction which doesn't show up on standard Steem feeds.

This custom json has a function name like 'dlux_token_dex_sbd_buy' which tells all the participants that this transaction needs further scrutiny. It says Alice would like to buy 10 STEEM for 100 DLUX, and that she'll take a partial fill on this order.

processor.on('dex_steem_sell', function(json, from) {
    var buyAmount = parseInt(parseFloat(json.steem) * 1000)
    if (json.dlux >= state.balances[from]){
      var txid = 'DLUX' + hashThis(from + current)
      state.dex.steem.sellOrders.push({txid, from: from, steem: buyAmount, sbd: 0, amount: json.amount, rate:parseInt((json.dlux)*10000/(buyAmount)), block:current, partial: json.partial || true})
      state.balances[from] -= json.amount
      if(state.contracts[from]) {
        state.contracts[from][txid] = state.dex.steem.sellOrders[state.dex.steem.sellOrders.length -1]
      } else {
        state.contracts[from] = {[txid]:state.dex.steem.sellOrders[state.dex.steem.sellOrders.length -1]}
      }
      sortSellArray (state.dex.steem.sellOrders, 'rate')
      console.log(`@${from} has placed an order to sell ${json.dlux} for ${json.steem} STEEM`)
    }
  });

All the nodes start to formulate a contract. They deduct 100 DLUX from Alice's balance and place it into the contract. This contract is placed into an order book array, and also stored in a table/object.

Bob is browsing and his UI shows him that a contract has just been posted and he likes the rate. He clicks on the contract but only has 5 STEEM. So he signs an escrow transaction. His UI has a list of each nodes escrow rating and fees, and chooses the most reasonable option. This transaction goes from Bob to Alice, if Charlie the escrow agent, and Alice both approve.

He signs that with a tap. The nodes now see this escrow transaction and match it to the contract. They all follow the same instructions to build a new Contract for 50 DLUX, and issue instructions for Charlie to sign the approval message.

When the approval message comes through all nodes remove the instruction from their queue, and maintain state in a deterministic way... even while issuing instructions only one set of keys has the authority to sign.

Alice then only has to claim her 5 STEEM by pressing a button.

Charlie may have gotten paid a small fee for his resource credit use.

However... While this sounds a little complex. Issuing a contract from the Steem side is a little trickier. There is no mechanism to have Steem proper generate an open ended contract for escrow.

So Alice has a change of heart. She issues a transaction to clear her order book and all the nodes remove the contract. if somebody sends an escrow transaction and the contract is no longer there the agent will receive instructions to sign a release.

Alice does want back in though. Nobody is selling though... She sets her new price and presses a button. This time her UI has selected two agents from the network. Her escrow transaction is now going to David', using Charlie as the agent.

You can see once the network has identified the type of transactions it generates to required operations to complete the contract and when the contract is bought... can be faithfully executed.

processor.onOperation('escrow_transfer', function(json,from){
    var op, dextx, contract, isAgent
    try {
      dextx = json.json_meta.dlux_dex
      contract = state.contracts[json.to][dextx.contract]
      isAgent = state.markets.node[json.agent].report.escrow
      isDAgent = state.markets.node[json.to].report.escrow
    } catch(e) {
      return;
    }
    if (isAgent && isDAgent && dextx){//two escrow agents to fascilitate open ended transfer with out estblishing steem/sbd bank //expiration times??
      var txid = 'DLUX' + hashThis(from + current)
      state.balances[json.from] -= dextx.dlux
      var auths = [[json.agent,
        [
          "escrow_approve",
          {
            "from": json.from,
            "to": json.to,
            "agent": json.agent,
            "who": json.agent,
            "escrow_id": json.escrow_id,
            "approve": true
        }
      ]],[json.to,
        [
          "escrow_approve",
          {
            "from": json.from,
            "to": json.to,
            "agent": json.agent,
            "who": json.to,
            "escrow_id": json.escrow_id,
            "approve": true
          }
        ]],
      ['virtual_escrow',
        {
          from: json.to,
          memo: txid,
          amount: dextx.steem || dextx.sbd,
          dlux: dextx.dlux,
        }
    ]]
      var reject =[json.to,
        [
          "escrow_release",
          {
            "from": json.from,
            "to": json.to,
            "agent": json.agent,
            "who": json.to,
            "receiver": json.from,
            "escrow_id": json.escrow_id,
            "sbd_amount": json.sbd_amount,
            "steem_amount": json.steem_amount
          }
        ]]
      if(json.steem_amount && dextx.dlux && typeof dextx.dlux === 'number') {
        console.log(`@${json.from} signed a ${json.steem_amount.amount} STEEM buy order`)
        state.dex.steem.buyOrders.push({txid, from: json.from, steem: json.steem_amount.amount, sbd: 0, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.steem_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject})
        if (state.contracts[json.from]){
          state.contracts[json.from][txid] = {txid, from: json.from, steem: json.steem_amount.amount, sbd: 0, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.steem_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject}
        } else {
          state.contracts[json.from] = {txid, from: json.from, steem: json.steem_amount.amount, sbd: 0, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.steem_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject}
        }
      } else if (json.sbd_amount && dextx.dlux && typeof dextx.dlux === 'number'){
        console.log(`@${json.from} signed a ${json.sbd_amount.amount} SBD buy order`)
        state.dex.sbd.buyOrders.push({txid, from: json.from, steem: 0, sbd: json.sbd_amount.amount, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.sbd_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject})
        if (state.contracts[json.from]){
          state.contracts[json.from][txid] = {txid, from: json.from, steem: 0, sbd: json.sbd_amount.amount, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.sbd_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject}
        } else {
          state.contracts[json.from] = {txid:{txid, from: json.from, steem: 0, sbd: json.sbd_amount.amount, amount: dextx.dlux , rate:parseInt((dextx.dlux)*10000/json.sbd_amount.amount), block:current, escrow_id:json.escrow_id, agent:json.agent, fee:json.fee.amount, partial:false, auths, reject}
        }
      }
    }

Bob decides to cash in on the quick buck and issues a transaction to fill the contract. Sending 40 DLUX for 5 STEEM. The tokens immediately get transferred to Alice, and a few seconds later both Charlie and David have released the funds, which 3 sends later David's node fulfills the instructions and send's Bob his 5 STEEM.

This can be programmed with additional fees of course..., it's decentralized, smart, rated, and incentivized and most importantly, trustless.

In addition to this 3 and 4 party escrow service. The DAO will take care of all the business. Nodes can have programmatic access to git pull request approval. Meaning a contract can be made, funded, voted on, and implemented that auto forks the chain...

Did I mention every 5 minutes the state is signed and saved to IPFS? A p2p network like bittorrents except the content is stored by hashing its content. Meaning you can verify state stored in public is state signed on the blockchain, and with nothing more than a hash value can start replaying your node from no more than 5 minutes ago.

While your gone your transactions stay pending, you sign them when you return... everybody stays happy and in sync.

A STEEM/SBD/DLUX bridge is cool, but using external API these nodes can also inspect ETH and BITCOIN blocks for relevant transactions. These can be reported and consensus reached. At which point relevant instructions can occur in a deterministic way.

This is a DAO. An organization that can run itself, pay itself, govern itself... and build itself better iteration after iteration.

It does a ton more... but this particular thing I'm pretty excited about and wanted to share.

DLUX ICO Continues

Send Steem to @robotolux to participate in our ICO. Our go live date has been pushed to block 29540000 ~

Jan 15th... My Birthday! When tokens purchased become liquid.

Delegation to @dlux-io wlll also earn rewards!

Follow along on github https://github.com/dluxio and join me on discord. https://discord.gg/Beeb38j

Sort:  

Im not a coder, but actually this "review" of the mechanism not complicated, at least, i understand it. Except the code-lines, of course, that seems a weird magic for me :)

So i think, this is a pro work!

And that 5 minute sync time sounds very impressive.

The real magic is getting the two people in the middle of the transaction to agree to it across a voluntary network of staked participants. The software can facilitate it. It can also be applied to things people are willing to exchange for tokens, insurance to transfer of physical assets would be all that's needed for chain of custody type transactions and even blind auctions.

Coin Marketplace

STEEM 0.15
TRX 0.16
JST 0.028
BTC 67715.17
ETH 2423.95
USDT 1.00
SBD 2.37