zkcloudworker 0.18.29 → 0.20.0

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 (37) hide show
  1. package/dist/node/index.cjs +160 -1568
  2. package/dist/node/mina/api/api.js +15 -3
  3. package/dist/node/mina/api/api.js.map +1 -1
  4. package/dist/node/mina/token/api.js +1 -4
  5. package/dist/node/mina/token/api.js.map +1 -1
  6. package/dist/node/mina/token/index.d.ts +0 -7
  7. package/dist/node/mina/token/index.js +0 -7
  8. package/dist/node/mina/token/index.js.map +1 -1
  9. package/dist/node/mina/transactions/transaction.d.ts +15 -3
  10. package/dist/node/mina/transactions/transaction.js +49 -6
  11. package/dist/node/mina/transactions/transaction.js.map +1 -1
  12. package/dist/tsconfig.web.tsbuildinfo +1 -1
  13. package/dist/web/mina/api/api.js +15 -3
  14. package/dist/web/mina/api/api.js.map +1 -1
  15. package/dist/web/mina/token/api.js +1 -4
  16. package/dist/web/mina/token/api.js.map +1 -1
  17. package/dist/web/mina/token/index.d.ts +0 -7
  18. package/dist/web/mina/token/index.js +0 -7
  19. package/dist/web/mina/token/index.js.map +1 -1
  20. package/dist/web/mina/transactions/transaction.d.ts +15 -3
  21. package/dist/web/mina/transactions/transaction.js +49 -6
  22. package/dist/web/mina/transactions/transaction.js.map +1 -1
  23. package/package.json +5 -5
  24. package/src/mina/api/api.ts +15 -3
  25. package/src/mina/token/api.ts +2 -4
  26. package/src/mina/token/index.ts +0 -7
  27. package/src/mina/transactions/transaction.ts +73 -13
  28. package/src/mina/token/FungibleTokenAdmin.ts +0 -89
  29. package/src/mina/token/FungibleTokenContract.ts +0 -327
  30. package/src/mina/token/FungibleTokenWhitelistedAdmin.ts +0 -112
  31. package/src/mina/token/bid.ts +0 -173
  32. package/src/mina/token/build.ts +0 -620
  33. package/src/mina/token/fee.ts +0 -2
  34. package/src/mina/token/offer.ts +0 -174
  35. package/src/mina/token/token.ts +0 -127
  36. package/src/mina/token/vk.ts +0 -42
  37. package/src/mina/token/whitelist.ts +0 -204
@@ -1,173 +0,0 @@
1
- import {
2
- AccountUpdate,
3
- DeployArgs,
4
- method,
5
- Permissions,
6
- PublicKey,
7
- State,
8
- state,
9
- UInt64,
10
- SmartContract,
11
- Bool,
12
- Field,
13
- assert,
14
- Mina,
15
- Struct,
16
- } from "o1js";
17
- import { Whitelist } from "./whitelist.js";
18
- import { FungibleToken, tokenVerificationKeys } from "./token.js";
19
-
20
- export interface FungibleTokenBidContractDeployProps
21
- extends Exclude<DeployArgs, undefined> {
22
- /** The whitelist. */
23
- whitelist: Whitelist;
24
- }
25
- export class FungibleTokenBidContract extends SmartContract {
26
- @state(UInt64) price = State<UInt64>();
27
- @state(PublicKey) buyer = State<PublicKey>();
28
- @state(PublicKey) token = State<PublicKey>();
29
- @state(Whitelist) whitelist = State<Whitelist>();
30
-
31
- async deploy(args: FungibleTokenBidContractDeployProps) {
32
- await super.deploy(args);
33
- const verificationKey =
34
- args?.verificationKey ?? FungibleTokenBidContract._verificationKey;
35
- assert(verificationKey !== undefined);
36
- const hash =
37
- typeof verificationKey.hash === "string"
38
- ? verificationKey.hash
39
- : verificationKey.hash.toJSON();
40
- const networkId = Mina.getNetworkId();
41
- assert(networkId === "mainnet" || networkId === "testnet");
42
- assert(
43
- hash === tokenVerificationKeys[networkId].vk.FungibleTokenBidContract.hash
44
- );
45
- assert(
46
- verificationKey.data ===
47
- tokenVerificationKeys[networkId].vk.FungibleTokenBidContract.data
48
- );
49
- this.whitelist.set(args.whitelist);
50
- this.account.permissions.set({
51
- ...Permissions.default(),
52
- send: Permissions.proof(),
53
- setVerificationKey:
54
- Permissions.VerificationKey.impossibleDuringCurrentVersion(),
55
- setPermissions: Permissions.impossible(),
56
- });
57
- }
58
-
59
- events = {
60
- bid: UInt64,
61
- withdraw: UInt64,
62
- sell: UInt64,
63
- updateWhitelist: Whitelist,
64
- };
65
-
66
- @method async initialize(token: PublicKey, amount: UInt64, price: UInt64) {
67
- this.account.provedState.requireEquals(Bool(false));
68
- amount.equals(UInt64.from(0)).assertFalse();
69
-
70
- const totalPriceField = price.value
71
- .mul(amount.value)
72
- .div(Field(1_000_000_000));
73
- totalPriceField.assertLessThan(
74
- UInt64.MAXINT().value,
75
- "totalPrice overflow"
76
- );
77
- const totalPrice = UInt64.Unsafe.fromField(totalPriceField);
78
-
79
- const buyer = this.sender.getUnconstrained();
80
- const buyerUpdate = AccountUpdate.createSigned(buyer);
81
- buyerUpdate.send({ to: this.address, amount: totalPrice });
82
- buyerUpdate.body.useFullCommitment = Bool(true);
83
-
84
- this.buyer.set(buyer);
85
- this.price.set(price);
86
- this.token.set(token);
87
- this.emitEvent("bid", amount);
88
- }
89
-
90
- @method async bid(amount: UInt64, price: UInt64) {
91
- amount.equals(UInt64.from(0)).assertFalse();
92
-
93
- const balance = this.account.balance.getAndRequireEquals();
94
- const oldPrice = this.price.getAndRequireEquals();
95
- // Price can be changed only when the balance is 0
96
- price
97
- .equals(oldPrice)
98
- .or(balance.equals(UInt64.from(0)))
99
- .assertTrue();
100
- this.price.set(price);
101
-
102
- const totalPriceField = price.value
103
- .mul(amount.value)
104
- .div(Field(1_000_000_000));
105
- totalPriceField.assertLessThan(
106
- UInt64.MAXINT().value,
107
- "totalPrice overflow"
108
- );
109
- const totalPrice = UInt64.Unsafe.fromField(totalPriceField);
110
-
111
- const sender = this.sender.getUnconstrained();
112
- const buyer = this.buyer.getAndRequireEquals();
113
- sender.assertEquals(buyer);
114
- const buyerUpdate = AccountUpdate.createSigned(buyer);
115
- buyerUpdate.send({ to: this.address, amount: totalPrice });
116
- buyerUpdate.body.useFullCommitment = Bool(true);
117
-
118
- this.price.set(price);
119
- this.emitEvent("bid", amount);
120
- }
121
-
122
- @method async withdraw(amountInMina: UInt64) {
123
- amountInMina.equals(UInt64.from(0)).assertFalse();
124
- this.account.balance.requireBetween(amountInMina, UInt64.MAXINT());
125
-
126
- const buyer = this.buyer.getAndRequireEquals();
127
- const sender = this.sender.getUnconstrained();
128
- const senderUpdate = AccountUpdate.createSigned(sender);
129
- senderUpdate.body.useFullCommitment = Bool(true);
130
- sender.assertEquals(buyer);
131
-
132
- let bidUpdate = this.send({ to: senderUpdate, amount: amountInMina });
133
- bidUpdate.body.useFullCommitment = Bool(true);
134
- this.emitEvent("withdraw", amountInMina);
135
- }
136
-
137
- @method async sell(amount: UInt64) {
138
- amount.equals(UInt64.from(0)).assertFalse();
139
- const price = this.price.getAndRequireEquals();
140
- const totalPriceField = price.value
141
- .mul(amount.value)
142
- .div(Field(1_000_000_000));
143
- totalPriceField.assertLessThan(
144
- UInt64.MAXINT().value,
145
- "totalPrice overflow"
146
- );
147
- const totalPrice = UInt64.Unsafe.fromField(totalPriceField);
148
-
149
- this.account.balance.requireBetween(totalPrice, UInt64.MAXINT());
150
- const buyer = this.buyer.getAndRequireEquals();
151
- const token = this.token.getAndRequireEquals();
152
-
153
- const seller = this.sender.getUnconstrained();
154
- const sellerUpdate = this.send({ to: seller, amount: totalPrice });
155
- sellerUpdate.body.useFullCommitment = Bool(true);
156
- sellerUpdate.requireSignature();
157
-
158
- const tokenContract = new FungibleToken(token);
159
- await tokenContract.transfer(seller, buyer, amount);
160
- this.emitEvent("sell", amount);
161
- }
162
-
163
- @method async updateWhitelist(whitelist: Whitelist) {
164
- const buyer = this.buyer.getAndRequireEquals();
165
- const sender = this.sender.getUnconstrained();
166
- const senderUpdate = AccountUpdate.createSigned(sender);
167
- senderUpdate.body.useFullCommitment = Bool(true);
168
- sender.assertEquals(buyer);
169
-
170
- this.whitelist.set(whitelist);
171
- this.emitEvent("updateWhitelist", whitelist);
172
- }
173
- }