Proper Design pattern for FA deposit / withdraw #296
-
Discord user IDNo response Describe your question in detail.I am trying to design a module which accepts FAs and preforms operations with them... to do so I need entry scripts... to make these entry scripts I need to withdraw / deposit FAs, however I've noticed that this is where there is a split in behaviour: If I understand correctly there a couple different flows for FAs for this deposit / withdraw concern:
My question is this: as a dapp creator, how should I plan for this? I just want to be able to deposit / withdraw FAs, and ideally would like a unified code path to do so (I thought this would be What error, if any, are you getting?No response What have you tried or looked at? Or how can we reproduce the error?No response Which operating system are you using?macOS Which SDK or tool are you using? (if any)TypeScript SDK Describe your environment or tooling in detailNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Just confirming that you've seen our docs on this topic: https://aptos.dev/en/build/smart-contracts/fungible-asset. We'll follow up later to make sure we answer all your questions here + update the docs accordingly! |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how you landed on your error. I read through the code, In general, directly interacting with In short, I would use |
Beta Was this translation helpful? Give feedback.
-
Addressing Your QuestionBtw calling directly into
The sanity check will pass here, since we set Separate Consideration (important) - Move VMHowever... when you're creating the module that defines and initializes the fungible asset, an issue arises when the VM call stack looks like this:
This breaks the reentrancy assumptions in Move. You get this error:
The solution is: Here's an example in FACoin. Note that ^this second half doesn't directly address the question in this discussion, but rather points towards a more general consideration with dispatchable fungible assets. |
Beta Was this translation helpful? Give feedback.
Addressing Your Question
Btw calling directly into
primary_fungible_store::withdraw
should not give this error. Can you double check/send some code snippets?pfs::withdraw
->dfa::withdraw
->fa::withdraw_sanity_check
The sanity check will pass here, since we set
abort_on_dispatch
as false.Separate Consideration (important) - Move VM
However... when you're creating the module that defines and initializes the fungible asset, an issue arises when the VM call stack looks like this:
your_module::transfer
->pfs::transfer
->pfs::withdraw
->dfa::withdraw
(sanity check will pass) ->dfa::dispatchable_withdraw
->your_module::withdraw
(noticeyour_module
is already on the stack)This breaks th…