zkcloudworker 0.18.2 → 0.18.5
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +2 -4
- package/dist/ts/cloud/config.js.map +1 -0
- package/dist/ts/cloud/index.js.map +1 -0
- package/dist/ts/cloud/networks.js.map +1 -0
- package/dist/ts/cloud/utils/base64.js.map +1 -0
- package/dist/ts/cloud/utils/graphql.js.map +1 -0
- package/dist/ts/cloud/utils/index.js.map +1 -0
- package/dist/ts/cloud/utils/utils.js.map +1 -0
- package/dist/ts/cloud/worker/cloud.js.map +1 -0
- package/dist/ts/cloud/worker/index.js.map +1 -0
- package/{lib → dist}/ts/cloud/worker/job.js.map +1 -1
- package/{lib → dist}/ts/cloud/worker/task.js.map +1 -1
- package/dist/ts/cloud/worker/transaction.js.map +1 -0
- package/dist/ts/cloud/worker/worker.js.map +1 -0
- package/dist/ts/index.js.map +1 -0
- package/dist/ts/mina/api/api.js.map +1 -0
- package/dist/ts/mina/index.js.map +1 -0
- package/dist/ts/mina/local/local.js.map +1 -0
- package/dist/ts/mina/storage/index.js.map +1 -0
- package/dist/ts/mina/storage/ipfs.js.map +1 -0
- package/dist/ts/mina/storage/pinata.js.map +1 -0
- package/dist/ts/mina/storage/storage.js.map +1 -0
- package/dist/ts/mina/token/FungibleToken.js.map +1 -0
- package/dist/ts/mina/token/FungibleTokenAdmin.js.map +1 -0
- package/dist/ts/mina/token/api.js.map +1 -0
- package/dist/ts/mina/token/index.js.map +1 -0
- package/dist/ts/mina/token/vk.js.map +1 -0
- package/{lib → dist}/ts/mina/token/whitelist.d.ts +1 -1
- package/{lib/web → dist/ts}/mina/token/whitelist.js +5 -1
- package/dist/ts/mina/token/whitelist.js.map +1 -0
- package/dist/ts/mina/transactions/account.js.map +1 -0
- package/dist/ts/mina/transactions/blockberry.js.map +1 -0
- package/dist/ts/mina/transactions/chain.js.map +1 -0
- package/dist/ts/mina/transactions/index.js.map +1 -0
- package/dist/ts/mina/transactions/nonce.js.map +1 -0
- package/dist/ts/mina/transactions/send.js.map +1 -0
- package/dist/ts/mina/transactions/tiny-contract.js.map +1 -0
- package/dist/ts/mina/transactions/transaction.js.map +1 -0
- package/dist/ts/mina/transactions/txstatus.js.map +1 -0
- package/dist/ts/mina/utils/base64.js.map +1 -0
- package/dist/ts/mina/utils/fee.js.map +1 -0
- package/dist/ts/mina/utils/fetch.js.map +1 -0
- package/dist/ts/mina/utils/fields.js.map +1 -0
- package/dist/ts/mina/utils/index.js.map +1 -0
- package/dist/ts/mina/utils/indexed-map.js.map +1 -0
- package/dist/ts/mina/utils/mina.js.map +1 -0
- package/dist/ts/mina/verification/index.js.map +1 -0
- package/dist/ts/mina/verification/verification.js.map +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/cloud/config.js.map +1 -0
- package/dist/web/cloud/index.js.map +1 -0
- package/dist/web/cloud/networks.js.map +1 -0
- package/dist/web/cloud/utils/base64.js.map +1 -0
- package/dist/web/cloud/utils/graphql.js.map +1 -0
- package/dist/web/cloud/utils/index.js.map +1 -0
- package/dist/web/cloud/utils/utils.js.map +1 -0
- package/dist/web/cloud/worker/cloud.js.map +1 -0
- package/dist/web/cloud/worker/index.js.map +1 -0
- package/{lib → dist}/web/cloud/worker/job.js.map +1 -1
- package/{lib → dist}/web/cloud/worker/task.js.map +1 -1
- package/dist/web/cloud/worker/transaction.js.map +1 -0
- package/dist/web/cloud/worker/worker.js.map +1 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mina/api/api.js.map +1 -0
- package/dist/web/mina/index.js.map +1 -0
- package/dist/web/mina/local/local.js.map +1 -0
- package/dist/web/mina/storage/index.js.map +1 -0
- package/dist/web/mina/storage/ipfs.js.map +1 -0
- package/dist/web/mina/storage/pinata.js.map +1 -0
- package/dist/web/mina/storage/storage.js.map +1 -0
- package/dist/web/mina/token/FungibleToken.js.map +1 -0
- package/dist/web/mina/token/FungibleTokenAdmin.js.map +1 -0
- package/dist/web/mina/token/api.js.map +1 -0
- package/dist/web/mina/token/index.js.map +1 -0
- package/dist/web/mina/token/vk.js.map +1 -0
- package/{lib → dist}/web/mina/token/whitelist.d.ts +1 -1
- package/{lib/ts → dist/web}/mina/token/whitelist.js +5 -1
- package/dist/web/mina/token/whitelist.js.map +1 -0
- package/dist/web/mina/transactions/account.js.map +1 -0
- package/dist/web/mina/transactions/blockberry.js.map +1 -0
- package/dist/web/mina/transactions/chain.js.map +1 -0
- package/dist/web/mina/transactions/index.js.map +1 -0
- package/dist/web/mina/transactions/nonce.js.map +1 -0
- package/dist/web/mina/transactions/send.js.map +1 -0
- package/dist/web/mina/transactions/tiny-contract.js.map +1 -0
- package/dist/web/mina/transactions/transaction.js.map +1 -0
- package/dist/web/mina/transactions/txstatus.js.map +1 -0
- package/dist/web/mina/utils/base64.js.map +1 -0
- package/dist/web/mina/utils/fee.js.map +1 -0
- package/dist/web/mina/utils/fetch.js.map +1 -0
- package/dist/web/mina/utils/fields.js.map +1 -0
- package/dist/web/mina/utils/index.js.map +1 -0
- package/dist/web/mina/utils/indexed-map.js.map +1 -0
- package/dist/web/mina/utils/mina.js.map +1 -0
- package/dist/web/mina/verification/index.js.map +1 -0
- package/dist/web/mina/verification/verification.js.map +1 -0
- package/package.json +32 -20
- package/src/cloud/config.ts +10 -0
- package/src/cloud/index.ts +4 -0
- package/src/cloud/networks.ts +130 -0
- package/src/cloud/utils/base64.ts +87 -0
- package/src/cloud/utils/graphql.ts +252 -0
- package/src/cloud/utils/index.ts +3 -0
- package/src/cloud/utils/utils.ts +79 -0
- package/src/cloud/worker/cloud.ts +326 -0
- package/src/cloud/worker/index.ts +5 -0
- package/src/cloud/worker/job.ts +123 -0
- package/src/cloud/worker/task.ts +45 -0
- package/src/cloud/worker/transaction.ts +12 -0
- package/src/cloud/worker/worker.ts +62 -0
- package/src/index.ts +2 -0
- package/src/mina/api/api.ts +597 -0
- package/src/mina/index.ts +8 -0
- package/src/mina/local/local.ts +651 -0
- package/src/mina/storage/index.ts +3 -0
- package/src/mina/storage/ipfs.ts +20 -0
- package/src/mina/storage/pinata.ts +52 -0
- package/src/mina/storage/storage.ts +55 -0
- package/src/mina/token/FungibleToken.ts +316 -0
- package/src/mina/token/FungibleTokenAdmin.ts +95 -0
- package/src/mina/token/api.ts +182 -0
- package/src/mina/token/index.ts +5 -0
- package/src/mina/token/vk.ts +42 -0
- package/src/mina/token/whitelist.ts +178 -0
- package/src/mina/transactions/account.ts +57 -0
- package/src/mina/transactions/blockberry.ts +166 -0
- package/src/mina/transactions/chain.ts +1 -0
- package/src/mina/transactions/index.ts +8 -0
- package/src/mina/transactions/nonce.ts +120 -0
- package/src/mina/transactions/send.ts +186 -0
- package/src/mina/transactions/tiny-contract.ts +9 -0
- package/src/mina/transactions/transaction.ts +255 -0
- package/src/mina/transactions/txstatus.ts +26 -0
- package/src/mina/utils/base64.ts +34 -0
- package/src/mina/utils/fee.ts +11 -0
- package/src/mina/utils/fetch.ts +126 -0
- package/src/mina/utils/fields.ts +39 -0
- package/src/mina/utils/index.ts +6 -0
- package/src/mina/utils/indexed-map.ts +169 -0
- package/src/mina/utils/mina.ts +175 -0
- package/src/mina/verification/index.ts +1 -0
- package/src/mina/verification/verification.ts +23 -0
- package/lib/ts/cloud/config.js.map +0 -1
- package/lib/ts/cloud/index.js.map +0 -1
- package/lib/ts/cloud/networks.js.map +0 -1
- package/lib/ts/cloud/utils/base64.js.map +0 -1
- package/lib/ts/cloud/utils/graphql.js.map +0 -1
- package/lib/ts/cloud/utils/index.js.map +0 -1
- package/lib/ts/cloud/utils/utils.js.map +0 -1
- package/lib/ts/cloud/worker/cloud.js.map +0 -1
- package/lib/ts/cloud/worker/index.js.map +0 -1
- package/lib/ts/cloud/worker/transaction.js.map +0 -1
- package/lib/ts/cloud/worker/worker.js.map +0 -1
- package/lib/ts/index.js.map +0 -1
- package/lib/ts/mina/api/api.js.map +0 -1
- package/lib/ts/mina/index.js.map +0 -1
- package/lib/ts/mina/local/local.js.map +0 -1
- package/lib/ts/mina/storage/index.js.map +0 -1
- package/lib/ts/mina/storage/ipfs.js.map +0 -1
- package/lib/ts/mina/storage/pinata.js.map +0 -1
- package/lib/ts/mina/storage/storage.js.map +0 -1
- package/lib/ts/mina/token/FungibleToken.js.map +0 -1
- package/lib/ts/mina/token/FungibleTokenAdmin.js.map +0 -1
- package/lib/ts/mina/token/api.js.map +0 -1
- package/lib/ts/mina/token/index.js.map +0 -1
- package/lib/ts/mina/token/vk.js.map +0 -1
- package/lib/ts/mina/token/whitelist.js.map +0 -1
- package/lib/ts/mina/transactions/account.js.map +0 -1
- package/lib/ts/mina/transactions/blockberry.js.map +0 -1
- package/lib/ts/mina/transactions/chain.js.map +0 -1
- package/lib/ts/mina/transactions/index.js.map +0 -1
- package/lib/ts/mina/transactions/nonce.js.map +0 -1
- package/lib/ts/mina/transactions/send.js.map +0 -1
- package/lib/ts/mina/transactions/tiny-contract.js.map +0 -1
- package/lib/ts/mina/transactions/transaction.js.map +0 -1
- package/lib/ts/mina/transactions/txstatus.js.map +0 -1
- package/lib/ts/mina/utils/base64.js.map +0 -1
- package/lib/ts/mina/utils/fee.js.map +0 -1
- package/lib/ts/mina/utils/fetch.js.map +0 -1
- package/lib/ts/mina/utils/fields.js.map +0 -1
- package/lib/ts/mina/utils/index.js.map +0 -1
- package/lib/ts/mina/utils/indexed-map.js.map +0 -1
- package/lib/ts/mina/utils/mina.js.map +0 -1
- package/lib/ts/mina/verification/index.js.map +0 -1
- package/lib/ts/mina/verification/verification.js.map +0 -1
- package/lib/tsconfig.web.tsbuildinfo +0 -1
- package/lib/web/cloud/config.js.map +0 -1
- package/lib/web/cloud/index.js.map +0 -1
- package/lib/web/cloud/networks.js.map +0 -1
- package/lib/web/cloud/utils/base64.js.map +0 -1
- package/lib/web/cloud/utils/graphql.js.map +0 -1
- package/lib/web/cloud/utils/index.js.map +0 -1
- package/lib/web/cloud/utils/utils.js.map +0 -1
- package/lib/web/cloud/worker/cloud.js.map +0 -1
- package/lib/web/cloud/worker/index.js.map +0 -1
- package/lib/web/cloud/worker/transaction.js.map +0 -1
- package/lib/web/cloud/worker/worker.js.map +0 -1
- package/lib/web/index.js.map +0 -1
- package/lib/web/mina/api/api.js.map +0 -1
- package/lib/web/mina/index.js.map +0 -1
- package/lib/web/mina/local/local.js.map +0 -1
- package/lib/web/mina/storage/index.js.map +0 -1
- package/lib/web/mina/storage/ipfs.js.map +0 -1
- package/lib/web/mina/storage/pinata.js.map +0 -1
- package/lib/web/mina/storage/storage.js.map +0 -1
- package/lib/web/mina/token/FungibleToken.js.map +0 -1
- package/lib/web/mina/token/FungibleTokenAdmin.js.map +0 -1
- package/lib/web/mina/token/api.js.map +0 -1
- package/lib/web/mina/token/index.js.map +0 -1
- package/lib/web/mina/token/vk.js.map +0 -1
- package/lib/web/mina/token/whitelist.js.map +0 -1
- package/lib/web/mina/transactions/account.js.map +0 -1
- package/lib/web/mina/transactions/blockberry.js.map +0 -1
- package/lib/web/mina/transactions/chain.js.map +0 -1
- package/lib/web/mina/transactions/index.js.map +0 -1
- package/lib/web/mina/transactions/nonce.js.map +0 -1
- package/lib/web/mina/transactions/send.js.map +0 -1
- package/lib/web/mina/transactions/tiny-contract.js.map +0 -1
- package/lib/web/mina/transactions/transaction.js.map +0 -1
- package/lib/web/mina/transactions/txstatus.js.map +0 -1
- package/lib/web/mina/utils/base64.js.map +0 -1
- package/lib/web/mina/utils/fee.js.map +0 -1
- package/lib/web/mina/utils/fetch.js.map +0 -1
- package/lib/web/mina/utils/fields.js.map +0 -1
- package/lib/web/mina/utils/index.js.map +0 -1
- package/lib/web/mina/utils/indexed-map.js.map +0 -1
- package/lib/web/mina/utils/mina.js.map +0 -1
- package/lib/web/mina/verification/index.js.map +0 -1
- package/lib/web/mina/verification/verification.js.map +0 -1
- /package/{lib → dist}/ts/cloud/config.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/config.js +0 -0
- /package/{lib → dist}/ts/cloud/index.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/index.js +0 -0
- /package/{lib → dist}/ts/cloud/networks.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/networks.js +0 -0
- /package/{lib → dist}/ts/cloud/utils/base64.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/utils/base64.js +0 -0
- /package/{lib → dist}/ts/cloud/utils/graphql.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/utils/graphql.js +0 -0
- /package/{lib → dist}/ts/cloud/utils/index.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/utils/index.js +0 -0
- /package/{lib → dist}/ts/cloud/utils/utils.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/utils/utils.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/cloud.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/cloud.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/index.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/index.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/job.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/job.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/task.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/task.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/transaction.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/transaction.js +0 -0
- /package/{lib → dist}/ts/cloud/worker/worker.d.ts +0 -0
- /package/{lib → dist}/ts/cloud/worker/worker.js +0 -0
- /package/{lib → dist}/ts/index.d.ts +0 -0
- /package/{lib → dist}/ts/index.js +0 -0
- /package/{lib → dist}/ts/mina/api/api.d.ts +0 -0
- /package/{lib → dist}/ts/mina/api/api.js +0 -0
- /package/{lib → dist}/ts/mina/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/index.js +0 -0
- /package/{lib → dist}/ts/mina/local/local.d.ts +0 -0
- /package/{lib → dist}/ts/mina/local/local.js +0 -0
- /package/{lib → dist}/ts/mina/storage/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/storage/index.js +0 -0
- /package/{lib → dist}/ts/mina/storage/ipfs.d.ts +0 -0
- /package/{lib → dist}/ts/mina/storage/ipfs.js +0 -0
- /package/{lib → dist}/ts/mina/storage/pinata.d.ts +0 -0
- /package/{lib → dist}/ts/mina/storage/pinata.js +0 -0
- /package/{lib → dist}/ts/mina/storage/storage.d.ts +0 -0
- /package/{lib → dist}/ts/mina/storage/storage.js +0 -0
- /package/{lib → dist}/ts/mina/token/FungibleToken.d.ts +0 -0
- /package/{lib → dist}/ts/mina/token/FungibleToken.js +0 -0
- /package/{lib → dist}/ts/mina/token/FungibleTokenAdmin.d.ts +0 -0
- /package/{lib → dist}/ts/mina/token/FungibleTokenAdmin.js +0 -0
- /package/{lib → dist}/ts/mina/token/api.d.ts +0 -0
- /package/{lib → dist}/ts/mina/token/api.js +0 -0
- /package/{lib → dist}/ts/mina/token/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/token/index.js +0 -0
- /package/{lib → dist}/ts/mina/token/vk.d.ts +0 -0
- /package/{lib → dist}/ts/mina/token/vk.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/account.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/account.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/blockberry.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/blockberry.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/chain.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/chain.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/index.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/nonce.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/nonce.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/send.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/send.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/tiny-contract.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/tiny-contract.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/transaction.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/transaction.js +0 -0
- /package/{lib → dist}/ts/mina/transactions/txstatus.d.ts +0 -0
- /package/{lib → dist}/ts/mina/transactions/txstatus.js +0 -0
- /package/{lib → dist}/ts/mina/utils/base64.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/base64.js +0 -0
- /package/{lib → dist}/ts/mina/utils/fee.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/fee.js +0 -0
- /package/{lib → dist}/ts/mina/utils/fetch.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/fetch.js +0 -0
- /package/{lib → dist}/ts/mina/utils/fields.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/fields.js +0 -0
- /package/{lib → dist}/ts/mina/utils/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/index.js +0 -0
- /package/{lib → dist}/ts/mina/utils/indexed-map.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/indexed-map.js +0 -0
- /package/{lib → dist}/ts/mina/utils/mina.d.ts +0 -0
- /package/{lib → dist}/ts/mina/utils/mina.js +0 -0
- /package/{lib → dist}/ts/mina/verification/index.d.ts +0 -0
- /package/{lib → dist}/ts/mina/verification/index.js +0 -0
- /package/{lib → dist}/ts/mina/verification/verification.d.ts +0 -0
- /package/{lib → dist}/ts/mina/verification/verification.js +0 -0
- /package/{lib → dist}/web/cloud/config.d.ts +0 -0
- /package/{lib → dist}/web/cloud/config.js +0 -0
- /package/{lib → dist}/web/cloud/index.d.ts +0 -0
- /package/{lib → dist}/web/cloud/index.js +0 -0
- /package/{lib → dist}/web/cloud/networks.d.ts +0 -0
- /package/{lib → dist}/web/cloud/networks.js +0 -0
- /package/{lib → dist}/web/cloud/utils/base64.d.ts +0 -0
- /package/{lib → dist}/web/cloud/utils/base64.js +0 -0
- /package/{lib → dist}/web/cloud/utils/graphql.d.ts +0 -0
- /package/{lib → dist}/web/cloud/utils/graphql.js +0 -0
- /package/{lib → dist}/web/cloud/utils/index.d.ts +0 -0
- /package/{lib → dist}/web/cloud/utils/index.js +0 -0
- /package/{lib → dist}/web/cloud/utils/utils.d.ts +0 -0
- /package/{lib → dist}/web/cloud/utils/utils.js +0 -0
- /package/{lib → dist}/web/cloud/worker/cloud.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/cloud.js +0 -0
- /package/{lib → dist}/web/cloud/worker/index.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/index.js +0 -0
- /package/{lib → dist}/web/cloud/worker/job.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/job.js +0 -0
- /package/{lib → dist}/web/cloud/worker/task.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/task.js +0 -0
- /package/{lib → dist}/web/cloud/worker/transaction.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/transaction.js +0 -0
- /package/{lib → dist}/web/cloud/worker/worker.d.ts +0 -0
- /package/{lib → dist}/web/cloud/worker/worker.js +0 -0
- /package/{lib → dist}/web/index.d.ts +0 -0
- /package/{lib → dist}/web/index.js +0 -0
- /package/{lib → dist}/web/mina/api/api.d.ts +0 -0
- /package/{lib → dist}/web/mina/api/api.js +0 -0
- /package/{lib → dist}/web/mina/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/index.js +0 -0
- /package/{lib → dist}/web/mina/local/local.d.ts +0 -0
- /package/{lib → dist}/web/mina/local/local.js +0 -0
- /package/{lib → dist}/web/mina/storage/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/storage/index.js +0 -0
- /package/{lib → dist}/web/mina/storage/ipfs.d.ts +0 -0
- /package/{lib → dist}/web/mina/storage/ipfs.js +0 -0
- /package/{lib → dist}/web/mina/storage/pinata.d.ts +0 -0
- /package/{lib → dist}/web/mina/storage/pinata.js +0 -0
- /package/{lib → dist}/web/mina/storage/storage.d.ts +0 -0
- /package/{lib → dist}/web/mina/storage/storage.js +0 -0
- /package/{lib → dist}/web/mina/token/FungibleToken.d.ts +0 -0
- /package/{lib → dist}/web/mina/token/FungibleToken.js +0 -0
- /package/{lib → dist}/web/mina/token/FungibleTokenAdmin.d.ts +0 -0
- /package/{lib → dist}/web/mina/token/FungibleTokenAdmin.js +0 -0
- /package/{lib → dist}/web/mina/token/api.d.ts +0 -0
- /package/{lib → dist}/web/mina/token/api.js +0 -0
- /package/{lib → dist}/web/mina/token/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/token/index.js +0 -0
- /package/{lib → dist}/web/mina/token/vk.d.ts +0 -0
- /package/{lib → dist}/web/mina/token/vk.js +0 -0
- /package/{lib → dist}/web/mina/transactions/account.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/account.js +0 -0
- /package/{lib → dist}/web/mina/transactions/blockberry.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/blockberry.js +0 -0
- /package/{lib → dist}/web/mina/transactions/chain.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/chain.js +0 -0
- /package/{lib → dist}/web/mina/transactions/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/index.js +0 -0
- /package/{lib → dist}/web/mina/transactions/nonce.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/nonce.js +0 -0
- /package/{lib → dist}/web/mina/transactions/send.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/send.js +0 -0
- /package/{lib → dist}/web/mina/transactions/tiny-contract.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/tiny-contract.js +0 -0
- /package/{lib → dist}/web/mina/transactions/transaction.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/transaction.js +0 -0
- /package/{lib → dist}/web/mina/transactions/txstatus.d.ts +0 -0
- /package/{lib → dist}/web/mina/transactions/txstatus.js +0 -0
- /package/{lib → dist}/web/mina/utils/base64.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/base64.js +0 -0
- /package/{lib → dist}/web/mina/utils/fee.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/fee.js +0 -0
- /package/{lib → dist}/web/mina/utils/fetch.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/fetch.js +0 -0
- /package/{lib → dist}/web/mina/utils/fields.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/fields.js +0 -0
- /package/{lib → dist}/web/mina/utils/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/index.js +0 -0
- /package/{lib → dist}/web/mina/utils/indexed-map.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/indexed-map.js +0 -0
- /package/{lib → dist}/web/mina/utils/mina.d.ts +0 -0
- /package/{lib → dist}/web/mina/utils/mina.js +0 -0
- /package/{lib → dist}/web/mina/verification/index.d.ts +0 -0
- /package/{lib → dist}/web/mina/verification/index.js +0 -0
- /package/{lib → dist}/web/mina/verification/verification.d.ts +0 -0
- /package/{lib → dist}/web/mina/verification/verification.js +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
export async function pinJSON(params: {
|
2
|
+
data: string | object;
|
3
|
+
name?: string;
|
4
|
+
keyvalues?: object;
|
5
|
+
auth?: string;
|
6
|
+
}): Promise<string | undefined> {
|
7
|
+
const {
|
8
|
+
data,
|
9
|
+
name = "data.json",
|
10
|
+
keyvalues = [{ key: "library", value: "zkcloudworker" }],
|
11
|
+
} = params;
|
12
|
+
const auth =
|
13
|
+
params.auth ??
|
14
|
+
process.env.PINATA_JWT ??
|
15
|
+
process.env.NEXT_PUBLIC_PINATA_JWT ??
|
16
|
+
process.env.REACT_APP_PINATA_JWT;
|
17
|
+
|
18
|
+
try {
|
19
|
+
const pinataData = {
|
20
|
+
pinataOptions: {
|
21
|
+
cidVersion: 1,
|
22
|
+
},
|
23
|
+
pinataMetadata: {
|
24
|
+
name,
|
25
|
+
keyvalues,
|
26
|
+
},
|
27
|
+
pinataContent: data,
|
28
|
+
};
|
29
|
+
|
30
|
+
const res = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
31
|
+
method: "POST",
|
32
|
+
headers: {
|
33
|
+
"Content-Type": "application/json",
|
34
|
+
Authorization: "Bearer " + auth,
|
35
|
+
},
|
36
|
+
body: JSON.stringify(pinataData),
|
37
|
+
});
|
38
|
+
|
39
|
+
if (!res.ok) {
|
40
|
+
throw new Error(`Pinata error: status: ${res.status} ${res.statusText}`);
|
41
|
+
}
|
42
|
+
|
43
|
+
const responseData = await res.json();
|
44
|
+
console.log("saveToIPFS result:", responseData);
|
45
|
+
return (
|
46
|
+
responseData as unknown as { IpfsHash: string | undefined } | undefined
|
47
|
+
)?.IpfsHash;
|
48
|
+
} catch (error: any) {
|
49
|
+
console.error("saveToIPFS error:", error?.message);
|
50
|
+
return undefined;
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Field, Bool, Struct, Encoding, Provable } from "o1js";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Represents the off-chain storage information,
|
5
|
+
* such as an IPFS hash.
|
6
|
+
*/
|
7
|
+
export class Storage extends Struct({
|
8
|
+
url: Provable.Array(Field, 2),
|
9
|
+
}) {
|
10
|
+
constructor(value: { url: [Field, Field] }) {
|
11
|
+
super(value);
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Asserts that two Storage instances are equal.
|
16
|
+
* @param a The first Storage instance.
|
17
|
+
* @param b The second Storage instance.
|
18
|
+
*/
|
19
|
+
static assertEquals(a: Storage, b: Storage) {
|
20
|
+
a.url[0].assertEquals(b.url[0]);
|
21
|
+
a.url[1].assertEquals(b.url[1]);
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Checks if two Storage instances are equal.
|
26
|
+
* @param a The first Storage instance.
|
27
|
+
* @param b The second Storage instance.
|
28
|
+
* @returns A Bool indicating whether the two instances are equal.
|
29
|
+
*/
|
30
|
+
static equals(a: Storage, b: Storage): Bool {
|
31
|
+
return a.url[0].equals(b.url[0]).and(a.url[1].equals(b.url[1]));
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Creates a Storage instance from a string.
|
36
|
+
* @param url The string representing the storage URL.
|
37
|
+
* @returns A new Storage instance.
|
38
|
+
*/
|
39
|
+
static fromString(url: string): Storage {
|
40
|
+
const fields = Encoding.stringToFields(url);
|
41
|
+
if (fields.length !== 2) throw new Error("Invalid string length");
|
42
|
+
return new Storage({ url: [fields[0], fields[1]] });
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Converts the Storage instance to a string.
|
47
|
+
* @returns The string representation of the storage URL.
|
48
|
+
*/
|
49
|
+
toString(): string {
|
50
|
+
if (this.url[0].toBigInt() === 0n && this.url[1].toBigInt() === 0n) {
|
51
|
+
throw new Error("Invalid string");
|
52
|
+
}
|
53
|
+
return Encoding.stringFromFields([this.url[0], this.url[1]]);
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,316 @@
|
|
1
|
+
import {
|
2
|
+
AccountUpdate,
|
3
|
+
AccountUpdateForest,
|
4
|
+
assert,
|
5
|
+
Bool,
|
6
|
+
DeployArgs,
|
7
|
+
Field,
|
8
|
+
Int64,
|
9
|
+
method,
|
10
|
+
Permissions,
|
11
|
+
Provable,
|
12
|
+
PublicKey,
|
13
|
+
State,
|
14
|
+
state,
|
15
|
+
Struct,
|
16
|
+
TokenContract,
|
17
|
+
Types,
|
18
|
+
UInt64,
|
19
|
+
UInt8,
|
20
|
+
VerificationKey,
|
21
|
+
} from "o1js";
|
22
|
+
import {
|
23
|
+
FungibleTokenAdmin,
|
24
|
+
FungibleTokenAdminBase,
|
25
|
+
} from "./FungibleTokenAdmin.js";
|
26
|
+
|
27
|
+
interface FungibleTokenDeployProps extends Exclude<DeployArgs, undefined> {
|
28
|
+
/** The token symbol. */
|
29
|
+
symbol: string;
|
30
|
+
/** A source code reference, which is placed within the `zkappUri` of the contract account.
|
31
|
+
* Typically a link to a file on github. */
|
32
|
+
src: string;
|
33
|
+
}
|
34
|
+
|
35
|
+
export const FungibleTokenErrors = {
|
36
|
+
noAdminKey: "could not fetch admin contract key",
|
37
|
+
noPermissionToChangeAdmin: "Not allowed to change admin contract",
|
38
|
+
tokenPaused: "Token is currently paused",
|
39
|
+
noPermissionToMint: "Not allowed to mint tokens",
|
40
|
+
noPermissionToPause: "Not allowed to pause token",
|
41
|
+
noPermissionToResume: "Not allowed to resume token",
|
42
|
+
noTransferFromCirculation: "Can't transfer to/from the circulation account",
|
43
|
+
noPermissionChangeAllowed:
|
44
|
+
"Can't change permissions for access or receive on token accounts",
|
45
|
+
flashMinting:
|
46
|
+
"Flash-minting or unbalanced transaction detected. Please make sure that your transaction is balanced, and that your `AccountUpdate`s are ordered properly, so that tokens are not received before they are sent.",
|
47
|
+
unbalancedTransaction: "Transaction is unbalanced",
|
48
|
+
};
|
49
|
+
|
50
|
+
export class FungibleToken extends TokenContract {
|
51
|
+
@state(UInt8)
|
52
|
+
decimals = State<UInt8>();
|
53
|
+
@state(PublicKey)
|
54
|
+
admin = State<PublicKey>();
|
55
|
+
@state(Bool)
|
56
|
+
paused = State<Bool>();
|
57
|
+
|
58
|
+
// This defines the type of the contract that is used to control access to administrative actions.
|
59
|
+
// If you want to have a custom contract, overwrite this by setting FungibleToken.AdminContract to
|
60
|
+
// your own implementation of FungibleTokenAdminBase.
|
61
|
+
static AdminContract: new (...args: any) => FungibleTokenAdminBase =
|
62
|
+
FungibleTokenAdmin;
|
63
|
+
|
64
|
+
readonly events = {
|
65
|
+
SetAdmin: SetAdminEvent,
|
66
|
+
Pause: PauseEvent,
|
67
|
+
Mint: MintEvent,
|
68
|
+
Burn: BurnEvent,
|
69
|
+
BalanceChange: BalanceChangeEvent,
|
70
|
+
};
|
71
|
+
|
72
|
+
async deploy(props: FungibleTokenDeployProps) {
|
73
|
+
await super.deploy(props);
|
74
|
+
this.paused.set(Bool(true));
|
75
|
+
this.account.zkappUri.set(props.src);
|
76
|
+
this.account.tokenSymbol.set(props.symbol);
|
77
|
+
|
78
|
+
this.account.permissions.set({
|
79
|
+
...Permissions.default(),
|
80
|
+
setVerificationKey:
|
81
|
+
Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
82
|
+
setPermissions: Permissions.impossible(),
|
83
|
+
access: Permissions.proof(),
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
/** Update the verification key.
|
88
|
+
* Note that because we have set the permissions for setting the verification key to `impossibleDuringCurrentVersion()`, this will only be possible in case of a protocol update that requires an update.
|
89
|
+
*/
|
90
|
+
@method
|
91
|
+
async updateVerificationKey(vk: VerificationKey) {
|
92
|
+
this.account.verificationKey.set(vk);
|
93
|
+
}
|
94
|
+
|
95
|
+
/** Initializes the account for tracking total circulation.
|
96
|
+
* @argument {PublicKey} admin - public key where the admin contract is deployed
|
97
|
+
* @argument {UInt8} decimals - number of decimals for the token
|
98
|
+
* @argument {Bool} startPaused - if set to `Bool(true), the contract will start in a mode where token minting and transfers are paused. This should be used for non-atomic deployments
|
99
|
+
*/
|
100
|
+
@method
|
101
|
+
async initialize(admin: PublicKey, decimals: UInt8, startPaused: Bool) {
|
102
|
+
this.account.provedState.requireEquals(Bool(false));
|
103
|
+
|
104
|
+
this.admin.set(admin);
|
105
|
+
this.decimals.set(decimals);
|
106
|
+
this.paused.set(Bool(false));
|
107
|
+
|
108
|
+
this.paused.set(startPaused);
|
109
|
+
|
110
|
+
const accountUpdate = AccountUpdate.createSigned(
|
111
|
+
this.address,
|
112
|
+
this.deriveTokenId()
|
113
|
+
);
|
114
|
+
let permissions = Permissions.default();
|
115
|
+
// This is necessary in order to allow token holders to burn.
|
116
|
+
permissions.send = Permissions.none();
|
117
|
+
permissions.setPermissions = Permissions.impossible();
|
118
|
+
accountUpdate.account.permissions.set(permissions);
|
119
|
+
}
|
120
|
+
|
121
|
+
public async getAdminContract(): Promise<FungibleTokenAdminBase> {
|
122
|
+
const admin = await Provable.witnessAsync(PublicKey, async () => {
|
123
|
+
let pk = await this.admin.fetch();
|
124
|
+
assert(pk !== undefined, FungibleTokenErrors.noAdminKey);
|
125
|
+
return pk;
|
126
|
+
});
|
127
|
+
this.admin.requireEquals(admin);
|
128
|
+
return new FungibleToken.AdminContract(admin);
|
129
|
+
}
|
130
|
+
|
131
|
+
@method
|
132
|
+
async setAdmin(admin: PublicKey) {
|
133
|
+
const adminContract = await this.getAdminContract();
|
134
|
+
const canChangeAdmin = await adminContract.canChangeAdmin(admin);
|
135
|
+
canChangeAdmin.assertTrue(FungibleTokenErrors.noPermissionToChangeAdmin);
|
136
|
+
this.admin.set(admin);
|
137
|
+
this.emitEvent("SetAdmin", new SetAdminEvent({ adminKey: admin }));
|
138
|
+
}
|
139
|
+
|
140
|
+
@method.returns(AccountUpdate)
|
141
|
+
async mint(recipient: PublicKey, amount: UInt64): Promise<AccountUpdate> {
|
142
|
+
this.paused
|
143
|
+
.getAndRequireEquals()
|
144
|
+
.assertFalse(FungibleTokenErrors.tokenPaused);
|
145
|
+
const accountUpdate = this.internal.mint({ address: recipient, amount });
|
146
|
+
const adminContract = await this.getAdminContract();
|
147
|
+
const canMint = await adminContract.canMint(accountUpdate);
|
148
|
+
canMint.assertTrue(FungibleTokenErrors.noPermissionToMint);
|
149
|
+
recipient
|
150
|
+
.equals(this.address)
|
151
|
+
.assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
152
|
+
this.approve(accountUpdate);
|
153
|
+
this.emitEvent("Mint", new MintEvent({ recipient, amount }));
|
154
|
+
const circulationUpdate = AccountUpdate.create(
|
155
|
+
this.address,
|
156
|
+
this.deriveTokenId()
|
157
|
+
);
|
158
|
+
circulationUpdate.balanceChange = Int64.fromUnsigned(amount);
|
159
|
+
return accountUpdate;
|
160
|
+
}
|
161
|
+
|
162
|
+
@method.returns(AccountUpdate)
|
163
|
+
async burn(from: PublicKey, amount: UInt64): Promise<AccountUpdate> {
|
164
|
+
this.paused
|
165
|
+
.getAndRequireEquals()
|
166
|
+
.assertFalse(FungibleTokenErrors.tokenPaused);
|
167
|
+
const accountUpdate = this.internal.burn({ address: from, amount });
|
168
|
+
const circulationUpdate = AccountUpdate.create(
|
169
|
+
this.address,
|
170
|
+
this.deriveTokenId()
|
171
|
+
);
|
172
|
+
from
|
173
|
+
.equals(this.address)
|
174
|
+
.assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
175
|
+
circulationUpdate.balanceChange = Int64.fromUnsigned(amount).neg();
|
176
|
+
this.emitEvent("Burn", new BurnEvent({ from, amount }));
|
177
|
+
return accountUpdate;
|
178
|
+
}
|
179
|
+
|
180
|
+
@method
|
181
|
+
async pause() {
|
182
|
+
const adminContract = await this.getAdminContract();
|
183
|
+
const canPause = await adminContract.canPause();
|
184
|
+
canPause.assertTrue(FungibleTokenErrors.noPermissionToPause);
|
185
|
+
this.paused.set(Bool(true));
|
186
|
+
this.emitEvent("Pause", new PauseEvent({ isPaused: Bool(true) }));
|
187
|
+
}
|
188
|
+
|
189
|
+
@method
|
190
|
+
async resume() {
|
191
|
+
const adminContract = await this.getAdminContract();
|
192
|
+
const canResume = await adminContract.canResume();
|
193
|
+
canResume.assertTrue(FungibleTokenErrors.noPermissionToResume);
|
194
|
+
this.paused.set(Bool(false));
|
195
|
+
this.emitEvent("Pause", new PauseEvent({ isPaused: Bool(false) }));
|
196
|
+
}
|
197
|
+
|
198
|
+
@method
|
199
|
+
async transfer(from: PublicKey, to: PublicKey, amount: UInt64) {
|
200
|
+
this.paused
|
201
|
+
.getAndRequireEquals()
|
202
|
+
.assertFalse(FungibleTokenErrors.tokenPaused);
|
203
|
+
from
|
204
|
+
.equals(this.address)
|
205
|
+
.assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
206
|
+
to.equals(this.address).assertFalse(
|
207
|
+
FungibleTokenErrors.noTransferFromCirculation
|
208
|
+
);
|
209
|
+
this.internal.send({ from, to, amount });
|
210
|
+
}
|
211
|
+
|
212
|
+
private checkPermissionsUpdate(update: AccountUpdate) {
|
213
|
+
let permissions = update.update.permissions;
|
214
|
+
|
215
|
+
let { access, receive } = permissions.value;
|
216
|
+
let accessIsNone = Provable.equal(
|
217
|
+
Types.AuthRequired,
|
218
|
+
access,
|
219
|
+
Permissions.none()
|
220
|
+
);
|
221
|
+
let receiveIsNone = Provable.equal(
|
222
|
+
Types.AuthRequired,
|
223
|
+
receive,
|
224
|
+
Permissions.none()
|
225
|
+
);
|
226
|
+
let updateAllowed = accessIsNone.and(receiveIsNone);
|
227
|
+
|
228
|
+
assert(
|
229
|
+
updateAllowed.or(permissions.isSome.not()),
|
230
|
+
FungibleTokenErrors.noPermissionChangeAllowed
|
231
|
+
);
|
232
|
+
}
|
233
|
+
|
234
|
+
/** Approve `AccountUpdate`s that have been created outside of the token contract.
|
235
|
+
*
|
236
|
+
* @argument {AccountUpdateForest} updates - The `AccountUpdate`s to approve. Note that the forest size is limited by the base token contract, @see TokenContractV2.MAX_ACCOUNT_UPDATES The current limit is 9.
|
237
|
+
*/
|
238
|
+
@method
|
239
|
+
async approveBase(updates: AccountUpdateForest): Promise<void> {
|
240
|
+
this.paused
|
241
|
+
.getAndRequireEquals()
|
242
|
+
.assertFalse(FungibleTokenErrors.tokenPaused);
|
243
|
+
let totalBalance = Int64.from(0);
|
244
|
+
this.forEachUpdate(updates, (update, usesToken) => {
|
245
|
+
// Make sure that the account permissions are not changed
|
246
|
+
this.checkPermissionsUpdate(update);
|
247
|
+
this.emitEventIf(
|
248
|
+
usesToken,
|
249
|
+
"BalanceChange",
|
250
|
+
new BalanceChangeEvent({
|
251
|
+
address: update.publicKey,
|
252
|
+
amount: update.balanceChange,
|
253
|
+
})
|
254
|
+
);
|
255
|
+
// Don't allow transfers to/from the account that's tracking circulation
|
256
|
+
update.publicKey
|
257
|
+
.equals(this.address)
|
258
|
+
.and(usesToken)
|
259
|
+
.assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
260
|
+
totalBalance = Provable.if(
|
261
|
+
usesToken,
|
262
|
+
totalBalance.add(update.balanceChange),
|
263
|
+
totalBalance
|
264
|
+
);
|
265
|
+
totalBalance.isPositive().assertFalse(FungibleTokenErrors.flashMinting);
|
266
|
+
});
|
267
|
+
totalBalance.assertEquals(
|
268
|
+
Int64.zero,
|
269
|
+
FungibleTokenErrors.unbalancedTransaction
|
270
|
+
);
|
271
|
+
}
|
272
|
+
|
273
|
+
@method.returns(UInt64)
|
274
|
+
async getBalanceOf(address: PublicKey): Promise<UInt64> {
|
275
|
+
const account = AccountUpdate.create(address, this.deriveTokenId()).account;
|
276
|
+
const balance = account.balance.get();
|
277
|
+
account.balance.requireEquals(balance);
|
278
|
+
return balance;
|
279
|
+
}
|
280
|
+
|
281
|
+
/** Reports the current circulating supply
|
282
|
+
* This does take into account currently unreduced actions.
|
283
|
+
*/
|
284
|
+
async getCirculating(): Promise<UInt64> {
|
285
|
+
let circulating = await this.getBalanceOf(this.address);
|
286
|
+
return circulating;
|
287
|
+
}
|
288
|
+
|
289
|
+
@method.returns(UInt8)
|
290
|
+
async getDecimals(): Promise<UInt8> {
|
291
|
+
return this.decimals.getAndRequireEquals();
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
export class SetAdminEvent extends Struct({
|
296
|
+
adminKey: PublicKey,
|
297
|
+
}) {}
|
298
|
+
|
299
|
+
export class PauseEvent extends Struct({
|
300
|
+
isPaused: Bool,
|
301
|
+
}) {}
|
302
|
+
|
303
|
+
export class MintEvent extends Struct({
|
304
|
+
recipient: PublicKey,
|
305
|
+
amount: UInt64,
|
306
|
+
}) {}
|
307
|
+
|
308
|
+
export class BurnEvent extends Struct({
|
309
|
+
from: PublicKey,
|
310
|
+
amount: UInt64,
|
311
|
+
}) {}
|
312
|
+
|
313
|
+
export class BalanceChangeEvent extends Struct({
|
314
|
+
address: PublicKey,
|
315
|
+
amount: Int64,
|
316
|
+
}) {}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import {
|
2
|
+
AccountUpdate,
|
3
|
+
assert,
|
4
|
+
Bool,
|
5
|
+
DeployArgs,
|
6
|
+
method,
|
7
|
+
Permissions,
|
8
|
+
Provable,
|
9
|
+
PublicKey,
|
10
|
+
SmartContract,
|
11
|
+
State,
|
12
|
+
state,
|
13
|
+
VerificationKey,
|
14
|
+
} from "o1js";
|
15
|
+
|
16
|
+
export type FungibleTokenAdminBase = SmartContract & {
|
17
|
+
canMint(accountUpdate: AccountUpdate): Promise<Bool>;
|
18
|
+
canChangeAdmin(admin: PublicKey): Promise<Bool>;
|
19
|
+
canPause(): Promise<Bool>;
|
20
|
+
canResume(): Promise<Bool>;
|
21
|
+
};
|
22
|
+
|
23
|
+
export interface FungibleTokenAdminDeployProps
|
24
|
+
extends Exclude<DeployArgs, undefined> {
|
25
|
+
adminPublicKey: PublicKey;
|
26
|
+
}
|
27
|
+
|
28
|
+
/** A contract that grants permissions for administrative actions on a token.
|
29
|
+
*
|
30
|
+
* We separate this out into a dedicated contract. That way, when issuing a token, a user can
|
31
|
+
* specify their own rules for administrative actions, without changing the token contract itself.
|
32
|
+
*
|
33
|
+
* The advantage is that third party applications that only use the token in a non-privileged way
|
34
|
+
* can integrate against the unchanged token contract.
|
35
|
+
*/
|
36
|
+
export class FungibleTokenAdmin
|
37
|
+
extends SmartContract
|
38
|
+
implements FungibleTokenAdminBase
|
39
|
+
{
|
40
|
+
@state(PublicKey)
|
41
|
+
private adminPublicKey = State<PublicKey>();
|
42
|
+
|
43
|
+
async deploy(props: FungibleTokenAdminDeployProps) {
|
44
|
+
await super.deploy(props);
|
45
|
+
this.adminPublicKey.set(props.adminPublicKey);
|
46
|
+
this.account.permissions.set({
|
47
|
+
...Permissions.default(),
|
48
|
+
setVerificationKey:
|
49
|
+
Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
50
|
+
setPermissions: Permissions.impossible(),
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
/** Update the verification key.
|
55
|
+
* Note that because we have set the permissions for setting the verification key to `impossibleDuringCurrentVersion()`, this will only be possible in case of a protocol update that requires an update.
|
56
|
+
*/
|
57
|
+
@method
|
58
|
+
async updateVerificationKey(vk: VerificationKey) {
|
59
|
+
this.account.verificationKey.set(vk);
|
60
|
+
}
|
61
|
+
|
62
|
+
private async ensureAdminSignature() {
|
63
|
+
const admin = await Provable.witnessAsync(PublicKey, async () => {
|
64
|
+
let pk = await this.adminPublicKey.fetch();
|
65
|
+
assert(pk !== undefined, "could not fetch admin public key");
|
66
|
+
return pk;
|
67
|
+
});
|
68
|
+
this.adminPublicKey.requireEquals(admin);
|
69
|
+
return AccountUpdate.createSigned(admin);
|
70
|
+
}
|
71
|
+
|
72
|
+
@method.returns(Bool)
|
73
|
+
public async canMint(_accountUpdate: AccountUpdate) {
|
74
|
+
await this.ensureAdminSignature();
|
75
|
+
return Bool(true);
|
76
|
+
}
|
77
|
+
|
78
|
+
@method.returns(Bool)
|
79
|
+
public async canChangeAdmin(_admin: PublicKey) {
|
80
|
+
await this.ensureAdminSignature();
|
81
|
+
return Bool(true);
|
82
|
+
}
|
83
|
+
|
84
|
+
@method.returns(Bool)
|
85
|
+
public async canPause(): Promise<Bool> {
|
86
|
+
await this.ensureAdminSignature();
|
87
|
+
return Bool(true);
|
88
|
+
}
|
89
|
+
|
90
|
+
@method.returns(Bool)
|
91
|
+
public async canResume(): Promise<Bool> {
|
92
|
+
await this.ensureAdminSignature();
|
93
|
+
return Bool(true);
|
94
|
+
}
|
95
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
4
|
+
|
5
|
+
export interface FungibleTokenDeployParams {
|
6
|
+
txType: "deploy";
|
7
|
+
tokenAddress: string;
|
8
|
+
adminContractAddress: string;
|
9
|
+
senderAddress: string;
|
10
|
+
chain: string;
|
11
|
+
symbol: string;
|
12
|
+
uri: string;
|
13
|
+
serializedTransaction: string;
|
14
|
+
signedData: string;
|
15
|
+
sendTransaction: boolean;
|
16
|
+
developerAddress?: string;
|
17
|
+
developerFee?: number;
|
18
|
+
}
|
19
|
+
|
20
|
+
export type FungibleTokenTransactionType =
|
21
|
+
| "mint"
|
22
|
+
| "transfer"
|
23
|
+
| "bid"
|
24
|
+
| "offer"
|
25
|
+
| "buy"
|
26
|
+
| "sell"
|
27
|
+
| "withdrawBid"
|
28
|
+
| "withdrawOffer";
|
29
|
+
export interface FungibleTokenTransactionParams {
|
30
|
+
txType: FungibleTokenTransactionType;
|
31
|
+
tokenAddress: string;
|
32
|
+
chain: string;
|
33
|
+
serializedTransaction: string;
|
34
|
+
signedData: string;
|
35
|
+
from: string;
|
36
|
+
to: string;
|
37
|
+
amount: number;
|
38
|
+
price?: number;
|
39
|
+
sendTransaction: boolean;
|
40
|
+
developerAddress?: string;
|
41
|
+
developerFee?: number;
|
42
|
+
symbol?: string;
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface FungibleTokenJobResult {
|
46
|
+
success: boolean;
|
47
|
+
jobStatus?: JobStatus;
|
48
|
+
tx?: string;
|
49
|
+
hash?: string;
|
50
|
+
error?: string;
|
51
|
+
}
|
52
|
+
|
53
|
+
export class TokenAPI {
|
54
|
+
readonly client: zkCloudWorkerClient;
|
55
|
+
|
56
|
+
constructor(params: {
|
57
|
+
jwt: string;
|
58
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
59
|
+
chain: blockchain;
|
60
|
+
}) {
|
61
|
+
const { jwt, zkcloudworker, chain } = params;
|
62
|
+
if (jwt === undefined) throw new Error("jwt is undefined");
|
63
|
+
|
64
|
+
this.client = new zkCloudWorkerClient({
|
65
|
+
jwt,
|
66
|
+
chain,
|
67
|
+
zkcloudworker,
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
async sendDeployTransaction(
|
72
|
+
params: FungibleTokenDeployParams
|
73
|
+
): Promise<string | undefined> {
|
74
|
+
const { symbol } = params;
|
75
|
+
|
76
|
+
const transaction = JSON.stringify(params, null, 2);
|
77
|
+
|
78
|
+
const answer = await this.client.execute({
|
79
|
+
developer: "DFST",
|
80
|
+
repo: "token-launchpad",
|
81
|
+
transactions: [transaction],
|
82
|
+
task: "deploy",
|
83
|
+
args: JSON.stringify({ tokenAddress: params.tokenAddress }),
|
84
|
+
metadata: `deploy token ${symbol}`,
|
85
|
+
});
|
86
|
+
|
87
|
+
const jobId = answer.jobId;
|
88
|
+
if (jobId === undefined)
|
89
|
+
console.error("Deploy Job ID is undefined", { answer, symbol });
|
90
|
+
return jobId;
|
91
|
+
}
|
92
|
+
|
93
|
+
async sendTransaction(
|
94
|
+
params: FungibleTokenTransactionParams
|
95
|
+
): Promise<string | undefined> {
|
96
|
+
const { txType, symbol } = params;
|
97
|
+
|
98
|
+
const transaction = JSON.stringify(params, null, 2);
|
99
|
+
|
100
|
+
const answer = await this.client.execute({
|
101
|
+
developer: "DFST",
|
102
|
+
repo: "token-launchpad",
|
103
|
+
transactions: [transaction],
|
104
|
+
task: txType,
|
105
|
+
args: JSON.stringify({ tokenAddress: params.tokenAddress }),
|
106
|
+
metadata: `${txType} token${symbol ? ` ${symbol}` : ""}`,
|
107
|
+
});
|
108
|
+
const jobId = answer.jobId;
|
109
|
+
if (jobId === undefined)
|
110
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
111
|
+
return jobId;
|
112
|
+
}
|
113
|
+
|
114
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
115
|
+
// Do not use it in "use server" functions, use getResult instead
|
116
|
+
async waitForJobResult(params: {
|
117
|
+
jobId: string;
|
118
|
+
maxAttempts?: number;
|
119
|
+
interval?: number;
|
120
|
+
maxErrors?: number;
|
121
|
+
printLogs?: boolean;
|
122
|
+
}): Promise<string | undefined> {
|
123
|
+
const deployResult = await this.client.waitForJobResult(params);
|
124
|
+
console.log(
|
125
|
+
"waitForJobResult result:",
|
126
|
+
deployResult?.result?.result?.slice(0, 50)
|
127
|
+
);
|
128
|
+
return deployResult?.result?.result ?? "error";
|
129
|
+
}
|
130
|
+
|
131
|
+
async getResult(jobId: string): Promise<FungibleTokenJobResult> {
|
132
|
+
try {
|
133
|
+
const callResult = await this.client.jobResult({ jobId });
|
134
|
+
const jobStatus: JobStatus | undefined =
|
135
|
+
callResult?.success === true
|
136
|
+
? callResult?.result?.jobStatus
|
137
|
+
: undefined;
|
138
|
+
if (!callResult.success) {
|
139
|
+
return {
|
140
|
+
success: false,
|
141
|
+
error: callResult?.error,
|
142
|
+
jobStatus,
|
143
|
+
};
|
144
|
+
}
|
145
|
+
const jobResult = callResult.result?.result;
|
146
|
+
if (callResult.error)
|
147
|
+
return {
|
148
|
+
success: false,
|
149
|
+
error: callResult.error,
|
150
|
+
jobStatus,
|
151
|
+
};
|
152
|
+
if (!jobResult) return { success: true, jobStatus };
|
153
|
+
|
154
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
155
|
+
return {
|
156
|
+
success: false,
|
157
|
+
error: jobResult,
|
158
|
+
jobStatus,
|
159
|
+
};
|
160
|
+
|
161
|
+
try {
|
162
|
+
const { success, tx, hash, error } = JSON.parse(jobResult);
|
163
|
+
if (success === undefined)
|
164
|
+
return {
|
165
|
+
success: false,
|
166
|
+
tx,
|
167
|
+
hash,
|
168
|
+
error,
|
169
|
+
jobStatus,
|
170
|
+
};
|
171
|
+
return { success, tx, hash, error, jobStatus };
|
172
|
+
} catch (e) {
|
173
|
+
return {
|
174
|
+
success: false,
|
175
|
+
error: `Error parsing job result: ${jobResult}`,
|
176
|
+
};
|
177
|
+
}
|
178
|
+
} catch (e) {
|
179
|
+
return { success: false, error: `Error getting job result: ${e}` };
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|