freeton_wallet icon indicating copy to clipboard operation
freeton_wallet copied to clipboard

Allow debots to get data from main net smart contracts without deploying them main net

Open NoamDev opened this issue 2 years ago • 7 comments

Some DeBots, need to get data from main net smart contracts, however I don't want to pay deployment fees each time I change something in the debot code. I think there's a need to allow running a debot that will interact with main net without deploying it to main net.

NoamDev avatar Aug 21 '21 20:08 NoamDev

I have three ideas of how to implement this. A) Run the debot without deploying at all. Requires generating contract data and hacking the debot browser to run the debot without downloading it. B) Create a dapp proxy that will pass requests regarding this debot address to tonos se while redirecting all other requests to main.ton.dev. C) Downloading the required contracts from main net in advance and deploy them to tonos se.

NoamDev avatar Aug 21 '21 20:08 NoamDev

ft is currently not able to run debots. The reason is that, to run a debot, it would require to call OCaml from Rust (for example, to give access to wallet keys in the debot), and we haven't tested that with the current OCaml-Rust binding. Yet, the proposed feature would be a "must-have" feature when we start implementing debots.

lefessan avatar Aug 23 '21 07:08 lefessan

I finally decided to give it a try. Here is what I have:

  • Download tonos-cli from https://github.com/lefessan/tonos-cli, branch z-2021-08-23-debot-from-boc
  • Set DEBOT_BOC_PRINT=1 in your environment, run the debot from TONOS SE , it should print the BOC it is using
  • Set DEBOT_BOC=XXX where XXX is the printed BOC value, run the debot on another network, it should print "Using state from DEBOT_BOC" and run the debot with the saved state but on the new network...

lefessan avatar Aug 23 '21 09:08 lefessan

Hey @lefessan, I was finally able to test the hack thoroughly, it has a problem. since you simply always return DEBOT_BOC whenever load_state is called, you are also preventing any getters on other smart contracts from being run locally. I think checking if the address requested is the address of the running debot would solve this problem. It's a good start though:)

NoamDev avatar Aug 29 '21 12:08 NoamDev

Indeed. I have uploaded a new version (should just need to call cargo update before cargo build in tonos-cli same branch). This time, the BOC of the debot is extracted from env variable DEBOT_XXX for address 0:XXX. DEBOT_BOC_PRINT=1 should display the name of that variable.

lefessan avatar Aug 29 '21 13:08 lefessan

And another version:

  • If $DEBOT_SAVE_DIR is defined, it will save the debot state in that directory (under name DEBOT_XXX.boc, where 0:XXX is the debot address)
  • If $DEBOT_LOAD_DIR is defined, it will load the debot state from that directory (from name DEBOT_XXX.boc)

lefessan avatar Aug 29 '21 14:08 lefessan

Latest version of ft automatically supports this behavior (since commit https://github.com/OCamlPro/freeton_wallet/pull/72/commits/b117b280ec4425f8555f6531ae17b5501fa7678b), using ft debot fetch --boc-from NETWORK ADDR (where ADDR is the debot address on NETWORK). It will automatically download the BOC, save it in $DEBOT_LOAD_DIR and set the env var before calling tonos-cli. However, you need to have the patched version of tonos-cli in $HOME/.ft/bin/.

lefessan avatar Sep 06 '21 14:09 lefessan