Sample t1-dApp Flow
Consider Yild, a cross-chain yield optimization dApp. The flow in Docker terms is:
- Yild's developer submits the Docker image with Yild's logic for t1 to pull and run, as a
t1-dappTEE-co-located witht1-core. - The newly started Yild container proceeds to call
initIdentity(callbackOnDeposit)ont1-core, wherecallbackOnDepositis Yild's handler that will determine how to treat deposits (e.g. credit a user, supply to a new yield source, withdraw to a user). - Furthermore, Yild will call
registerCallbackOnTransaction(chainId, address, callback)for each chain where Yild users should be able to withdraw to, with the respective Yild ERC-20 share token contract address and a handler. - Now, upon a new user deposit,
t1-corewill invoke the previously registeredcallbackOnDeposithandler and pass metadata such as chain ID, sender address, or deposited amount to the Yildt1-dappcontainer. - Yild will then run its logic to determine the deposit type ("credit a user"), update its cross-chain global ledger, mint new Yild share tokens to the user, and determine which yield source to direct the new funds to.
- For example, Yild might proceed to call
sendTx(chainId, payload, callback)with a payload constructed to mean opening a bridge intent from the deposit chain to the chain with the best yield source. - Upon
t1-core's subsequent invocation of the Yild-providedcallbackwill the Yildt1-dappdecode the callback parameters to determine whether the transaction was sent correctly, and may decide to retry etc. - Once a solver fills the intent on the target chain to Yild's initialized identity, will
t1-coreinvokecallbackOnDeposit, as always—but this time, Yild will decode the callback parameters to interpret this deposit as a bridge (cross-chain optimization) transaction. It will therefore NOT credit these funds to a user, but instead callsendTxagain, with a payload instructingt1-coreto supply the newly arrived funds to a yield source on the new chain. - If a user wishes to withdraw, they will burn their Yild share tokens. This will result in
t1-coreinvoking the callback ont1-dappfrom the previously registered watcher (viaregisterCallbackOnTransaction) on said share token address. Therefore,t1-dappwill be able to process the withdrawal request, update its ledger, and usesendTxcalls to withdraw the calculated amount of funds from a yield source, bridge them if needed, and finally send them to the requesting user.