zkcloudworker 0.14.9 → 0.15.1
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.
- package/lib/ts/src/mina/index.d.ts +1 -0
- package/lib/ts/src/mina/index.js +1 -0
- package/lib/ts/src/mina/nft/index.d.ts +3 -0
- package/lib/ts/src/mina/nft/index.js +19 -0
- package/lib/ts/src/mina/nft/types.d.ts +1254 -0
- package/lib/ts/src/mina/nft/types.js +236 -0
- package/lib/ts/src/mina/nft/whitelist-admin.d.ts +21 -0
- package/lib/ts/src/mina/nft/whitelist-admin.js +131 -0
- package/lib/ts/src/mina/nft/whitelist.d.ts +20 -0
- package/lib/ts/src/mina/nft/whitelist.js +113 -0
- package/lib/ts/src/mina/token/FungibleToken.d.ts +2 -2
- package/lib/ts/src/mina/token/FungibleToken.js +34 -16
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/mina/index.d.ts +1 -0
- package/lib/web/src/mina/index.js +1 -0
- package/lib/web/src/mina/index.js.map +1 -1
- package/lib/web/src/mina/nft/index.d.ts +3 -0
- package/lib/web/src/mina/nft/index.js +4 -0
- package/lib/web/src/mina/nft/index.js.map +1 -0
- package/lib/web/src/mina/nft/types.d.ts +1254 -0
- package/lib/web/src/mina/nft/types.js +227 -0
- package/lib/web/src/mina/nft/types.js.map +1 -0
- package/lib/web/src/mina/nft/whitelist-admin.d.ts +21 -0
- package/lib/web/src/mina/nft/whitelist-admin.js +120 -0
- package/lib/web/src/mina/nft/whitelist-admin.js.map +1 -0
- package/lib/web/src/mina/nft/whitelist.d.ts +20 -0
- package/lib/web/src/mina/nft/whitelist.js +106 -0
- package/lib/web/src/mina/nft/whitelist.js.map +1 -0
- package/lib/web/src/mina/token/FungibleToken.d.ts +2 -2
- package/lib/web/src/mina/token/FungibleToken.js +36 -18
- package/lib/web/src/mina/token/FungibleToken.js.map +1 -1
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +2 -2
@@ -0,0 +1,236 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NFTUpdateProof = exports.NFTImmutableState = exports.NFTState = exports.CollectionData = exports.NFTData = exports.MintSignatureData = exports.MintParams = exports.Storage = void 0;
|
4
|
+
const o1js_1 = require("o1js");
|
5
|
+
class Storage extends (0, o1js_1.Struct)({
|
6
|
+
url: o1js_1.Provable.Array(o1js_1.Field, 2),
|
7
|
+
}) {
|
8
|
+
constructor(value) {
|
9
|
+
super(value);
|
10
|
+
}
|
11
|
+
static assertEquals(a, b) {
|
12
|
+
a.url[0].assertEquals(b.url[0]);
|
13
|
+
a.url[1].assertEquals(b.url[1]);
|
14
|
+
}
|
15
|
+
static equals(a, b) {
|
16
|
+
return a.url[0].equals(b.url[0]).and(a.url[1].equals(b.url[1]));
|
17
|
+
}
|
18
|
+
static fromURL(url) {
|
19
|
+
const fields = o1js_1.Encoding.stringToFields(url);
|
20
|
+
if (fields.length !== 2)
|
21
|
+
throw new Error("Invalid URL");
|
22
|
+
return new Storage({ url: [fields[0], fields[1]] });
|
23
|
+
}
|
24
|
+
toURL() {
|
25
|
+
return o1js_1.Encoding.stringFromFields(this.url);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.Storage = Storage;
|
29
|
+
class NFTImmutableState extends (0, o1js_1.Struct)({
|
30
|
+
creator: o1js_1.PublicKey, // readonly
|
31
|
+
canChangeOwner: o1js_1.Bool, // readonly
|
32
|
+
canChangeMetadata: o1js_1.Bool, // readonly
|
33
|
+
canChangePrice: o1js_1.Bool, // readonly
|
34
|
+
canChangeStorage: o1js_1.Bool, // readonly
|
35
|
+
canChangeName: o1js_1.Bool, // readonly
|
36
|
+
canChangeMetadataVerificationKeyHash: o1js_1.Bool, // readonly
|
37
|
+
canPause: o1js_1.Bool, // readonly
|
38
|
+
address: o1js_1.PublicKey, // readonly
|
39
|
+
tokenId: o1js_1.Field, // readonly
|
40
|
+
}) {
|
41
|
+
static assertEqual(a, b) {
|
42
|
+
a.creator.assertEquals(b.creator);
|
43
|
+
a.canChangeOwner.assertEquals(b.canChangeOwner);
|
44
|
+
a.canChangeMetadata.assertEquals(b.canChangeMetadata);
|
45
|
+
a.canChangePrice.assertEquals(b.canChangePrice);
|
46
|
+
a.canChangeStorage.assertEquals(b.canChangeStorage);
|
47
|
+
a.canChangeName.assertEquals(b.canChangeName);
|
48
|
+
a.canChangeMetadataVerificationKeyHash.assertEquals(b.canChangeMetadataVerificationKeyHash);
|
49
|
+
a.canPause.assertEquals(b.canPause);
|
50
|
+
a.address.assertEquals(b.address);
|
51
|
+
a.tokenId.assertEquals(b.tokenId);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.NFTImmutableState = NFTImmutableState;
|
55
|
+
class NFTState extends (0, o1js_1.Struct)({
|
56
|
+
immutableState: NFTImmutableState,
|
57
|
+
name: o1js_1.Field,
|
58
|
+
metadata: o1js_1.Field,
|
59
|
+
storage: Storage,
|
60
|
+
owner: o1js_1.PublicKey,
|
61
|
+
price: o1js_1.UInt64,
|
62
|
+
version: o1js_1.UInt32,
|
63
|
+
isPaused: o1js_1.Bool,
|
64
|
+
}) {
|
65
|
+
static assertEqual(a, b) {
|
66
|
+
NFTImmutableState.assertEqual(a.immutableState, b.immutableState);
|
67
|
+
a.name.assertEquals(b.name);
|
68
|
+
a.metadata.assertEquals(b.metadata);
|
69
|
+
Storage.assertEquals(a.storage, b.storage);
|
70
|
+
a.owner.assertEquals(b.owner);
|
71
|
+
a.price.assertEquals(b.price);
|
72
|
+
a.version.assertEquals(b.version);
|
73
|
+
a.isPaused.assertEquals(b.isPaused);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
exports.NFTState = NFTState;
|
77
|
+
class NFTUpdateProof extends o1js_1.DynamicProof {
|
78
|
+
}
|
79
|
+
exports.NFTUpdateProof = NFTUpdateProof;
|
80
|
+
NFTUpdateProof.publicInputType = NFTState;
|
81
|
+
NFTUpdateProof.publicOutputType = NFTState;
|
82
|
+
NFTUpdateProof.maxProofsVerified = 2;
|
83
|
+
NFTUpdateProof.featureFlags = o1js_1.FeatureFlags.allMaybe;
|
84
|
+
class NFTData extends (0, o1js_1.Struct)({
|
85
|
+
price: o1js_1.UInt64,
|
86
|
+
version: o1js_1.UInt32,
|
87
|
+
canChangeOwner: o1js_1.Bool, // readonly
|
88
|
+
canChangeMetadata: o1js_1.Bool, // readonly
|
89
|
+
canChangePrice: o1js_1.Bool, // readonly
|
90
|
+
canChangeStorage: o1js_1.Bool, // readonly
|
91
|
+
canChangeName: o1js_1.Bool, // readonly
|
92
|
+
canChangeMetadataVerificationKeyHash: o1js_1.Bool, // readonly
|
93
|
+
canPause: o1js_1.Bool, // readonly
|
94
|
+
isPaused: o1js_1.Bool,
|
95
|
+
// what else?
|
96
|
+
}) {
|
97
|
+
new(params = {}) {
|
98
|
+
const { price, version, canChangeOwner, canChangeMetadata, canChangePrice, canChangeStorage, canChangeName, canChangeMetadataVerificationKeyHash, canPause, isPaused, } = params;
|
99
|
+
return new NFTData({
|
100
|
+
price: o1js_1.UInt64.from(price ?? 0),
|
101
|
+
version: o1js_1.UInt32.from(version ?? 0),
|
102
|
+
canChangeOwner: (0, o1js_1.Bool)(canChangeOwner ?? true),
|
103
|
+
canChangeMetadata: (0, o1js_1.Bool)(canChangeMetadata ?? false),
|
104
|
+
canChangePrice: (0, o1js_1.Bool)(canChangePrice ?? true),
|
105
|
+
canChangeStorage: (0, o1js_1.Bool)(canChangeStorage ?? false),
|
106
|
+
canChangeName: (0, o1js_1.Bool)(canChangeName ?? false),
|
107
|
+
canChangeMetadataVerificationKeyHash: (0, o1js_1.Bool)(canChangeMetadataVerificationKeyHash ?? false),
|
108
|
+
canPause: (0, o1js_1.Bool)(canPause ?? false),
|
109
|
+
isPaused: (0, o1js_1.Bool)(isPaused ?? false),
|
110
|
+
});
|
111
|
+
}
|
112
|
+
pack() {
|
113
|
+
const price = this.price.value.toBits(64);
|
114
|
+
const version = this.version.value.toBits(32);
|
115
|
+
return o1js_1.Field.fromBits([
|
116
|
+
...price,
|
117
|
+
...version,
|
118
|
+
this.canChangeOwner,
|
119
|
+
this.canChangeMetadata,
|
120
|
+
this.canChangePrice,
|
121
|
+
this.canChangeStorage,
|
122
|
+
this.canChangeName,
|
123
|
+
this.canChangeMetadataVerificationKeyHash,
|
124
|
+
this.canPause,
|
125
|
+
this.isPaused,
|
126
|
+
]);
|
127
|
+
}
|
128
|
+
static unpack(packed) {
|
129
|
+
const bits = packed.toBits(64 + 32 + 8);
|
130
|
+
const price = o1js_1.UInt64.Unsafe.fromField(o1js_1.Field.fromBits(bits.slice(0, 64)));
|
131
|
+
const version = o1js_1.UInt32.Unsafe.fromField(o1js_1.Field.fromBits(bits.slice(64, 64 + 32)));
|
132
|
+
const canChangeOwner = bits[64 + 32];
|
133
|
+
const canChangeMetadata = bits[64 + 32 + 1];
|
134
|
+
const canChangePrice = bits[64 + 32 + 2];
|
135
|
+
const canChangeStorage = bits[64 + 32 + 3];
|
136
|
+
const canChangeName = bits[64 + 32 + 4];
|
137
|
+
const canChangeMetadataVerificationKeyHash = bits[64 + 32 + 5];
|
138
|
+
const canPause = bits[64 + 32 + 6];
|
139
|
+
const isPaused = bits[64 + 32 + 7];
|
140
|
+
return new NFTData({
|
141
|
+
price,
|
142
|
+
version,
|
143
|
+
canChangeOwner,
|
144
|
+
canChangeMetadata,
|
145
|
+
canChangePrice,
|
146
|
+
canChangeStorage,
|
147
|
+
canChangeName,
|
148
|
+
canChangeMetadataVerificationKeyHash,
|
149
|
+
canPause,
|
150
|
+
isPaused,
|
151
|
+
});
|
152
|
+
}
|
153
|
+
}
|
154
|
+
exports.NFTData = NFTData;
|
155
|
+
class CollectionData extends (0, o1js_1.Struct)({
|
156
|
+
requireTransferApproval: o1js_1.Bool,
|
157
|
+
requireUpdateApproval: o1js_1.Bool,
|
158
|
+
requireSaleApproval: o1js_1.Bool,
|
159
|
+
requireBuyApproval: o1js_1.Bool,
|
160
|
+
requireMintApproval: o1js_1.Bool,
|
161
|
+
canMint: o1js_1.Bool,
|
162
|
+
canPause: o1js_1.Bool,
|
163
|
+
canResume: o1js_1.Bool,
|
164
|
+
canChangeName: o1js_1.Bool,
|
165
|
+
canChangeCreator: o1js_1.Bool,
|
166
|
+
canChangeBaseUri: o1js_1.Bool,
|
167
|
+
canChangeSaleCommission: o1js_1.Bool,
|
168
|
+
isPaused: o1js_1.Bool,
|
169
|
+
}) {
|
170
|
+
pack() {
|
171
|
+
return o1js_1.Field.fromBits([
|
172
|
+
this.requireTransferApproval,
|
173
|
+
this.requireUpdateApproval,
|
174
|
+
this.requireSaleApproval,
|
175
|
+
this.requireMintApproval,
|
176
|
+
this.requireBuyApproval,
|
177
|
+
this.canMint,
|
178
|
+
this.canChangeName,
|
179
|
+
this.canChangeCreator,
|
180
|
+
this.canChangeBaseUri,
|
181
|
+
this.canChangeSaleCommission,
|
182
|
+
this.canPause,
|
183
|
+
this.canResume,
|
184
|
+
this.isPaused,
|
185
|
+
]);
|
186
|
+
}
|
187
|
+
static unpack(packed) {
|
188
|
+
const bits = packed.toBits(13);
|
189
|
+
return new CollectionData({
|
190
|
+
requireTransferApproval: bits[0],
|
191
|
+
requireUpdateApproval: bits[1],
|
192
|
+
requireSaleApproval: bits[2],
|
193
|
+
requireMintApproval: bits[3],
|
194
|
+
requireBuyApproval: bits[4],
|
195
|
+
canMint: bits[5],
|
196
|
+
canChangeName: bits[6],
|
197
|
+
canChangeCreator: bits[7],
|
198
|
+
canChangeBaseUri: bits[8],
|
199
|
+
canChangeSaleCommission: bits[9],
|
200
|
+
canPause: bits[10],
|
201
|
+
canResume: bits[11],
|
202
|
+
isPaused: bits[12],
|
203
|
+
});
|
204
|
+
}
|
205
|
+
}
|
206
|
+
exports.CollectionData = CollectionData;
|
207
|
+
class MintParams extends (0, o1js_1.Struct)({
|
208
|
+
name: o1js_1.Field,
|
209
|
+
address: o1js_1.PublicKey,
|
210
|
+
tokenId: o1js_1.Field,
|
211
|
+
owner: o1js_1.PublicKey,
|
212
|
+
data: NFTData,
|
213
|
+
fee: o1js_1.UInt64,
|
214
|
+
metadata: o1js_1.Field,
|
215
|
+
storage: Storage,
|
216
|
+
metadataVerificationKey: o1js_1.VerificationKey,
|
217
|
+
nftVerificationKey: o1js_1.VerificationKey,
|
218
|
+
expiry: o1js_1.UInt32,
|
219
|
+
}) {
|
220
|
+
}
|
221
|
+
exports.MintParams = MintParams;
|
222
|
+
class MintSignatureData extends (0, o1js_1.Struct)({
|
223
|
+
name: o1js_1.Field,
|
224
|
+
address: o1js_1.PublicKey,
|
225
|
+
tokenId: o1js_1.Field,
|
226
|
+
owner: o1js_1.PublicKey,
|
227
|
+
packedData: o1js_1.Field,
|
228
|
+
fee: o1js_1.UInt64,
|
229
|
+
metadata: o1js_1.Field,
|
230
|
+
storage: Storage,
|
231
|
+
metadataVerificationKeyHash: o1js_1.Field,
|
232
|
+
nftVerificationKeyHash: o1js_1.Field,
|
233
|
+
expiry: o1js_1.UInt32,
|
234
|
+
}) {
|
235
|
+
}
|
236
|
+
exports.MintSignatureData = MintSignatureData;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { DeployArgs, PublicKey, SmartContract, State, VerificationKey, UInt64, Field } from "o1js";
|
2
|
+
import { MintParams, NFTState, NFTAdminBase, Storage } from "./types";
|
3
|
+
export interface NFTWhitelistedAdminDeployProps extends Exclude<DeployArgs, undefined> {
|
4
|
+
admin: PublicKey;
|
5
|
+
whitelist: Field;
|
6
|
+
storage: Storage;
|
7
|
+
}
|
8
|
+
export declare class NFTWhitelistedAdmin extends SmartContract implements NFTAdminBase {
|
9
|
+
admin: State<PublicKey>;
|
10
|
+
whitelist: State<import("o1js/dist/node/lib/provable/field").Field>;
|
11
|
+
storage: State<Storage>;
|
12
|
+
deploy(props: NFTWhitelistedAdminDeployProps): Promise<void>;
|
13
|
+
isWhitelisted(address: PublicKey, amount: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
14
|
+
updateVerificationKey(vk: VerificationKey): Promise<void>;
|
15
|
+
canMint(params: MintParams): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
16
|
+
canUpdate(input: NFTState, output: NFTState): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
17
|
+
canTransfer(address: PublicKey, from: PublicKey, to: PublicKey): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
18
|
+
canSell(address: PublicKey, seller: PublicKey, price: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
19
|
+
canBuy(address: PublicKey, seller: PublicKey, buyer: PublicKey, price: UInt64): Promise<import("o1js/dist/node/lib/provable/bool").Bool>;
|
20
|
+
updateMerkleMapRoot(root: Field): Promise<void>;
|
21
|
+
}
|
@@ -0,0 +1,131 @@
|
|
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.NFTWhitelistedAdmin = void 0;
|
13
|
+
const o1js_1 = require("o1js");
|
14
|
+
const whitelist_1 = require("./whitelist");
|
15
|
+
const types_1 = require("./types");
|
16
|
+
class NFTWhitelistedAdmin extends o1js_1.SmartContract {
|
17
|
+
constructor() {
|
18
|
+
super(...arguments);
|
19
|
+
this.admin = (0, o1js_1.State)();
|
20
|
+
this.whitelist = (0, o1js_1.State)();
|
21
|
+
this.storage = (0, o1js_1.State)();
|
22
|
+
}
|
23
|
+
async deploy(props) {
|
24
|
+
await super.deploy(props);
|
25
|
+
this.admin.set(props.admin);
|
26
|
+
this.whitelist.set(props.whitelist);
|
27
|
+
this.storage.set(props.storage);
|
28
|
+
this.account.permissions.set({
|
29
|
+
...o1js_1.Permissions.default(),
|
30
|
+
setVerificationKey: o1js_1.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
31
|
+
setPermissions: o1js_1.Permissions.impossible(),
|
32
|
+
});
|
33
|
+
}
|
34
|
+
async isWhitelisted(address, amount) {
|
35
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
36
|
+
const storage = this.storage.getAndRequireEquals();
|
37
|
+
const map = await o1js_1.Provable.witnessAsync(whitelist_1.Whitelist, async () => {
|
38
|
+
return await (0, whitelist_1.loadWhitelist)(storage);
|
39
|
+
});
|
40
|
+
map.root.assertEquals(whitelist);
|
41
|
+
const key = o1js_1.Poseidon.hash(address.toFields());
|
42
|
+
map.assertIncluded(key, "Address not whitelisted");
|
43
|
+
const value = map.get(key);
|
44
|
+
value.assertLessThanOrEqual((0, o1js_1.Field)(o1js_1.UInt64.MAXINT().value));
|
45
|
+
const maxAmount = o1js_1.UInt64.Unsafe.fromField(value);
|
46
|
+
return (0, o1js_1.Bool)(amount.lessThanOrEqual(maxAmount));
|
47
|
+
}
|
48
|
+
async updateVerificationKey(vk) {
|
49
|
+
const sender = this.sender.getAndRequireSignature();
|
50
|
+
this.admin.getAndRequireEquals().assertEquals(sender);
|
51
|
+
this.account.verificationKey.set(vk);
|
52
|
+
}
|
53
|
+
async canMint(params) {
|
54
|
+
return await this.isWhitelisted(params.owner, o1js_1.UInt64.from(0));
|
55
|
+
}
|
56
|
+
async canUpdate(input, output) {
|
57
|
+
return await this.isWhitelisted(output.owner, o1js_1.UInt64.from(0));
|
58
|
+
}
|
59
|
+
async canTransfer(address, from, to) {
|
60
|
+
return await this.isWhitelisted(to, o1js_1.UInt64.from(0));
|
61
|
+
}
|
62
|
+
async canSell(address, seller, price) {
|
63
|
+
return await this.isWhitelisted(address, price);
|
64
|
+
}
|
65
|
+
async canBuy(address, seller, buyer, price) {
|
66
|
+
return (await this.isWhitelisted(buyer, price)).and(await this.isWhitelisted(seller, price));
|
67
|
+
}
|
68
|
+
async updateMerkleMapRoot(root) {
|
69
|
+
const sender = this.sender.getAndRequireSignature();
|
70
|
+
this.admin.getAndRequireEquals().assertEquals(sender);
|
71
|
+
this.whitelist.set(root);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
exports.NFTWhitelistedAdmin = NFTWhitelistedAdmin;
|
75
|
+
__decorate([
|
76
|
+
(0, o1js_1.state)(o1js_1.PublicKey),
|
77
|
+
__metadata("design:type", Object)
|
78
|
+
], NFTWhitelistedAdmin.prototype, "admin", void 0);
|
79
|
+
__decorate([
|
80
|
+
(0, o1js_1.state)(o1js_1.Field),
|
81
|
+
__metadata("design:type", Object)
|
82
|
+
], NFTWhitelistedAdmin.prototype, "whitelist", void 0);
|
83
|
+
__decorate([
|
84
|
+
(0, o1js_1.state)(types_1.Storage),
|
85
|
+
__metadata("design:type", Object)
|
86
|
+
], NFTWhitelistedAdmin.prototype, "storage", void 0);
|
87
|
+
__decorate([
|
88
|
+
o1js_1.method,
|
89
|
+
__metadata("design:type", Function),
|
90
|
+
__metadata("design:paramtypes", [o1js_1.VerificationKey]),
|
91
|
+
__metadata("design:returntype", Promise)
|
92
|
+
], NFTWhitelistedAdmin.prototype, "updateVerificationKey", null);
|
93
|
+
__decorate([
|
94
|
+
o1js_1.method.returns(o1js_1.Bool),
|
95
|
+
__metadata("design:type", Function),
|
96
|
+
__metadata("design:paramtypes", [types_1.MintParams]),
|
97
|
+
__metadata("design:returntype", Promise)
|
98
|
+
], NFTWhitelistedAdmin.prototype, "canMint", null);
|
99
|
+
__decorate([
|
100
|
+
o1js_1.method.returns(o1js_1.Bool),
|
101
|
+
__metadata("design:type", Function),
|
102
|
+
__metadata("design:paramtypes", [types_1.NFTState, types_1.NFTState]),
|
103
|
+
__metadata("design:returntype", Promise)
|
104
|
+
], NFTWhitelistedAdmin.prototype, "canUpdate", null);
|
105
|
+
__decorate([
|
106
|
+
o1js_1.method.returns(o1js_1.Bool),
|
107
|
+
__metadata("design:type", Function),
|
108
|
+
__metadata("design:paramtypes", [o1js_1.PublicKey, o1js_1.PublicKey, o1js_1.PublicKey]),
|
109
|
+
__metadata("design:returntype", Promise)
|
110
|
+
], NFTWhitelistedAdmin.prototype, "canTransfer", null);
|
111
|
+
__decorate([
|
112
|
+
o1js_1.method.returns(o1js_1.Bool),
|
113
|
+
__metadata("design:type", Function),
|
114
|
+
__metadata("design:paramtypes", [o1js_1.PublicKey, o1js_1.PublicKey, o1js_1.UInt64]),
|
115
|
+
__metadata("design:returntype", Promise)
|
116
|
+
], NFTWhitelistedAdmin.prototype, "canSell", null);
|
117
|
+
__decorate([
|
118
|
+
o1js_1.method.returns(o1js_1.Bool),
|
119
|
+
__metadata("design:type", Function),
|
120
|
+
__metadata("design:paramtypes", [o1js_1.PublicKey,
|
121
|
+
o1js_1.PublicKey,
|
122
|
+
o1js_1.PublicKey,
|
123
|
+
o1js_1.UInt64]),
|
124
|
+
__metadata("design:returntype", Promise)
|
125
|
+
], NFTWhitelistedAdmin.prototype, "canBuy", null);
|
126
|
+
__decorate([
|
127
|
+
o1js_1.method,
|
128
|
+
__metadata("design:type", Function),
|
129
|
+
__metadata("design:paramtypes", [o1js_1.Field]),
|
130
|
+
__metadata("design:returntype", Promise)
|
131
|
+
], NFTWhitelistedAdmin.prototype, "updateMerkleMapRoot", null);
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Storage } from "./types";
|
2
|
+
declare const IndexedMerkleMap: typeof import("o1js/dist/node/lib/provable/merkle-tree-indexed").IndexedMerkleMap;
|
3
|
+
declare const Whitelist_base: typeof import("o1js/dist/node/lib/provable/merkle-tree-indexed").IndexedMerkleMapBase;
|
4
|
+
export declare class Whitelist extends Whitelist_base {
|
5
|
+
}
|
6
|
+
export declare function loadWhitelist(storage: Storage): Promise<Whitelist>;
|
7
|
+
interface IndexedMapSerialized {
|
8
|
+
height: number;
|
9
|
+
root: string;
|
10
|
+
length: string;
|
11
|
+
nodes: string;
|
12
|
+
sortedLeaves: string;
|
13
|
+
}
|
14
|
+
export declare function serializeWhitelist(map: Whitelist): string;
|
15
|
+
export declare function deserializeWhitelist(params: {
|
16
|
+
serializedIndexedMap: string;
|
17
|
+
type?: ReturnType<typeof IndexedMerkleMap>;
|
18
|
+
}): InstanceType<ReturnType<typeof IndexedMerkleMap>> | undefined;
|
19
|
+
export declare function parseIndexedMapSerialized(serializedMap: string): IndexedMapSerialized;
|
20
|
+
export {};
|
@@ -0,0 +1,113 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Whitelist = void 0;
|
4
|
+
exports.loadWhitelist = loadWhitelist;
|
5
|
+
exports.serializeWhitelist = serializeWhitelist;
|
6
|
+
exports.deserializeWhitelist = deserializeWhitelist;
|
7
|
+
exports.parseIndexedMapSerialized = parseIndexedMapSerialized;
|
8
|
+
const o1js_1 = require("o1js");
|
9
|
+
const cloud_1 = require("../../cloud");
|
10
|
+
const { IndexedMerkleMap } = o1js_1.Experimental;
|
11
|
+
const height = 10;
|
12
|
+
class Whitelist extends IndexedMerkleMap(height) {
|
13
|
+
}
|
14
|
+
exports.Whitelist = Whitelist;
|
15
|
+
async function loadWhitelist(storage) {
|
16
|
+
const url = "https://gateway.pinata.cloud/ipfs/" + storage.toURL();
|
17
|
+
const response = await fetch(url);
|
18
|
+
if (!response.ok) {
|
19
|
+
throw new Error("Failed to fetch whitelist");
|
20
|
+
}
|
21
|
+
const json = await response.text();
|
22
|
+
const map = deserializeWhitelist({
|
23
|
+
serializedIndexedMap: json,
|
24
|
+
type: Whitelist,
|
25
|
+
});
|
26
|
+
if (!map) {
|
27
|
+
throw new Error("Failed to deserialize whitelist");
|
28
|
+
}
|
29
|
+
return map;
|
30
|
+
}
|
31
|
+
function serializeWhitelist(map) {
|
32
|
+
const serializedMap = JSON.stringify({
|
33
|
+
height: map.height,
|
34
|
+
root: map.root.toJSON(),
|
35
|
+
length: map.length.toJSON(),
|
36
|
+
nodes: JSON.stringify(map.data.get().nodes, (_, v) => typeof v === "bigint" ? "n" + (0, cloud_1.bigintToBase64)(v) : v),
|
37
|
+
sortedLeaves: JSON.stringify(map.data
|
38
|
+
.get()
|
39
|
+
.sortedLeaves.map((v) => [
|
40
|
+
(0, cloud_1.bigintToBase64)(v.key),
|
41
|
+
(0, cloud_1.bigintToBase64)(v.nextKey),
|
42
|
+
(0, cloud_1.bigintToBase64)(v.value),
|
43
|
+
(0, cloud_1.bigintToBase64)(BigInt(v.index)),
|
44
|
+
])),
|
45
|
+
}, null, 2);
|
46
|
+
return serializedMap;
|
47
|
+
}
|
48
|
+
function deserializeWhitelist(params) {
|
49
|
+
try {
|
50
|
+
const { serializedIndexedMap, type } = params;
|
51
|
+
const json = parseIndexedMapSerialized(serializedIndexedMap);
|
52
|
+
return deserializeIndexedMapInternal({
|
53
|
+
json,
|
54
|
+
type: type ?? IndexedMerkleMap(json.height),
|
55
|
+
});
|
56
|
+
}
|
57
|
+
catch (error) {
|
58
|
+
console.error("Error deserializing map:", error?.message ?? error);
|
59
|
+
return undefined;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
function parseIndexedMapSerialized(serializedMap) {
|
63
|
+
const json = JSON.parse(serializedMap);
|
64
|
+
if (json.height === undefined ||
|
65
|
+
json.root === undefined ||
|
66
|
+
json.length === undefined ||
|
67
|
+
json.nodes === undefined ||
|
68
|
+
json.sortedLeaves === undefined)
|
69
|
+
throw new Error("wrong IndexedMerkleMap json format");
|
70
|
+
if (typeof json.height !== "number")
|
71
|
+
throw new Error("wrong IndexedMerkleMap height format");
|
72
|
+
if (typeof json.root !== "string")
|
73
|
+
throw new Error("wrong IndexedMerkleMap root format");
|
74
|
+
if (typeof json.length !== "string")
|
75
|
+
throw new Error("wrong IndexedMerkleMap length format");
|
76
|
+
if (typeof json.nodes !== "string")
|
77
|
+
throw new Error("wrong IndexedMerkleMap nodes format");
|
78
|
+
if (typeof json.sortedLeaves !== "string")
|
79
|
+
throw new Error("wrong IndexedMerkleMap sortedLeaves format");
|
80
|
+
return json;
|
81
|
+
}
|
82
|
+
function deserializeIndexedMapInternal(params) {
|
83
|
+
const { json, type } = params;
|
84
|
+
const map = new type();
|
85
|
+
if (json.height !== map.height) {
|
86
|
+
throw new Error("wrong IndexedMap height");
|
87
|
+
}
|
88
|
+
const nodes = JSON.parse(json.nodes, (_, v) => {
|
89
|
+
// Check if the value is a string that represents a BigInt
|
90
|
+
if (typeof v === "string" && v[0] === "n") {
|
91
|
+
// Remove the first 'n' and convert the string to a BigInt
|
92
|
+
return (0, cloud_1.bigintFromBase64)(v.slice(1));
|
93
|
+
}
|
94
|
+
return v;
|
95
|
+
});
|
96
|
+
const sortedLeaves = JSON.parse(json.sortedLeaves).map((row) => {
|
97
|
+
return {
|
98
|
+
key: (0, cloud_1.bigintFromBase64)(row[0]),
|
99
|
+
nextKey: (0, cloud_1.bigintFromBase64)(row[1]),
|
100
|
+
value: (0, cloud_1.bigintFromBase64)(row[2]),
|
101
|
+
index: Number((0, cloud_1.bigintFromBase64)(row[3])),
|
102
|
+
};
|
103
|
+
});
|
104
|
+
map.root = o1js_1.Field.fromJSON(json.root);
|
105
|
+
map.length = o1js_1.Field.fromJSON(json.length);
|
106
|
+
map.data.updateAsProver(() => {
|
107
|
+
return {
|
108
|
+
nodes: nodes.map((row) => [...row]),
|
109
|
+
sortedLeaves: [...sortedLeaves],
|
110
|
+
};
|
111
|
+
});
|
112
|
+
return map;
|
113
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AccountUpdate, AccountUpdateForest, Bool, DeployArgs, Field, Int64, PublicKey, State,
|
1
|
+
import { AccountUpdate, AccountUpdateForest, Bool, DeployArgs, Field, Int64, PublicKey, State, TokenContract, Types, UInt64, UInt8, VerificationKey } from "o1js";
|
2
2
|
import { FungibleTokenAdminBase } from "./FungibleTokenAdmin.js";
|
3
3
|
interface FungibleTokenDeployProps extends Exclude<DeployArgs, undefined> {
|
4
4
|
/** The token symbol. */
|
@@ -19,7 +19,7 @@ export declare const FungibleTokenErrors: {
|
|
19
19
|
flashMinting: string;
|
20
20
|
unbalancedTransaction: string;
|
21
21
|
};
|
22
|
-
export declare class FungibleToken extends
|
22
|
+
export declare class FungibleToken extends TokenContract {
|
23
23
|
decimals: State<UInt8>;
|
24
24
|
admin: State<PublicKey>;
|
25
25
|
paused: State<import("o1js/dist/node/lib/provable/bool.js").Bool>;
|
@@ -24,7 +24,7 @@ exports.FungibleTokenErrors = {
|
|
24
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
25
|
unbalancedTransaction: "Transaction is unbalanced",
|
26
26
|
};
|
27
|
-
class FungibleToken extends o1js_1.
|
27
|
+
class FungibleToken extends o1js_1.TokenContract {
|
28
28
|
constructor() {
|
29
29
|
super(...arguments);
|
30
30
|
this.decimals = (0, o1js_1.State)();
|
@@ -81,7 +81,7 @@ class FungibleToken extends o1js_1.TokenContractV2 {
|
|
81
81
|
return pk;
|
82
82
|
});
|
83
83
|
this.admin.requireEquals(admin);
|
84
|
-
return
|
84
|
+
return new FungibleToken.AdminContract(admin);
|
85
85
|
}
|
86
86
|
async setAdmin(admin) {
|
87
87
|
const adminContract = await this.getAdminContract();
|
@@ -91,12 +91,16 @@ class FungibleToken extends o1js_1.TokenContractV2 {
|
|
91
91
|
this.emitEvent("SetAdmin", new SetAdminEvent({ adminKey: admin }));
|
92
92
|
}
|
93
93
|
async mint(recipient, amount) {
|
94
|
-
this.paused
|
94
|
+
this.paused
|
95
|
+
.getAndRequireEquals()
|
96
|
+
.assertFalse(exports.FungibleTokenErrors.tokenPaused);
|
95
97
|
const accountUpdate = this.internal.mint({ address: recipient, amount });
|
96
98
|
const adminContract = await this.getAdminContract();
|
97
99
|
const canMint = await adminContract.canMint(accountUpdate);
|
98
100
|
canMint.assertTrue(exports.FungibleTokenErrors.noPermissionToMint);
|
99
|
-
recipient
|
101
|
+
recipient
|
102
|
+
.equals(this.address)
|
103
|
+
.assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
|
100
104
|
this.approve(accountUpdate);
|
101
105
|
this.emitEvent("Mint", new MintEvent({ recipient, amount }));
|
102
106
|
const circulationUpdate = o1js_1.AccountUpdate.create(this.address, this.deriveTokenId());
|
@@ -104,11 +108,15 @@ class FungibleToken extends o1js_1.TokenContractV2 {
|
|
104
108
|
return accountUpdate;
|
105
109
|
}
|
106
110
|
async burn(from, amount) {
|
107
|
-
this.paused
|
111
|
+
this.paused
|
112
|
+
.getAndRequireEquals()
|
113
|
+
.assertFalse(exports.FungibleTokenErrors.tokenPaused);
|
108
114
|
const accountUpdate = this.internal.burn({ address: from, amount });
|
109
115
|
const circulationUpdate = o1js_1.AccountUpdate.create(this.address, this.deriveTokenId());
|
110
|
-
from
|
111
|
-
|
116
|
+
from
|
117
|
+
.equals(this.address)
|
118
|
+
.assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
|
119
|
+
circulationUpdate.balanceChange = o1js_1.Int64.fromUnsigned(amount).neg();
|
112
120
|
this.emitEvent("Burn", new BurnEvent({ from, amount }));
|
113
121
|
return accountUpdate;
|
114
122
|
}
|
@@ -127,8 +135,12 @@ class FungibleToken extends o1js_1.TokenContractV2 {
|
|
127
135
|
this.emitEvent("Pause", new PauseEvent({ isPaused: (0, o1js_1.Bool)(false) }));
|
128
136
|
}
|
129
137
|
async transfer(from, to, amount) {
|
130
|
-
this.paused
|
131
|
-
|
138
|
+
this.paused
|
139
|
+
.getAndRequireEquals()
|
140
|
+
.assertFalse(exports.FungibleTokenErrors.tokenPaused);
|
141
|
+
from
|
142
|
+
.equals(this.address)
|
143
|
+
.assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
|
132
144
|
to.equals(this.address).assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
|
133
145
|
this.internal.send({ from, to, amount });
|
134
146
|
}
|
@@ -145,16 +157,24 @@ class FungibleToken extends o1js_1.TokenContractV2 {
|
|
145
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.
|
146
158
|
*/
|
147
159
|
async approveBase(updates) {
|
148
|
-
this.paused
|
160
|
+
this.paused
|
161
|
+
.getAndRequireEquals()
|
162
|
+
.assertFalse(exports.FungibleTokenErrors.tokenPaused);
|
149
163
|
let totalBalance = o1js_1.Int64.from(0);
|
150
164
|
this.forEachUpdate(updates, (update, usesToken) => {
|
151
165
|
// Make sure that the account permissions are not changed
|
152
166
|
this.checkPermissionsUpdate(update);
|
153
|
-
this.emitEventIf(usesToken, "BalanceChange", new BalanceChangeEvent({
|
167
|
+
this.emitEventIf(usesToken, "BalanceChange", new BalanceChangeEvent({
|
168
|
+
address: update.publicKey,
|
169
|
+
amount: update.balanceChange,
|
170
|
+
}));
|
154
171
|
// Don't allow transfers to/from the account that's tracking circulation
|
155
|
-
update.publicKey
|
172
|
+
update.publicKey
|
173
|
+
.equals(this.address)
|
174
|
+
.and(usesToken)
|
175
|
+
.assertFalse(exports.FungibleTokenErrors.noTransferFromCirculation);
|
156
176
|
totalBalance = o1js_1.Provable.if(usesToken, totalBalance.add(update.balanceChange), totalBalance);
|
157
|
-
totalBalance.
|
177
|
+
totalBalance.isPositive().assertFalse(exports.FungibleTokenErrors.flashMinting);
|
158
178
|
});
|
159
179
|
totalBalance.assertEquals(o1js_1.Int64.zero, exports.FungibleTokenErrors.unbalancedTransaction);
|
160
180
|
}
|
@@ -201,9 +221,7 @@ __decorate([
|
|
201
221
|
__decorate([
|
202
222
|
o1js_1.method,
|
203
223
|
__metadata("design:type", Function),
|
204
|
-
__metadata("design:paramtypes", [o1js_1.PublicKey,
|
205
|
-
o1js_1.UInt8,
|
206
|
-
o1js_1.Bool]),
|
224
|
+
__metadata("design:paramtypes", [o1js_1.PublicKey, o1js_1.UInt8, o1js_1.Bool]),
|
207
225
|
__metadata("design:returntype", Promise)
|
208
226
|
], FungibleToken.prototype, "initialize", null);
|
209
227
|
__decorate([
|