zkcloudworker 0.16.3 → 0.16.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/lib/ts/src/mina/index.d.ts +0 -1
  2. package/lib/ts/src/mina/index.js +0 -1
  3. package/lib/ts/src/mina/token/vk.d.ts +20 -0
  4. package/lib/ts/src/mina/token/vk.js +20 -0
  5. package/lib/ts/tsconfig.tsbuildinfo +1 -1
  6. package/lib/web/src/mina/index.d.ts +0 -1
  7. package/lib/web/src/mina/index.js +0 -1
  8. package/lib/web/src/mina/index.js.map +1 -1
  9. package/lib/web/src/mina/token/vk.d.ts +20 -0
  10. package/lib/web/src/mina/token/vk.js +20 -0
  11. package/lib/web/src/mina/token/vk.js.map +1 -1
  12. package/lib/web/tsconfig.web.tsbuildinfo +1 -1
  13. package/package.json +2 -8
  14. package/lib/ts/src/mina/V1/FungibleToken.d.ts +0 -338
  15. package/lib/ts/src/mina/V1/FungibleToken.js +0 -308
  16. package/lib/ts/src/mina/V1/FungibleTokenAdmin.d.ts +0 -31
  17. package/lib/ts/src/mina/V1/FungibleTokenAdmin.js +0 -102
  18. package/lib/ts/src/mina/V1/index.d.ts +0 -28
  19. package/lib/ts/src/mina/V1/index.js +0 -13
  20. package/lib/ts/src/mina/V1/vk.d.ts +0 -22
  21. package/lib/ts/src/mina/V1/vk.js +0 -25
  22. package/lib/web/src/mina/V1/FungibleToken.d.ts +0 -338
  23. package/lib/web/src/mina/V1/FungibleToken.js +0 -292
  24. package/lib/web/src/mina/V1/FungibleToken.js.map +0 -1
  25. package/lib/web/src/mina/V1/FungibleTokenAdmin.d.ts +0 -31
  26. package/lib/web/src/mina/V1/FungibleTokenAdmin.js +0 -91
  27. package/lib/web/src/mina/V1/FungibleTokenAdmin.js.map +0 -1
  28. package/lib/web/src/mina/V1/index.d.ts +0 -28
  29. package/lib/web/src/mina/V1/index.js +0 -11
  30. package/lib/web/src/mina/V1/index.js.map +0 -1
  31. package/lib/web/src/mina/V1/vk.d.ts +0 -22
  32. package/lib/web/src/mina/V1/vk.js +0 -23
  33. package/lib/web/src/mina/V1/vk.js.map +0 -1
@@ -1,338 +0,0 @@
1
- import { AccountUpdate, AccountUpdateForest, DeployArgs, Bool, Field, Int64, PublicKey, State, TokenContractV2, Types, UInt64, UInt8, VerificationKey } from "o1js_v1";
2
- import { FungibleTokenAdminBase } from "./FungibleTokenAdmin.js";
3
- interface FungibleTokenDeployProps extends Exclude<DeployArgs, undefined> {
4
- /** The token symbol. */
5
- symbol: string;
6
- /** A source code reference, which is placed within the `zkappUri` of the contract account.
7
- * Typically a link to a file on github. */
8
- src: string;
9
- }
10
- export declare const FungibleTokenErrors: {
11
- noAdminKey: string;
12
- noPermissionToChangeAdmin: string;
13
- tokenPaused: string;
14
- noPermissionToMint: string;
15
- noPermissionToPause: string;
16
- noPermissionToResume: string;
17
- noTransferFromCirculation: string;
18
- noPermissionChangeAllowed: string;
19
- flashMinting: string;
20
- unbalancedTransaction: string;
21
- };
22
- export declare class FungibleToken extends TokenContractV2 {
23
- decimals: State<UInt8>;
24
- admin: State<PublicKey>;
25
- paused: State<import("o1js_v1/dist/node/lib/provable/bool.js").Bool>;
26
- static AdminContract: new (...args: any) => FungibleTokenAdminBase;
27
- readonly events: {
28
- SetAdmin: typeof SetAdminEvent;
29
- Pause: typeof PauseEvent;
30
- Mint: typeof MintEvent;
31
- Burn: typeof BurnEvent;
32
- BalanceChange: typeof BalanceChangeEvent;
33
- };
34
- deploy(props: FungibleTokenDeployProps): Promise<void>;
35
- /** Update the verification key.
36
- * 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.
37
- */
38
- updateVerificationKey(vk: VerificationKey): Promise<void>;
39
- /** Initializes the account for tracking total circulation.
40
- * @argument {PublicKey} admin - public key where the admin contract is deployed
41
- * @argument {UInt8} decimals - number of decimals for the token
42
- * @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
43
- */
44
- initialize(admin: PublicKey, decimals: UInt8, startPaused: Bool): Promise<void>;
45
- getAdminContract(): Promise<FungibleTokenAdminBase>;
46
- setAdmin(admin: PublicKey): Promise<void>;
47
- mint(recipient: PublicKey, amount: UInt64): Promise<AccountUpdate>;
48
- burn(from: PublicKey, amount: UInt64): Promise<AccountUpdate>;
49
- pause(): Promise<void>;
50
- resume(): Promise<void>;
51
- transfer(from: PublicKey, to: PublicKey, amount: UInt64): Promise<void>;
52
- private checkPermissionsUpdate;
53
- /** Approve `AccountUpdate`s that have been created outside of the token contract.
54
- *
55
- * @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.
56
- */
57
- approveBase(updates: AccountUpdateForest): Promise<void>;
58
- getBalanceOf(address: PublicKey): Promise<UInt64>;
59
- /** Reports the current circulating supply
60
- * This does take into account currently unreduced actions.
61
- */
62
- getCirculating(): Promise<UInt64>;
63
- getDecimals(): Promise<UInt8>;
64
- }
65
- declare const SetAdminEvent_base: (new (value: {
66
- adminKey: PublicKey;
67
- }) => {
68
- adminKey: PublicKey;
69
- }) & {
70
- _isStruct: true;
71
- } & Omit<import("o1js_v1/dist/node/lib/provable/types/provable-intf.js").Provable<{
72
- adminKey: PublicKey;
73
- }, {
74
- adminKey: {
75
- x: bigint;
76
- isOdd: boolean;
77
- };
78
- }>, "fromFields"> & {
79
- fromFields: (fields: import("o1js_v1/dist/node/lib/provable/field.js").Field[]) => {
80
- adminKey: PublicKey;
81
- };
82
- } & {
83
- fromValue: (value: {
84
- adminKey: PublicKey | {
85
- x: Field | bigint;
86
- isOdd: Bool | boolean;
87
- };
88
- }) => {
89
- adminKey: PublicKey;
90
- };
91
- toInput: (x: {
92
- adminKey: PublicKey;
93
- }) => {
94
- fields?: Field[] | undefined;
95
- packed?: [Field, number][] | undefined;
96
- };
97
- toJSON: (x: {
98
- adminKey: PublicKey;
99
- }) => {
100
- adminKey: string;
101
- };
102
- fromJSON: (x: {
103
- adminKey: string;
104
- }) => {
105
- adminKey: PublicKey;
106
- };
107
- empty: () => {
108
- adminKey: PublicKey;
109
- };
110
- };
111
- export declare class SetAdminEvent extends SetAdminEvent_base {
112
- }
113
- declare const PauseEvent_base: (new (value: {
114
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
115
- }) => {
116
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
117
- }) & {
118
- _isStruct: true;
119
- } & Omit<import("o1js_v1/dist/node/lib/provable/types/provable-intf.js").Provable<{
120
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
121
- }, {
122
- isPaused: boolean;
123
- }>, "fromFields"> & {
124
- fromFields: (fields: import("o1js_v1/dist/node/lib/provable/field.js").Field[]) => {
125
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
126
- };
127
- } & {
128
- fromValue: (value: {
129
- isPaused: boolean | import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
130
- }) => {
131
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
132
- };
133
- toInput: (x: {
134
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
135
- }) => {
136
- fields?: Field[] | undefined;
137
- packed?: [Field, number][] | undefined;
138
- };
139
- toJSON: (x: {
140
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
141
- }) => {
142
- isPaused: boolean;
143
- };
144
- fromJSON: (x: {
145
- isPaused: boolean;
146
- }) => {
147
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
148
- };
149
- empty: () => {
150
- isPaused: import("o1js_v1/dist/node/lib/provable/bool.js").Bool;
151
- };
152
- };
153
- export declare class PauseEvent extends PauseEvent_base {
154
- }
155
- declare const MintEvent_base: (new (value: {
156
- recipient: PublicKey;
157
- amount: Types.UInt64;
158
- }) => {
159
- recipient: PublicKey;
160
- amount: Types.UInt64;
161
- }) & {
162
- _isStruct: true;
163
- } & Omit<import("o1js_v1/dist/node/lib/provable/types/provable-intf.js").Provable<{
164
- recipient: PublicKey;
165
- amount: Types.UInt64;
166
- }, {
167
- recipient: {
168
- x: bigint;
169
- isOdd: boolean;
170
- };
171
- amount: bigint;
172
- }>, "fromFields"> & {
173
- fromFields: (fields: import("o1js_v1/dist/node/lib/provable/field.js").Field[]) => {
174
- recipient: PublicKey;
175
- amount: Types.UInt64;
176
- };
177
- } & {
178
- fromValue: (value: {
179
- recipient: PublicKey | {
180
- x: Field | bigint;
181
- isOdd: Bool | boolean;
182
- };
183
- amount: bigint | Types.UInt64;
184
- }) => {
185
- recipient: PublicKey;
186
- amount: Types.UInt64;
187
- };
188
- toInput: (x: {
189
- recipient: PublicKey;
190
- amount: Types.UInt64;
191
- }) => {
192
- fields?: Field[] | undefined;
193
- packed?: [Field, number][] | undefined;
194
- };
195
- toJSON: (x: {
196
- recipient: PublicKey;
197
- amount: Types.UInt64;
198
- }) => {
199
- recipient: string;
200
- amount: string;
201
- };
202
- fromJSON: (x: {
203
- recipient: string;
204
- amount: string;
205
- }) => {
206
- recipient: PublicKey;
207
- amount: Types.UInt64;
208
- };
209
- empty: () => {
210
- recipient: PublicKey;
211
- amount: Types.UInt64;
212
- };
213
- };
214
- export declare class MintEvent extends MintEvent_base {
215
- }
216
- declare const BurnEvent_base: (new (value: {
217
- from: PublicKey;
218
- amount: Types.UInt64;
219
- }) => {
220
- from: PublicKey;
221
- amount: Types.UInt64;
222
- }) & {
223
- _isStruct: true;
224
- } & Omit<import("o1js_v1/dist/node/lib/provable/types/provable-intf.js").Provable<{
225
- from: PublicKey;
226
- amount: Types.UInt64;
227
- }, {
228
- from: {
229
- x: bigint;
230
- isOdd: boolean;
231
- };
232
- amount: bigint;
233
- }>, "fromFields"> & {
234
- fromFields: (fields: import("o1js_v1/dist/node/lib/provable/field.js").Field[]) => {
235
- from: PublicKey;
236
- amount: Types.UInt64;
237
- };
238
- } & {
239
- fromValue: (value: {
240
- from: PublicKey | {
241
- x: Field | bigint;
242
- isOdd: Bool | boolean;
243
- };
244
- amount: bigint | Types.UInt64;
245
- }) => {
246
- from: PublicKey;
247
- amount: Types.UInt64;
248
- };
249
- toInput: (x: {
250
- from: PublicKey;
251
- amount: Types.UInt64;
252
- }) => {
253
- fields?: Field[] | undefined;
254
- packed?: [Field, number][] | undefined;
255
- };
256
- toJSON: (x: {
257
- from: PublicKey;
258
- amount: Types.UInt64;
259
- }) => {
260
- from: string;
261
- amount: string;
262
- };
263
- fromJSON: (x: {
264
- from: string;
265
- amount: string;
266
- }) => {
267
- from: PublicKey;
268
- amount: Types.UInt64;
269
- };
270
- empty: () => {
271
- from: PublicKey;
272
- amount: Types.UInt64;
273
- };
274
- };
275
- export declare class BurnEvent extends BurnEvent_base {
276
- }
277
- declare const BalanceChangeEvent_base: (new (value: {
278
- address: PublicKey;
279
- amount: Int64;
280
- }) => {
281
- address: PublicKey;
282
- amount: Int64;
283
- }) & {
284
- _isStruct: true;
285
- } & Omit<import("o1js_v1/dist/node/lib/provable/types/provable-intf.js").Provable<{
286
- address: PublicKey;
287
- amount: Int64;
288
- }, {
289
- address: {
290
- x: bigint;
291
- isOdd: boolean;
292
- };
293
- amount: any;
294
- }>, "fromFields"> & {
295
- fromFields: (fields: import("o1js_v1/dist/node/lib/provable/field.js").Field[]) => {
296
- address: PublicKey;
297
- amount: Int64;
298
- };
299
- } & {
300
- fromValue: (value: {
301
- address: PublicKey | {
302
- x: Field | bigint;
303
- isOdd: Bool | boolean;
304
- };
305
- amount: any;
306
- }) => {
307
- address: PublicKey;
308
- amount: Int64;
309
- };
310
- toInput: (x: {
311
- address: PublicKey;
312
- amount: Int64;
313
- }) => {
314
- fields?: Field[] | undefined;
315
- packed?: [Field, number][] | undefined;
316
- };
317
- toJSON: (x: {
318
- address: PublicKey;
319
- amount: Int64;
320
- }) => {
321
- address: string;
322
- amount: any;
323
- };
324
- fromJSON: (x: {
325
- address: string;
326
- amount: any;
327
- }) => {
328
- address: PublicKey;
329
- amount: Int64;
330
- };
331
- empty: () => {
332
- address: PublicKey;
333
- amount: Int64;
334
- };
335
- };
336
- export declare class BalanceChangeEvent extends BalanceChangeEvent_base {
337
- }
338
- export {};
@@ -1,308 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BalanceChangeEvent = exports.BurnEvent = exports.MintEvent = exports.PauseEvent = exports.SetAdminEvent = exports.FungibleToken = exports.FungibleTokenErrors = void 0;
13
- const o1js_v1_1 = require("o1js_v1");
14
- const FungibleTokenAdmin_js_1 = require("./FungibleTokenAdmin.js");
15
- exports.FungibleTokenErrors = {
16
- noAdminKey: "could not fetch admin contract key",
17
- noPermissionToChangeAdmin: "Not allowed to change admin contract",
18
- tokenPaused: "Token is currently paused",
19
- noPermissionToMint: "Not allowed to mint tokens",
20
- noPermissionToPause: "Not allowed to pause token",
21
- noPermissionToResume: "Not allowed to resume token",
22
- noTransferFromCirculation: "Can't transfer to/from the circulation account",
23
- noPermissionChangeAllowed: "Can't change permissions for access or receive on token accounts",
24
- flashMinting: "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.",
25
- unbalancedTransaction: "Transaction is unbalanced",
26
- };
27
- class FungibleToken extends o1js_v1_1.TokenContractV2 {
28
- constructor() {
29
- super(...arguments);
30
- this.decimals = (0, o1js_v1_1.State)();
31
- this.admin = (0, o1js_v1_1.State)();
32
- this.paused = (0, o1js_v1_1.State)();
33
- this.events = {
34
- SetAdmin: SetAdminEvent,
35
- Pause: PauseEvent,
36
- Mint: MintEvent,
37
- Burn: BurnEvent,
38
- BalanceChange: BalanceChangeEvent,
39
- };
40
- }
41
- async deploy(props) {
42
- await super.deploy(props);
43
- this.paused.set((0, o1js_v1_1.Bool)(true));
44
- this.account.zkappUri.set(props.src);
45
- this.account.tokenSymbol.set(props.symbol);
46
- this.account.permissions.set({
47
- ...o1js_v1_1.Permissions.default(),
48
- setVerificationKey: o1js_v1_1.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
49
- setPermissions: o1js_v1_1.Permissions.impossible(),
50
- access: o1js_v1_1.Permissions.proof(),
51
- });
52
- }
53
- /** Update the verification key.
54
- * 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.
55
- */
56
- async updateVerificationKey(vk) {
57
- this.account.verificationKey.set(vk);
58
- }
59
- /** Initializes the account for tracking total circulation.
60
- * @argument {PublicKey} admin - public key where the admin contract is deployed
61
- * @argument {UInt8} decimals - number of decimals for the token
62
- * @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
63
- */
64
- async initialize(admin, decimals, startPaused) {
65
- this.account.provedState.requireEquals((0, o1js_v1_1.Bool)(false));
66
- this.admin.set(admin);
67
- this.decimals.set(decimals);
68
- this.paused.set((0, o1js_v1_1.Bool)(false));
69
- this.paused.set(startPaused);
70
- const accountUpdate = o1js_v1_1.AccountUpdate.createSigned(this.address, this.deriveTokenId());
71
- let permissions = o1js_v1_1.Permissions.default();
72
- // This is necessary in order to allow token holders to burn.
73
- permissions.send = o1js_v1_1.Permissions.none();
74
- permissions.setPermissions = o1js_v1_1.Permissions.impossible();
75
- accountUpdate.account.permissions.set(permissions);
76
- }
77
- async getAdminContract() {
78
- const admin = await o1js_v1_1.Provable.witnessAsync(o1js_v1_1.PublicKey, async () => {
79
- let pk = await this.admin.fetch();
80
- (0, o1js_v1_1.assert)(pk !== undefined, exports.FungibleTokenErrors.noAdminKey);
81
- return pk;
82
- });
83
- this.admin.requireEquals(admin);
84
- return new FungibleToken.AdminContract(admin);
85
- }
86
- async setAdmin(admin) {
87
- const adminContract = await this.getAdminContract();
88
- const canChangeAdmin = await adminContract.canChangeAdmin(admin);
89
- canChangeAdmin.assertTrue(exports.FungibleTokenErrors.noPermissionToChangeAdmin);
90
- this.admin.set(admin);
91
- this.emitEvent("SetAdmin", new SetAdminEvent({ adminKey: admin }));
92
- }
93
- async mint(recipient, amount) {
94
- this.paused
95
- .getAndRequireEquals()
96
- .assertFalse(exports.FungibleTokenErrors.tokenPaused);
97
- const accountUpdate = this.internal.mint({ address: recipient, amount });
98
- const adminContract = await this.getAdminContract();
99
- const canMint = await adminContract.canMint(accountUpdate);
100
- canMint.assertTrue(exports.FungibleTokenErrors.noPermissionToMint);
101
- recipient
102
- .equals(this.address)
103
- .assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
104
- this.approve(accountUpdate);
105
- this.emitEvent("Mint", new MintEvent({ recipient, amount }));
106
- const circulationUpdate = o1js_v1_1.AccountUpdate.create(this.address, this.deriveTokenId());
107
- circulationUpdate.balanceChange = o1js_v1_1.Int64.fromUnsigned(amount);
108
- return accountUpdate;
109
- }
110
- async burn(from, amount) {
111
- this.paused
112
- .getAndRequireEquals()
113
- .assertFalse(exports.FungibleTokenErrors.tokenPaused);
114
- const accountUpdate = this.internal.burn({ address: from, amount });
115
- const circulationUpdate = o1js_v1_1.AccountUpdate.create(this.address, this.deriveTokenId());
116
- from
117
- .equals(this.address)
118
- .assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
119
- circulationUpdate.balanceChange = o1js_v1_1.Int64.fromUnsigned(amount).negV2();
120
- this.emitEvent("Burn", new BurnEvent({ from, amount }));
121
- return accountUpdate;
122
- }
123
- async pause() {
124
- const adminContract = await this.getAdminContract();
125
- const canPause = await adminContract.canPause();
126
- canPause.assertTrue(exports.FungibleTokenErrors.noPermissionToPause);
127
- this.paused.set((0, o1js_v1_1.Bool)(true));
128
- this.emitEvent("Pause", new PauseEvent({ isPaused: (0, o1js_v1_1.Bool)(true) }));
129
- }
130
- async resume() {
131
- const adminContract = await this.getAdminContract();
132
- const canResume = await adminContract.canResume();
133
- canResume.assertTrue(exports.FungibleTokenErrors.noPermissionToResume);
134
- this.paused.set((0, o1js_v1_1.Bool)(false));
135
- this.emitEvent("Pause", new PauseEvent({ isPaused: (0, o1js_v1_1.Bool)(false) }));
136
- }
137
- async transfer(from, to, amount) {
138
- this.paused
139
- .getAndRequireEquals()
140
- .assertFalse(exports.FungibleTokenErrors.tokenPaused);
141
- from
142
- .equals(this.address)
143
- .assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
144
- to.equals(this.address).assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
145
- this.internal.send({ from, to, amount });
146
- }
147
- checkPermissionsUpdate(update) {
148
- let permissions = update.update.permissions;
149
- let { access, receive } = permissions.value;
150
- let accessIsNone = o1js_v1_1.Provable.equal(o1js_v1_1.Types.AuthRequired, access, o1js_v1_1.Permissions.none());
151
- let receiveIsNone = o1js_v1_1.Provable.equal(o1js_v1_1.Types.AuthRequired, receive, o1js_v1_1.Permissions.none());
152
- let updateAllowed = accessIsNone.and(receiveIsNone);
153
- (0, o1js_v1_1.assert)(updateAllowed.or(permissions.isSome.not()), exports.FungibleTokenErrors.noPermissionChangeAllowed);
154
- }
155
- /** Approve `AccountUpdate`s that have been created outside of the token contract.
156
- *
157
- * @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.
158
- */
159
- async approveBase(updates) {
160
- this.paused
161
- .getAndRequireEquals()
162
- .assertFalse(exports.FungibleTokenErrors.tokenPaused);
163
- let totalBalance = o1js_v1_1.Int64.from(0);
164
- this.forEachUpdate(updates, (update, usesToken) => {
165
- // Make sure that the account permissions are not changed
166
- this.checkPermissionsUpdate(update);
167
- this.emitEventIf(usesToken, "BalanceChange", new BalanceChangeEvent({
168
- address: update.publicKey,
169
- amount: update.balanceChange,
170
- }));
171
- // Don't allow transfers to/from the account that's tracking circulation
172
- update.publicKey
173
- .equals(this.address)
174
- .and(usesToken)
175
- .assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
176
- totalBalance = o1js_v1_1.Provable.if(usesToken, totalBalance.add(update.balanceChange), totalBalance);
177
- totalBalance.isPositiveV2().assertFalse(exports.FungibleTokenErrors.flashMinting);
178
- });
179
- totalBalance.assertEquals(o1js_v1_1.Int64.zero, exports.FungibleTokenErrors.unbalancedTransaction);
180
- }
181
- async getBalanceOf(address) {
182
- const account = o1js_v1_1.AccountUpdate.create(address, this.deriveTokenId()).account;
183
- const balance = account.balance.get();
184
- account.balance.requireEquals(balance);
185
- return balance;
186
- }
187
- /** Reports the current circulating supply
188
- * This does take into account currently unreduced actions.
189
- */
190
- async getCirculating() {
191
- let circulating = await this.getBalanceOf(this.address);
192
- return circulating;
193
- }
194
- async getDecimals() {
195
- return this.decimals.getAndRequireEquals();
196
- }
197
- }
198
- exports.FungibleToken = FungibleToken;
199
- // This defines the type of the contract that is used to control access to administrative actions.
200
- // If you want to have a custom contract, overwrite this by setting FungibleToken.AdminContract to
201
- // your own implementation of FungibleTokenAdminBase.
202
- FungibleToken.AdminContract = FungibleTokenAdmin_js_1.FungibleTokenAdmin;
203
- __decorate([
204
- (0, o1js_v1_1.state)(o1js_v1_1.UInt8),
205
- __metadata("design:type", Object)
206
- ], FungibleToken.prototype, "decimals", void 0);
207
- __decorate([
208
- (0, o1js_v1_1.state)(o1js_v1_1.PublicKey),
209
- __metadata("design:type", Object)
210
- ], FungibleToken.prototype, "admin", void 0);
211
- __decorate([
212
- (0, o1js_v1_1.state)(o1js_v1_1.Bool),
213
- __metadata("design:type", Object)
214
- ], FungibleToken.prototype, "paused", void 0);
215
- __decorate([
216
- o1js_v1_1.method,
217
- __metadata("design:type", Function),
218
- __metadata("design:paramtypes", [o1js_v1_1.VerificationKey]),
219
- __metadata("design:returntype", Promise)
220
- ], FungibleToken.prototype, "updateVerificationKey", null);
221
- __decorate([
222
- o1js_v1_1.method,
223
- __metadata("design:type", Function),
224
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey, o1js_v1_1.UInt8, o1js_v1_1.Bool]),
225
- __metadata("design:returntype", Promise)
226
- ], FungibleToken.prototype, "initialize", null);
227
- __decorate([
228
- o1js_v1_1.method,
229
- __metadata("design:type", Function),
230
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey]),
231
- __metadata("design:returntype", Promise)
232
- ], FungibleToken.prototype, "setAdmin", null);
233
- __decorate([
234
- o1js_v1_1.method.returns(o1js_v1_1.AccountUpdate),
235
- __metadata("design:type", Function),
236
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey, o1js_v1_1.UInt64]),
237
- __metadata("design:returntype", Promise)
238
- ], FungibleToken.prototype, "mint", null);
239
- __decorate([
240
- o1js_v1_1.method.returns(o1js_v1_1.AccountUpdate),
241
- __metadata("design:type", Function),
242
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey, o1js_v1_1.UInt64]),
243
- __metadata("design:returntype", Promise)
244
- ], FungibleToken.prototype, "burn", null);
245
- __decorate([
246
- o1js_v1_1.method,
247
- __metadata("design:type", Function),
248
- __metadata("design:paramtypes", []),
249
- __metadata("design:returntype", Promise)
250
- ], FungibleToken.prototype, "pause", null);
251
- __decorate([
252
- o1js_v1_1.method,
253
- __metadata("design:type", Function),
254
- __metadata("design:paramtypes", []),
255
- __metadata("design:returntype", Promise)
256
- ], FungibleToken.prototype, "resume", null);
257
- __decorate([
258
- o1js_v1_1.method,
259
- __metadata("design:type", Function),
260
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey, o1js_v1_1.PublicKey, o1js_v1_1.UInt64]),
261
- __metadata("design:returntype", Promise)
262
- ], FungibleToken.prototype, "transfer", null);
263
- __decorate([
264
- o1js_v1_1.method,
265
- __metadata("design:type", Function),
266
- __metadata("design:paramtypes", [o1js_v1_1.AccountUpdateForest]),
267
- __metadata("design:returntype", Promise)
268
- ], FungibleToken.prototype, "approveBase", null);
269
- __decorate([
270
- o1js_v1_1.method.returns(o1js_v1_1.UInt64),
271
- __metadata("design:type", Function),
272
- __metadata("design:paramtypes", [o1js_v1_1.PublicKey]),
273
- __metadata("design:returntype", Promise)
274
- ], FungibleToken.prototype, "getBalanceOf", null);
275
- __decorate([
276
- o1js_v1_1.method.returns(o1js_v1_1.UInt8),
277
- __metadata("design:type", Function),
278
- __metadata("design:paramtypes", []),
279
- __metadata("design:returntype", Promise)
280
- ], FungibleToken.prototype, "getDecimals", null);
281
- class SetAdminEvent extends (0, o1js_v1_1.Struct)({
282
- adminKey: o1js_v1_1.PublicKey,
283
- }) {
284
- }
285
- exports.SetAdminEvent = SetAdminEvent;
286
- class PauseEvent extends (0, o1js_v1_1.Struct)({
287
- isPaused: o1js_v1_1.Bool,
288
- }) {
289
- }
290
- exports.PauseEvent = PauseEvent;
291
- class MintEvent extends (0, o1js_v1_1.Struct)({
292
- recipient: o1js_v1_1.PublicKey,
293
- amount: o1js_v1_1.UInt64,
294
- }) {
295
- }
296
- exports.MintEvent = MintEvent;
297
- class BurnEvent extends (0, o1js_v1_1.Struct)({
298
- from: o1js_v1_1.PublicKey,
299
- amount: o1js_v1_1.UInt64,
300
- }) {
301
- }
302
- exports.BurnEvent = BurnEvent;
303
- class BalanceChangeEvent extends (0, o1js_v1_1.Struct)({
304
- address: o1js_v1_1.PublicKey,
305
- amount: o1js_v1_1.Int64,
306
- }) {
307
- }
308
- exports.BalanceChangeEvent = BalanceChangeEvent;
@@ -1,31 +0,0 @@
1
- import { AccountUpdate, Bool, DeployArgs, PublicKey, SmartContract, VerificationKey } from "o1js_v1";
2
- export type FungibleTokenAdminBase = SmartContract & {
3
- canMint(accountUpdate: AccountUpdate): Promise<Bool>;
4
- canChangeAdmin(admin: PublicKey): Promise<Bool>;
5
- canPause(): Promise<Bool>;
6
- canResume(): Promise<Bool>;
7
- };
8
- export interface FungibleTokenAdminDeployProps extends Exclude<DeployArgs, undefined> {
9
- adminPublicKey: PublicKey;
10
- }
11
- /** A contract that grants permissions for administrative actions on a token.
12
- *
13
- * We separate this out into a dedicated contract. That way, when issuing a token, a user can
14
- * specify their own rules for administrative actions, without changing the token contract itself.
15
- *
16
- * The advantage is that third party applications that only use the token in a non-privileged way
17
- * can integrate against the unchanged token contract.
18
- */
19
- export declare class FungibleTokenAdmin extends SmartContract implements FungibleTokenAdminBase {
20
- private adminPublicKey;
21
- deploy(props: FungibleTokenAdminDeployProps): Promise<void>;
22
- /** Update the verification key.
23
- * 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.
24
- */
25
- updateVerificationKey(vk: VerificationKey): Promise<void>;
26
- private ensureAdminSignature;
27
- canMint(_accountUpdate: AccountUpdate): Promise<import("o1js_v1/dist/node/lib/provable/bool").Bool>;
28
- canChangeAdmin(_admin: PublicKey): Promise<import("o1js_v1/dist/node/lib/provable/bool").Bool>;
29
- canPause(): Promise<Bool>;
30
- canResume(): Promise<Bool>;
31
- }