Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support contracts sending funds to a Moonlight Account #2284

Merged
merged 3 commits into from
Sep 6, 2024

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented Sep 5, 2024

This PR enables the ability of contracts to send funds directly to a Moonlight account. This facilitates use-cases requiring sending Dusk through a contract to Moonlight accounts, including but not limited to bridging.

To achieve this we add a transfer_to_account function to the transfer contract, taking as argument a TransferToAccount structure, that can be called by a contract to transfer funds to any Moonlight account they wish. Multiple calls may be chained to make contracts that effectively transfer Dusk to several accounts atomically. The function is the equivalent of transfer_to_contract but for accounts, and puts accounts and contracts on the same footing in terms of being able to receive funds directly.

One important asymmetry between accounts and contracts, however, is the capability of contracts to reject the funds sent to them by a contract. With this implementation, accounts do not have this capability.

Copy link

@marta-belles marta-belles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I only left a couple of minor comments.

Although I have a general comment about the tests: if it's not too much trouble, could we add a test that ensures that the code correctly captures scenarios where a transaction should fail? (e.g., attempting to send money from a contract to an account with insufficient funds).

contracts/transfer/src/state.rs Outdated Show resolved Hide resolved
contracts/transfer/tests/transfer.rs Outdated Show resolved Hide resolved
contracts/transfer/tests/transfer.rs Show resolved Hide resolved
@ureeves ureeves force-pushed the transfer-to-account branch 3 times, most recently from a1440fe to 30f4dc7 Compare September 5, 2024 22:29
HDauven
HDauven previously approved these changes Sep 6, 2024
Copy link
Member

@HDauven HDauven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice test suite additions as well

execution-core/src/transfer.rs Outdated Show resolved Hide resolved
execution-core/src/transfer.rs Show resolved Hide resolved
Eduardo Leegwater Simões added 3 commits September 6, 2024 11:13
This structure will be used as an argument to a transfer contract
function allowing for a contract to send Dusk to a Moonlight account.
This will allow us to test that the contract successfully transfers funds
to an account using the "transfer_to_account" function taking a
`TransferToAccount` as argument.
The `transfer_to_account` can be called by contract using the
`TransferToAccount` structure to move some of its funds to a Moonlight
account.
@ureeves ureeves merged commit 6601d70 into master Sep 6, 2024
15 checks passed
@ureeves ureeves deleted the transfer-to-account branch September 6, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants