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

Implement API for sending MINA tokens via Party transactions #281

Closed
MartinMinkov opened this issue Jul 14, 2022 · 4 comments
Closed

Implement API for sending MINA tokens via Party transactions #281

MartinMinkov opened this issue Jul 14, 2022 · 4 comments
Assignees
Labels
rfc Issues that contain some important documentation

Comments

@MartinMinkov
Copy link
Contributor

Description

During an internal discussion of the Tokens RFC, the product team decided to not include an API for transfers of MINA for zkApps. We instead decided to punt on this for a later PR as we wanted more time to decide on an easy to use API.

Once we have a good design in place for tokens, this should be implemented as part of this issue.

@MartinMinkov
Copy link
Contributor Author

RFC

We wish to expose an intuitive and easy-to-use API for supporting sending MINA in party transfers. Adding transactions for MINA payments was discussed in #233 but was cut out of scope and should be implemented in another PR. Here, we propose an API that zkApp developers can use to support transactions with default MINA that is separate from the custom tokens API.

Sending inside a zkApp method

An easy-to-use API should be exposed on the zkApp instance inside a method's execution. For example, a method name such as send can be attached to the this property inside a zkApp method. The send method will take as input an address to send MINA to as the receiver and the amount to send. The following code would be an example of such a method:

@method sendMINATokens(receiverAddress: PublicKey) {
    this.send({
        to: receiverAddress,
        amount: 10e9
    })
}

When the sendMINATokens method is invoked, the method will execute this.send with the specified properties. this.send will construct the parties necessary to represent a valid balance change in both the zkApp balance and the receiverAddress.

Sending using a constructed Party

In addition to exposing a way to send MINA tokens on a zkApp method execution, we would also like to support generating the parties structure by the zkApp developer outside of a zkApp. This can be done by adding a send method to the Party class inside SnarkyJS. This send method will behave similarly to the zkApp version by taking in an address to send to as the receiver and the amount. The following code would be an example of such method:

let party = Party.createSigned(privateKey); // create party from a private key
let party2 = Party.createUnsigned(publicKey); // Can also create a party from a public key but require authorization later before txn is submitted
party.send({ to: someAddress, amount: 10e9 }); // send MINA from the party's account

This way to construct a signed party and specify a send operation can be done inside a transaction block. This means that sending MINA in SnarkyJS isn't dependent on interacting with a zkApp and can be done anywhere a zkApp uses it.

The combination of these two approaches (inside a zkApp and with a signed party) should cover the primary use cases that a zkApp developer needs to send MINA in an easy-to-use way.

Testing

A suite of unit tests should verify that these methods behave correctly. The following test cases should cover these behaviors:
A zkApp successfully sends tokens when invoked in a smart contract method
A zkApp cannot send an amount greater than its current balance
A signed party sends MINA when used inside a transaction block
A signed party cannot send an amount greater than its current balance

@Trivo25
Copy link
Member

Trivo25 commented Aug 3, 2022

clean and easy to use :)

@mitschabaude
Copy link
Collaborator

this looks great to me!

something I think we still have to improve is the naming of Party.createSigned, but that's an independent issue.

@ymekuria
Copy link
Contributor

ymekuria commented Aug 3, 2022

This is a very intuitive API. Nice work Martin!

@mitschabaude mitschabaude added the rfc Issues that contain some important documentation label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfc Issues that contain some important documentation
Projects
None yet
Development

No branches or pull requests

4 participants