dToken is an extension of the DIP20 fungible token standard, it is fully compatible with DIP20 but with the ability to describe money flows. The dToken standard is the core that enables capital efficient realtime finance on the Internet Computer.

Specification

dToken standard is extended from the DIP20 standard, we describe the dToken specific changes in the following.

1. Data Structures

  1. Constant rate flow:

    type Flow = record {
      settleTime : nat64;
      deposit : nat;
      sender : principal;
      startTime : nat64;
      flowRate : nat;
      receiver : principal;
      flowType : FlowType;
    };
    
  2. Request & response types:

    type FlowType = variant {
    	Constant;
    };
    type UserFlows = record {
      sendFlows : vec Flow;
      receiveFlows : vec Flow;
    };
    type UserInfo = record {
    	balance: Nat;
      liquidationDate : nat64;
      sendFlows : vec Flow;
      receiveFlows : vec Flow;
      flowRate : int;
    };
    type TxError = variant {
      InsufficientAllowance;
      InsufficientBalance;
      ErrorOperationStyle;
      Unauthorized;
      LedgerTrap;
      ErrorTo;
      Other : text;
      BlockUsed;
      AmountTooSmall;
    };
    type TxReceipt = Result<Nat, TxError>;
    

2. Interfaces

Update calls

createFlow

Create a money flow, must specify flow type(now only supports constant rate flow), receiver and flow rate, returns the flow id.

public shared(msg) func createFlow(type: FlowType, sender: Principal, receiver: Principal, flowRate: Nat) -> Result<Text, Text>

deleteFlow

Delete a money flow, specify the flow id.

public shared(msg) func deleteFlow(id: Text) -> TxReceipt

updateFlow

Update the configuration of a flow, specify flow id and new flow rate.

public shared(msg) func updateFlow(id: Text, flowRate: Nat) -> TxReceipt

mint

For non-native dTokens, mint will help wrap the underlying DIP20 token to its dToken form, once called, it will first transferFrom amount of underlying tokens to this dToken canister and mint amount of dTokens to user to. For native dTokens, its behavior is the same as DIP20 mint, mint amount of new tokens and increase the totalSupply.