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

Add Third Party Feepayer #424

Merged
merged 90 commits into from
Jun 20, 2023
Merged

Add Third Party Feepayer #424

merged 90 commits into from
Jun 20, 2023

Conversation

ymekuria
Copy link
Collaborator

@ymekuria ymekuria commented Jun 2, 2023

closes #129 #435 #429

Background

Currently, the zkApp cli creates a keypair for the zkApp account after running the zk config command. The cli assumes that this zkApp account has funds to pay fees, and uses it as fee payer.

There are two reasons why the flow above is insufficient:

Incompatible with permissions

  • A zkApp is deployed with send: proof permissions by default which means you need to provide a proof (of running a smart contract method) as authorization to send MINA away from the zkApp account.
  • A fee payer tries to pay the fee using signature authorization (proofs are not supported). If the zkApp account is used as fee payer after deployment, the transaction will get rejected because the permissions of the account will be violated. This currently breaks all re-deployments and the interact.ts script in the template project.

Unnecessary work to fund zkApp

  • Having to fund each zkApp account before deploying, just for using it to pay fees, is cumbersome.
  • It would save time to just have a developer account, which is funded and can always pay fees immediately.

Approach

After entering zk config, new steps are added to create or select a fee payer account.

✔ Create a name (can be anything): · berkeley
✔ Set the Mina GraphQL API URL to deploy to: · https://proxy.berkeley.minaexplorer.com/graphql
✔ Set transaction fee to use when deploying (in MINA): · .1
? Choose an account to pay transaction fees: …
❯ Recover fee payer account from an existing base58 private key
  Create a new fee payer key pair

The first time a user enters zk config, they will be shown two option prompts.

❯ Recover fee payer account from an existing base58 private key
  Create a new fee payer key pair

After selecting one of these options, there is an additional step to add an alias for this fee payer account.

? Create an alias for this account :

This base58 private key can be exported from a wallet or from any other existing account.

Every other time a use runs zk config, an option will be shown to use a stored account as a fee payer and an option to use a different account.

❯ Use stored account dev (public key: B62qkw6ZCxKgMkxegegq8Z6mGibvsMUc5TopqwztpkseU7n2cDF4iEo)
  Use a different account (select to see options)

If a user selects to use a different account they will see the previous options to recover a fee payor account or create a new one.

  Recover fee-payer account from an existing base58 private key
❯ Create a new fee payer key pair

If a user has more than one fee payor account stored on their machine, an additional option is shown to choose another saved fee payer

   Recover fee-payer account from an existing base58 private key
   Create a new fee payer key pair
  ❯ Choose another saved fee payer
? Choose another saved fee payer: …
❯ berkeley
  dev
  mainnet

The fee payer alias and corresponding keypair is stored globally on a users machine in the form of <os specific cache directory>/zkapp-cli/keys/<fee payor alias>.json. These fee payer accounts can be used across multiple projects.

The feepayerKeyPath and feepayerAliasName are also added to the config.json.

{

  "version": 1,
  "deployAliases": {
    "berkeley": {
      "url": "https://berkeley.minascan.io/graphql",
      "keyPath": "keys/berkeley.json",
      "feepayerKeyPath": "<os specific cache directory>/zkapp-cli/keys/dev.json",
      "feepayerAlias": "dev",
      "fee": ".1"
    }
  }
}

The interact.ts script in the project template was also updated to work with the third party fee payer.

See the discussion for more details.

ymekuria and others added 30 commits May 5, 2023 11:31
@shimkiv shimkiv self-requested a review June 16, 2023 14:56
Copy link
Member

@shimkiv shimkiv left a comment

Choose a reason for hiding this comment

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

Looks good now! Thank you.
I've added couple more minor notes though.

templates/project-ts/src/interact.ts Outdated Show resolved Hide resolved
templates/project-ts/src/interact.ts Outdated Show resolved Hide resolved
templates/project-ts/src/interact.ts Outdated Show resolved Hide resolved
src/lib/prompts.js Outdated Show resolved Hide resolved
@ymekuria ymekuria merged commit a1f7ac4 into main Jun 20, 2023
@ymekuria ymekuria deleted the feature/third-party-feepayer branch June 21, 2023 17:00
@barriebyron barriebyron mentioned this pull request Jun 28, 2023
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.

Add third-party fee payer during deployment
4 participants