zkcloudworker 0.18.8 → 0.18.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/ts/mina/token/FungibleTokenAdmin.d.ts +1 -6
  2. package/dist/ts/mina/token/FungibleTokenAdmin.js.map +1 -1
  3. package/dist/ts/mina/token/FungibleTokenContract.d.ts +520 -0
  4. package/dist/ts/mina/token/FungibleTokenContract.js +290 -0
  5. package/dist/ts/mina/token/FungibleTokenContract.js.map +1 -0
  6. package/dist/ts/mina/token/FungibleTokenWhitelistedAdmin.d.ts +33 -0
  7. package/dist/ts/mina/token/FungibleTokenWhitelistedAdmin.js +119 -0
  8. package/dist/ts/mina/token/FungibleTokenWhitelistedAdmin.js.map +1 -0
  9. package/dist/ts/mina/token/api.d.ts +2 -2
  10. package/dist/ts/mina/token/api.js.map +1 -1
  11. package/dist/ts/mina/token/bid.d.ts +24 -0
  12. package/dist/ts/mina/token/bid.js +167 -0
  13. package/dist/ts/mina/token/bid.js.map +1 -0
  14. package/dist/ts/mina/token/build.d.ts +64 -0
  15. package/dist/ts/mina/token/build.js +437 -0
  16. package/dist/ts/mina/token/build.js.map +1 -0
  17. package/dist/ts/mina/token/fee.d.ts +2 -0
  18. package/dist/ts/mina/token/fee.js +3 -0
  19. package/dist/ts/mina/token/fee.js.map +1 -0
  20. package/dist/ts/mina/token/index.d.ts +5 -2
  21. package/dist/ts/mina/token/index.js +5 -2
  22. package/dist/ts/mina/token/index.js.map +1 -1
  23. package/dist/ts/mina/token/offer.d.ts +25 -0
  24. package/dist/ts/mina/token/offer.js +175 -0
  25. package/dist/ts/mina/token/offer.js.map +1 -0
  26. package/dist/ts/mina/token/token.d.ts +426 -0
  27. package/dist/ts/mina/token/token.js +87 -0
  28. package/dist/ts/mina/token/token.js.map +1 -0
  29. package/dist/tsconfig.web.tsbuildinfo +1 -1
  30. package/dist/web/mina/token/FungibleTokenAdmin.d.ts +1 -6
  31. package/dist/web/mina/token/FungibleTokenAdmin.js.map +1 -1
  32. package/dist/web/mina/token/FungibleTokenContract.d.ts +520 -0
  33. package/dist/web/mina/token/FungibleTokenContract.js +290 -0
  34. package/dist/web/mina/token/FungibleTokenContract.js.map +1 -0
  35. package/dist/web/mina/token/FungibleTokenWhitelistedAdmin.d.ts +33 -0
  36. package/dist/web/mina/token/FungibleTokenWhitelistedAdmin.js +119 -0
  37. package/dist/web/mina/token/FungibleTokenWhitelistedAdmin.js.map +1 -0
  38. package/dist/web/mina/token/api.d.ts +2 -2
  39. package/dist/web/mina/token/api.js.map +1 -1
  40. package/dist/web/mina/token/bid.d.ts +24 -0
  41. package/dist/web/mina/token/bid.js +167 -0
  42. package/dist/web/mina/token/bid.js.map +1 -0
  43. package/dist/web/mina/token/build.d.ts +64 -0
  44. package/dist/web/mina/token/build.js +437 -0
  45. package/dist/web/mina/token/build.js.map +1 -0
  46. package/dist/web/mina/token/fee.d.ts +2 -0
  47. package/dist/web/mina/token/fee.js +3 -0
  48. package/dist/web/mina/token/fee.js.map +1 -0
  49. package/dist/web/mina/token/index.d.ts +5 -2
  50. package/dist/web/mina/token/index.js +5 -2
  51. package/dist/web/mina/token/index.js.map +1 -1
  52. package/dist/web/mina/token/offer.d.ts +25 -0
  53. package/dist/web/mina/token/offer.js +175 -0
  54. package/dist/web/mina/token/offer.js.map +1 -0
  55. package/dist/web/mina/token/token.d.ts +426 -0
  56. package/dist/web/mina/token/token.js +87 -0
  57. package/dist/web/mina/token/token.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/mina/token/FungibleTokenAdmin.ts +1 -7
  60. package/src/mina/token/FungibleTokenContract.ts +327 -0
  61. package/src/mina/token/FungibleTokenWhitelistedAdmin.ts +112 -0
  62. package/src/mina/token/api.ts +5 -2
  63. package/src/mina/token/bid.ts +173 -0
  64. package/src/mina/token/build.ts +610 -0
  65. package/src/mina/token/fee.ts +2 -0
  66. package/src/mina/token/index.ts +5 -2
  67. package/src/mina/token/offer.ts +174 -0
  68. package/src/mina/token/token.ts +127 -0
  69. package/src/mina/token/FungibleToken.ts +0 -316
@@ -1,316 +0,0 @@
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
- }) {}