@zoralabs/protocol-sdk 0.9.2 → 0.9.4-PRE.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.
- package/.env +1 -0
- package/.turbo/turbo-build.log +18 -18
- package/CHANGELOG.md +13 -0
- package/dist/create/minter-defaults.d.ts +1 -1
- package/dist/create/minter-defaults.d.ts.map +1 -1
- package/dist/create/token-setup.d.ts +2 -0
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/index.cjs +2094 -2106
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2127 -2139
- package/dist/index.js.map +1 -1
- package/package.json +15 -14
- package/src/create/1155-create-helper.test.ts +46 -2
- package/src/create/1155-create-helper.ts +6 -1
- package/src/create/minter-defaults.ts +11 -20
- package/src/create/token-setup.ts +5 -1
- package/src/create/types.ts +1 -1
- package/yarn-error.log +8602 -0
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -4297,2279 +4297,2267 @@ var semver2 = __toESM(require_semver2(), 1);
|
|
|
4297
4297
|
import { zoraCreator1155ImplABI as zoraCreator1155ImplABI5 } from "@zoralabs/protocol-deployments";
|
|
4298
4298
|
import { encodeFunctionData as encodeFunctionData2, zeroAddress as zeroAddress5 } from "viem";
|
|
4299
4299
|
|
|
4300
|
-
// src/
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
//
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
}
|
|
4318
|
-
return true;
|
|
4319
|
-
}
|
|
4320
|
-
function coerce2(o) {
|
|
4321
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
4322
|
-
return o;
|
|
4323
|
-
if (o instanceof ArrayBuffer)
|
|
4324
|
-
return new Uint8Array(o);
|
|
4325
|
-
if (ArrayBuffer.isView(o)) {
|
|
4326
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
4327
|
-
}
|
|
4328
|
-
throw new Error("Unknown type, must be binary type");
|
|
4329
|
-
}
|
|
4330
|
-
|
|
4331
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
4332
|
-
function base2(ALPHABET, name) {
|
|
4333
|
-
if (ALPHABET.length >= 255) {
|
|
4334
|
-
throw new TypeError("Alphabet too long");
|
|
4335
|
-
}
|
|
4336
|
-
var BASE_MAP = new Uint8Array(256);
|
|
4337
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
4338
|
-
BASE_MAP[j] = 255;
|
|
4339
|
-
}
|
|
4340
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
4341
|
-
var x = ALPHABET.charAt(i);
|
|
4342
|
-
var xc = x.charCodeAt(0);
|
|
4343
|
-
if (BASE_MAP[xc] !== 255) {
|
|
4344
|
-
throw new TypeError(x + " is ambiguous");
|
|
4345
|
-
}
|
|
4346
|
-
BASE_MAP[xc] = i;
|
|
4347
|
-
}
|
|
4348
|
-
var BASE = ALPHABET.length;
|
|
4349
|
-
var LEADER = ALPHABET.charAt(0);
|
|
4350
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
4351
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
4352
|
-
function encode3(source) {
|
|
4353
|
-
if (source instanceof Uint8Array)
|
|
4354
|
-
;
|
|
4355
|
-
else if (ArrayBuffer.isView(source)) {
|
|
4356
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
4357
|
-
} else if (Array.isArray(source)) {
|
|
4358
|
-
source = Uint8Array.from(source);
|
|
4359
|
-
}
|
|
4360
|
-
if (!(source instanceof Uint8Array)) {
|
|
4361
|
-
throw new TypeError("Expected Uint8Array");
|
|
4362
|
-
}
|
|
4363
|
-
if (source.length === 0) {
|
|
4364
|
-
return "";
|
|
4365
|
-
}
|
|
4366
|
-
var zeroes = 0;
|
|
4367
|
-
var length2 = 0;
|
|
4368
|
-
var pbegin = 0;
|
|
4369
|
-
var pend = source.length;
|
|
4370
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
4371
|
-
pbegin++;
|
|
4372
|
-
zeroes++;
|
|
4373
|
-
}
|
|
4374
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
4375
|
-
var b58 = new Uint8Array(size);
|
|
4376
|
-
while (pbegin !== pend) {
|
|
4377
|
-
var carry = source[pbegin];
|
|
4378
|
-
var i2 = 0;
|
|
4379
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
4380
|
-
carry += 256 * b58[it1] >>> 0;
|
|
4381
|
-
b58[it1] = carry % BASE >>> 0;
|
|
4382
|
-
carry = carry / BASE >>> 0;
|
|
4383
|
-
}
|
|
4384
|
-
if (carry !== 0) {
|
|
4385
|
-
throw new Error("Non-zero carry");
|
|
4386
|
-
}
|
|
4387
|
-
length2 = i2;
|
|
4388
|
-
pbegin++;
|
|
4389
|
-
}
|
|
4390
|
-
var it2 = size - length2;
|
|
4391
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
4392
|
-
it2++;
|
|
4393
|
-
}
|
|
4394
|
-
var str = LEADER.repeat(zeroes);
|
|
4395
|
-
for (; it2 < size; ++it2) {
|
|
4396
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
4397
|
-
}
|
|
4398
|
-
return str;
|
|
4399
|
-
}
|
|
4400
|
-
function decodeUnsafe(source) {
|
|
4401
|
-
if (typeof source !== "string") {
|
|
4402
|
-
throw new TypeError("Expected String");
|
|
4403
|
-
}
|
|
4404
|
-
if (source.length === 0) {
|
|
4405
|
-
return new Uint8Array();
|
|
4406
|
-
}
|
|
4407
|
-
var psz = 0;
|
|
4408
|
-
if (source[psz] === " ") {
|
|
4409
|
-
return;
|
|
4410
|
-
}
|
|
4411
|
-
var zeroes = 0;
|
|
4412
|
-
var length2 = 0;
|
|
4413
|
-
while (source[psz] === LEADER) {
|
|
4414
|
-
zeroes++;
|
|
4415
|
-
psz++;
|
|
4416
|
-
}
|
|
4417
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
4418
|
-
var b256 = new Uint8Array(size);
|
|
4419
|
-
while (source[psz]) {
|
|
4420
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
4421
|
-
if (carry === 255) {
|
|
4422
|
-
return;
|
|
4423
|
-
}
|
|
4424
|
-
var i2 = 0;
|
|
4425
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
4426
|
-
carry += BASE * b256[it3] >>> 0;
|
|
4427
|
-
b256[it3] = carry % 256 >>> 0;
|
|
4428
|
-
carry = carry / 256 >>> 0;
|
|
4429
|
-
}
|
|
4430
|
-
if (carry !== 0) {
|
|
4431
|
-
throw new Error("Non-zero carry");
|
|
4432
|
-
}
|
|
4433
|
-
length2 = i2;
|
|
4434
|
-
psz++;
|
|
4435
|
-
}
|
|
4436
|
-
if (source[psz] === " ") {
|
|
4437
|
-
return;
|
|
4438
|
-
}
|
|
4439
|
-
var it4 = size - length2;
|
|
4440
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
4441
|
-
it4++;
|
|
4442
|
-
}
|
|
4443
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
4444
|
-
var j2 = zeroes;
|
|
4445
|
-
while (it4 !== size) {
|
|
4446
|
-
vch[j2++] = b256[it4++];
|
|
4447
|
-
}
|
|
4448
|
-
return vch;
|
|
4449
|
-
}
|
|
4450
|
-
function decode5(string) {
|
|
4451
|
-
var buffer = decodeUnsafe(string);
|
|
4452
|
-
if (buffer) {
|
|
4453
|
-
return buffer;
|
|
4454
|
-
}
|
|
4455
|
-
throw new Error(`Non-${name} character`);
|
|
4456
|
-
}
|
|
4300
|
+
// src/create/minter-defaults.ts
|
|
4301
|
+
var SALE_END_FOREVER = 18446744073709551615n;
|
|
4302
|
+
var DEFAULT_SALE_START_AND_END = {
|
|
4303
|
+
// Sale start time – defaults to beginning of unix time
|
|
4304
|
+
saleStart: 0n,
|
|
4305
|
+
// This is the end of uint64, plenty of time
|
|
4306
|
+
saleEnd: SALE_END_FOREVER
|
|
4307
|
+
};
|
|
4308
|
+
var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
|
|
4309
|
+
maxTokensPerAddress: 0n
|
|
4310
|
+
};
|
|
4311
|
+
var erc20SaleSettingsWithDefaults = (params) => ({
|
|
4312
|
+
...DEFAULT_SALE_START_AND_END,
|
|
4313
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
4314
|
+
...params
|
|
4315
|
+
});
|
|
4316
|
+
var allowListWithDefaults = (allowlist) => {
|
|
4457
4317
|
return {
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
decode: decode5
|
|
4318
|
+
...DEFAULT_SALE_START_AND_END,
|
|
4319
|
+
...allowlist
|
|
4461
4320
|
};
|
|
4462
|
-
}
|
|
4463
|
-
var
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
__publicField(this, "baseEncode");
|
|
4473
|
-
this.name = name;
|
|
4474
|
-
this.prefix = prefix;
|
|
4475
|
-
this.baseEncode = baseEncode;
|
|
4321
|
+
};
|
|
4322
|
+
var fixedPriceSettingsWithDefaults = (params) => ({
|
|
4323
|
+
...DEFAULT_SALE_START_AND_END,
|
|
4324
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
4325
|
+
type: "fixedPrice",
|
|
4326
|
+
...params
|
|
4327
|
+
});
|
|
4328
|
+
var parseNameIntoSymbol = (name) => {
|
|
4329
|
+
if (name === "") {
|
|
4330
|
+
throw new Error("Name must be provided to generate a symbol");
|
|
4476
4331
|
}
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
} else {
|
|
4481
|
-
throw Error("Unknown type, must be binary type");
|
|
4482
|
-
}
|
|
4332
|
+
const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
|
|
4333
|
+
if (result === "$") {
|
|
4334
|
+
throw new Error("Not enough valid characters to generate a symbol");
|
|
4483
4335
|
}
|
|
4336
|
+
return result;
|
|
4484
4337
|
};
|
|
4485
|
-
var
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4338
|
+
var timedSaleSettingsWithDefaults = async (params, contractName) => {
|
|
4339
|
+
const erc20Name = params.erc20Name || contractName;
|
|
4340
|
+
const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
|
|
4341
|
+
return {
|
|
4342
|
+
type: "timed",
|
|
4343
|
+
...DEFAULT_SALE_START_AND_END,
|
|
4344
|
+
...params,
|
|
4345
|
+
erc20Name,
|
|
4346
|
+
erc20Symbol: symbol
|
|
4347
|
+
};
|
|
4348
|
+
};
|
|
4349
|
+
var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
4350
|
+
var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
4351
|
+
var isFixedPrice = (salesConfig) => {
|
|
4352
|
+
return salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > 0n;
|
|
4353
|
+
};
|
|
4354
|
+
var getSalesConfigWithDefaults = async (salesConfig, contractName) => {
|
|
4355
|
+
if (!salesConfig)
|
|
4356
|
+
return timedSaleSettingsWithDefaults({}, contractName);
|
|
4357
|
+
if (isAllowList(salesConfig)) {
|
|
4358
|
+
return allowListWithDefaults(salesConfig);
|
|
4498
4359
|
}
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
4502
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
4503
|
-
}
|
|
4504
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
4505
|
-
} else {
|
|
4506
|
-
throw Error("Can only multibase decode strings");
|
|
4507
|
-
}
|
|
4360
|
+
if (isErc20(salesConfig)) {
|
|
4361
|
+
return erc20SaleSettingsWithDefaults(salesConfig);
|
|
4508
4362
|
}
|
|
4509
|
-
|
|
4510
|
-
return
|
|
4363
|
+
if (isFixedPrice(salesConfig)) {
|
|
4364
|
+
return fixedPriceSettingsWithDefaults(salesConfig);
|
|
4511
4365
|
}
|
|
4366
|
+
return timedSaleSettingsWithDefaults(salesConfig, contractName);
|
|
4512
4367
|
};
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
}
|
|
4368
|
+
|
|
4369
|
+
// src/create/minter-setup.ts
|
|
4370
|
+
import {
|
|
4371
|
+
erc20MinterABI as erc20MinterABI2,
|
|
4372
|
+
erc20MinterAddress as erc20MinterAddresses,
|
|
4373
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
|
|
4374
|
+
zoraCreatorFixedPriceSaleStrategyABI,
|
|
4375
|
+
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2,
|
|
4376
|
+
zoraCreatorMerkleMinterStrategyABI,
|
|
4377
|
+
zoraCreatorMerkleMinterStrategyAddress,
|
|
4378
|
+
zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI2,
|
|
4379
|
+
zoraTimedSaleStrategyAddress
|
|
4380
|
+
} from "@zoralabs/protocol-deployments";
|
|
4381
|
+
import { encodeFunctionData } from "viem";
|
|
4382
|
+
var PERMISSION_BITS = {
|
|
4383
|
+
MINTER: 2n ** 2n
|
|
4530
4384
|
};
|
|
4531
|
-
function
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4385
|
+
function setupErc20Minter({
|
|
4386
|
+
pricePerToken,
|
|
4387
|
+
chainId,
|
|
4388
|
+
tokenId: nextTokenId,
|
|
4389
|
+
currency,
|
|
4390
|
+
saleStart,
|
|
4391
|
+
saleEnd,
|
|
4392
|
+
maxTokensPerAddress: mintLimit,
|
|
4393
|
+
fundsRecipient
|
|
4394
|
+
}) {
|
|
4395
|
+
const erc20MinterAddress = erc20MinterAddresses[chainId];
|
|
4396
|
+
if (!erc20MinterAddress)
|
|
4397
|
+
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
4398
|
+
const erc20MinterApproval = encodeFunctionData({
|
|
4399
|
+
abi: zoraCreator1155ImplABI4,
|
|
4400
|
+
functionName: "addPermission",
|
|
4401
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
4402
|
+
});
|
|
4403
|
+
const saleData = encodeFunctionData({
|
|
4404
|
+
abi: erc20MinterABI2,
|
|
4405
|
+
functionName: "setSale",
|
|
4406
|
+
args: [
|
|
4407
|
+
BigInt(nextTokenId),
|
|
4408
|
+
{
|
|
4409
|
+
saleStart: saleStart || BigInt(0),
|
|
4410
|
+
saleEnd: saleEnd || BigInt(0),
|
|
4411
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
4412
|
+
pricePerToken,
|
|
4413
|
+
fundsRecipient,
|
|
4414
|
+
currency
|
|
4415
|
+
}
|
|
4416
|
+
]
|
|
4417
|
+
});
|
|
4418
|
+
const callSale = encodeFunctionData({
|
|
4419
|
+
abi: zoraCreator1155ImplABI4,
|
|
4420
|
+
functionName: "callSale",
|
|
4421
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
|
|
4535
4422
|
});
|
|
4423
|
+
return {
|
|
4424
|
+
minter: erc20MinterAddress,
|
|
4425
|
+
setupActions: [erc20MinterApproval, callSale]
|
|
4426
|
+
};
|
|
4536
4427
|
}
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4428
|
+
function setupFixedPriceMinter({
|
|
4429
|
+
pricePerToken: price,
|
|
4430
|
+
tokenId: nextTokenId,
|
|
4431
|
+
chainId,
|
|
4432
|
+
saleStart,
|
|
4433
|
+
saleEnd,
|
|
4434
|
+
maxTokensPerAddress: mintLimit,
|
|
4435
|
+
fundsRecipient
|
|
4436
|
+
}) {
|
|
4437
|
+
const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
|
|
4438
|
+
const fixedPriceApproval = encodeFunctionData({
|
|
4439
|
+
abi: zoraCreator1155ImplABI4,
|
|
4440
|
+
functionName: "addPermission",
|
|
4441
|
+
args: [
|
|
4442
|
+
BigInt(nextTokenId),
|
|
4443
|
+
fixedPriceStrategyAddress,
|
|
4444
|
+
PERMISSION_BITS.MINTER
|
|
4445
|
+
]
|
|
4446
|
+
});
|
|
4447
|
+
const saleData = encodeFunctionData({
|
|
4448
|
+
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
4449
|
+
functionName: "setSale",
|
|
4450
|
+
args: [
|
|
4451
|
+
BigInt(nextTokenId),
|
|
4452
|
+
{
|
|
4453
|
+
pricePerToken: price,
|
|
4454
|
+
saleStart: saleStart || BigInt(0),
|
|
4455
|
+
saleEnd: saleEnd || BigInt(0),
|
|
4456
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
4457
|
+
fundsRecipient
|
|
4458
|
+
}
|
|
4459
|
+
]
|
|
4460
|
+
});
|
|
4461
|
+
const callSale = encodeFunctionData({
|
|
4462
|
+
abi: zoraCreator1155ImplABI4,
|
|
4463
|
+
functionName: "callSale",
|
|
4464
|
+
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
4465
|
+
});
|
|
4466
|
+
return {
|
|
4467
|
+
minter: fixedPriceStrategyAddress,
|
|
4468
|
+
setupActions: [fixedPriceApproval, callSale]
|
|
4469
|
+
};
|
|
4561
4470
|
}
|
|
4562
|
-
function
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4471
|
+
function setupTimedSaleMinter({
|
|
4472
|
+
chainId,
|
|
4473
|
+
tokenId,
|
|
4474
|
+
erc20Name: erc20zName,
|
|
4475
|
+
erc20Symbol: erc20zSymbol,
|
|
4476
|
+
saleStart,
|
|
4477
|
+
saleEnd
|
|
4478
|
+
}) {
|
|
4479
|
+
const minterAddress = zoraTimedSaleStrategyAddress[chainId];
|
|
4480
|
+
const fixedPriceApproval = encodeFunctionData({
|
|
4481
|
+
abi: zoraCreator1155ImplABI4,
|
|
4482
|
+
functionName: "addPermission",
|
|
4483
|
+
args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
|
|
4484
|
+
});
|
|
4485
|
+
const saleData = encodeFunctionData({
|
|
4486
|
+
abi: zoraTimedSaleStrategyABI2,
|
|
4487
|
+
functionName: "setSale",
|
|
4488
|
+
args: [
|
|
4489
|
+
BigInt(tokenId),
|
|
4490
|
+
{
|
|
4491
|
+
saleStart,
|
|
4492
|
+
saleEnd,
|
|
4493
|
+
name: erc20zName,
|
|
4494
|
+
symbol: erc20zSymbol
|
|
4495
|
+
}
|
|
4496
|
+
]
|
|
4569
4497
|
});
|
|
4498
|
+
const callSale = encodeFunctionData({
|
|
4499
|
+
abi: zoraCreator1155ImplABI4,
|
|
4500
|
+
functionName: "callSale",
|
|
4501
|
+
args: [BigInt(tokenId), minterAddress, saleData]
|
|
4502
|
+
});
|
|
4503
|
+
return {
|
|
4504
|
+
minter: minterAddress,
|
|
4505
|
+
setupActions: [fixedPriceApproval, callSale]
|
|
4506
|
+
};
|
|
4570
4507
|
}
|
|
4571
|
-
function
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4508
|
+
function setupAllowListMinter({
|
|
4509
|
+
chainId,
|
|
4510
|
+
tokenId: nextTokenId,
|
|
4511
|
+
allowlist,
|
|
4512
|
+
fundsRecipient
|
|
4513
|
+
}) {
|
|
4514
|
+
const merkleSaleStrategyAddress = zoraCreatorMerkleMinterStrategyAddress[chainId];
|
|
4515
|
+
const merkleApproval = encodeFunctionData({
|
|
4516
|
+
abi: zoraCreator1155ImplABI4,
|
|
4517
|
+
functionName: "addPermission",
|
|
4518
|
+
args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
|
|
4519
|
+
});
|
|
4520
|
+
const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
|
|
4521
|
+
const saleData = encodeFunctionData({
|
|
4522
|
+
abi: zoraCreatorMerkleMinterStrategyABI,
|
|
4523
|
+
functionName: "setSale",
|
|
4524
|
+
args: [
|
|
4525
|
+
BigInt(nextTokenId),
|
|
4526
|
+
{
|
|
4527
|
+
presaleStart: allowlist.saleStart,
|
|
4528
|
+
presaleEnd: allowlist.saleEnd,
|
|
4529
|
+
merkleRoot,
|
|
4530
|
+
fundsRecipient
|
|
4531
|
+
}
|
|
4532
|
+
]
|
|
4533
|
+
});
|
|
4534
|
+
const callSaleMerkle = encodeFunctionData({
|
|
4535
|
+
abi: zoraCreator1155ImplABI4,
|
|
4536
|
+
functionName: "callSale",
|
|
4537
|
+
args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
|
|
4538
|
+
});
|
|
4539
|
+
return {
|
|
4540
|
+
minter: merkleSaleStrategyAddress,
|
|
4541
|
+
setupActions: [merkleApproval, callSaleMerkle]
|
|
4542
|
+
};
|
|
4543
|
+
}
|
|
4544
|
+
var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
4545
|
+
var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
4546
|
+
var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
|
|
4547
|
+
function setupMinters({ salesConfig, ...rest }) {
|
|
4548
|
+
if (isErc202(salesConfig)) {
|
|
4549
|
+
return setupErc20Minter({
|
|
4550
|
+
...salesConfig,
|
|
4551
|
+
...rest
|
|
4552
|
+
});
|
|
4575
4553
|
}
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4554
|
+
if (isAllowList2(salesConfig)) {
|
|
4555
|
+
return setupAllowListMinter({
|
|
4556
|
+
allowlist: salesConfig,
|
|
4557
|
+
...rest
|
|
4558
|
+
});
|
|
4579
4559
|
}
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4560
|
+
if (isFixedPrice2(salesConfig))
|
|
4561
|
+
return setupFixedPriceMinter({
|
|
4562
|
+
...salesConfig,
|
|
4563
|
+
...rest
|
|
4564
|
+
});
|
|
4565
|
+
return setupTimedSaleMinter({
|
|
4566
|
+
...salesConfig,
|
|
4567
|
+
...rest
|
|
4568
|
+
});
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
// src/create/token-setup.ts
|
|
4572
|
+
async function applyNew1155Defaults(props, ownerAddress, contractName) {
|
|
4573
|
+
const { payoutRecipient: fundsRecipient } = props;
|
|
4574
|
+
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress5 ? fundsRecipient : ownerAddress;
|
|
4575
|
+
return {
|
|
4576
|
+
payoutRecipient: fundsRecipientOrOwner,
|
|
4577
|
+
createReferral: props.createReferral || zeroAddress5,
|
|
4578
|
+
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
4579
|
+
royaltyBPS: props.royaltyBPS || 1e3,
|
|
4580
|
+
tokenMetadataURI: props.tokenMetadataURI,
|
|
4581
|
+
salesConfig: await getSalesConfigWithDefaults(
|
|
4582
|
+
props.salesConfig,
|
|
4583
|
+
contractName
|
|
4584
|
+
)
|
|
4585
|
+
};
|
|
4586
|
+
}
|
|
4587
|
+
function buildSetupNewToken({
|
|
4588
|
+
tokenURI,
|
|
4589
|
+
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
4590
|
+
createReferral = zeroAddress5,
|
|
4591
|
+
contractVersion
|
|
4592
|
+
}) {
|
|
4593
|
+
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
4594
|
+
return encodeFunctionData2({
|
|
4595
|
+
abi: zoraCreator1155ImplABI5,
|
|
4596
|
+
functionName: "setupNewTokenWithCreateReferral",
|
|
4597
|
+
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
4598
|
+
});
|
|
4595
4599
|
}
|
|
4596
|
-
if (
|
|
4597
|
-
throw new
|
|
4600
|
+
if (createReferral !== zeroAddress5) {
|
|
4601
|
+
throw new Error(
|
|
4602
|
+
"Contract does not support create referral, but one was provided"
|
|
4603
|
+
);
|
|
4598
4604
|
}
|
|
4599
|
-
return
|
|
4605
|
+
return encodeFunctionData2({
|
|
4606
|
+
abi: zoraCreator1155ImplABI5,
|
|
4607
|
+
functionName: "setupNewToken",
|
|
4608
|
+
args: [tokenURI, BigInt(maxSupply)]
|
|
4609
|
+
});
|
|
4600
4610
|
}
|
|
4601
|
-
function
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4611
|
+
function setupRoyaltyConfig({
|
|
4612
|
+
royaltyBPS,
|
|
4613
|
+
royaltyRecipient,
|
|
4614
|
+
nextTokenId
|
|
4615
|
+
}) {
|
|
4616
|
+
if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
|
|
4617
|
+
return encodeFunctionData2({
|
|
4618
|
+
abi: zoraCreator1155ImplABI5,
|
|
4619
|
+
functionName: "updateRoyaltiesForToken",
|
|
4620
|
+
args: [
|
|
4621
|
+
nextTokenId,
|
|
4622
|
+
{
|
|
4623
|
+
royaltyBPS,
|
|
4624
|
+
royaltyRecipient,
|
|
4625
|
+
royaltyMintSchedule: 0
|
|
4626
|
+
}
|
|
4627
|
+
]
|
|
4628
|
+
});
|
|
4617
4629
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4630
|
+
return null;
|
|
4631
|
+
}
|
|
4632
|
+
function makeAdminMintCall({
|
|
4633
|
+
ownerAddress,
|
|
4634
|
+
mintQuantity,
|
|
4635
|
+
nextTokenId
|
|
4636
|
+
}) {
|
|
4637
|
+
if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
|
|
4638
|
+
return null;
|
|
4622
4639
|
}
|
|
4623
|
-
return
|
|
4640
|
+
return encodeFunctionData2({
|
|
4641
|
+
abi: zoraCreator1155ImplABI5,
|
|
4642
|
+
functionName: "adminMint",
|
|
4643
|
+
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
|
|
4644
|
+
});
|
|
4624
4645
|
}
|
|
4625
|
-
function
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4646
|
+
async function constructCreate1155TokenCalls(props) {
|
|
4647
|
+
const {
|
|
4648
|
+
chainId,
|
|
4649
|
+
nextTokenId,
|
|
4650
|
+
mintToCreatorCount,
|
|
4651
|
+
ownerAddress,
|
|
4652
|
+
contractVersion
|
|
4653
|
+
} = props;
|
|
4654
|
+
const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
|
|
4655
|
+
props,
|
|
4656
|
+
ownerAddress,
|
|
4657
|
+
props.contractName
|
|
4658
|
+
);
|
|
4659
|
+
const verifyTokenIdExpected = encodeFunctionData2({
|
|
4660
|
+
abi: zoraCreator1155ImplABI5,
|
|
4661
|
+
functionName: "assumeLastTokenIdMatches",
|
|
4662
|
+
args: [nextTokenId - 1n]
|
|
4663
|
+
});
|
|
4664
|
+
const setupNewToken = buildSetupNewToken({
|
|
4665
|
+
tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
|
|
4666
|
+
maxSupply: new1155TokenPropsWithDefaults.maxSupply,
|
|
4667
|
+
createReferral: new1155TokenPropsWithDefaults.createReferral,
|
|
4668
|
+
contractVersion
|
|
4669
|
+
});
|
|
4670
|
+
const royaltyConfig = setupRoyaltyConfig({
|
|
4671
|
+
royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
|
|
4672
|
+
royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
4673
|
+
nextTokenId
|
|
4674
|
+
});
|
|
4675
|
+
const { minter, setupActions: mintersSetup } = setupMinters({
|
|
4676
|
+
tokenId: nextTokenId,
|
|
4677
|
+
chainId,
|
|
4678
|
+
fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
4679
|
+
salesConfig: new1155TokenPropsWithDefaults.salesConfig
|
|
4680
|
+
});
|
|
4681
|
+
const adminMintCall = makeAdminMintCall({
|
|
4682
|
+
ownerAddress,
|
|
4683
|
+
mintQuantity: mintToCreatorCount,
|
|
4684
|
+
nextTokenId
|
|
4635
4685
|
});
|
|
4686
|
+
const setupActions = [
|
|
4687
|
+
verifyTokenIdExpected,
|
|
4688
|
+
setupNewToken,
|
|
4689
|
+
...mintersSetup,
|
|
4690
|
+
royaltyConfig,
|
|
4691
|
+
adminMintCall
|
|
4692
|
+
].filter((item) => item !== null);
|
|
4693
|
+
return {
|
|
4694
|
+
setupActions,
|
|
4695
|
+
minter,
|
|
4696
|
+
newToken: new1155TokenPropsWithDefaults
|
|
4697
|
+
};
|
|
4636
4698
|
}
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
4649
|
-
bitsPerChar: 5
|
|
4650
|
-
});
|
|
4651
|
-
var base32pad = rfc4648({
|
|
4652
|
-
prefix: "c",
|
|
4653
|
-
name: "base32pad",
|
|
4654
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
4655
|
-
bitsPerChar: 5
|
|
4656
|
-
});
|
|
4657
|
-
var base32padupper = rfc4648({
|
|
4658
|
-
prefix: "C",
|
|
4659
|
-
name: "base32padupper",
|
|
4660
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
4661
|
-
bitsPerChar: 5
|
|
4662
|
-
});
|
|
4663
|
-
var base32hex = rfc4648({
|
|
4664
|
-
prefix: "v",
|
|
4665
|
-
name: "base32hex",
|
|
4666
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
4667
|
-
bitsPerChar: 5
|
|
4668
|
-
});
|
|
4669
|
-
var base32hexupper = rfc4648({
|
|
4670
|
-
prefix: "V",
|
|
4671
|
-
name: "base32hexupper",
|
|
4672
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
4673
|
-
bitsPerChar: 5
|
|
4674
|
-
});
|
|
4675
|
-
var base32hexpad = rfc4648({
|
|
4676
|
-
prefix: "t",
|
|
4677
|
-
name: "base32hexpad",
|
|
4678
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
4679
|
-
bitsPerChar: 5
|
|
4680
|
-
});
|
|
4681
|
-
var base32hexpadupper = rfc4648({
|
|
4682
|
-
prefix: "T",
|
|
4683
|
-
name: "base32hexpadupper",
|
|
4684
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
4685
|
-
bitsPerChar: 5
|
|
4686
|
-
});
|
|
4687
|
-
var base32z = rfc4648({
|
|
4688
|
-
prefix: "h",
|
|
4689
|
-
name: "base32z",
|
|
4690
|
-
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
4691
|
-
bitsPerChar: 5
|
|
4692
|
-
});
|
|
4693
|
-
|
|
4694
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
4695
|
-
var base58btc = baseX({
|
|
4696
|
-
name: "base58btc",
|
|
4697
|
-
prefix: "z",
|
|
4698
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
4699
|
-
});
|
|
4700
|
-
var base58flickr = baseX({
|
|
4701
|
-
name: "base58flickr",
|
|
4702
|
-
prefix: "Z",
|
|
4703
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
4704
|
-
});
|
|
4705
|
-
|
|
4706
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
4707
|
-
var encode_1 = encode2;
|
|
4708
|
-
var MSB = 128;
|
|
4709
|
-
var REST = 127;
|
|
4710
|
-
var MSBALL = ~REST;
|
|
4711
|
-
var INT = Math.pow(2, 31);
|
|
4712
|
-
function encode2(num, out, offset) {
|
|
4713
|
-
out = out || [];
|
|
4714
|
-
offset = offset || 0;
|
|
4715
|
-
var oldOffset = offset;
|
|
4716
|
-
while (num >= INT) {
|
|
4717
|
-
out[offset++] = num & 255 | MSB;
|
|
4718
|
-
num /= 128;
|
|
4719
|
-
}
|
|
4720
|
-
while (num & MSBALL) {
|
|
4721
|
-
out[offset++] = num & 255 | MSB;
|
|
4722
|
-
num >>>= 7;
|
|
4699
|
+
var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
4700
|
+
if (!contractStandard || !contractVersion) {
|
|
4701
|
+
return false;
|
|
4702
|
+
}
|
|
4703
|
+
const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
|
|
4704
|
+
if (!semVerContractVersion)
|
|
4705
|
+
return false;
|
|
4706
|
+
if (contractStandard === "ERC1155") {
|
|
4707
|
+
return semver2.gte(semVerContractVersion, "1.3.5");
|
|
4708
|
+
} else {
|
|
4709
|
+
return semver2.gte(semVerContractVersion, "14.0.0");
|
|
4723
4710
|
}
|
|
4724
|
-
out[offset] = num | 0;
|
|
4725
|
-
encode2.bytes = offset - oldOffset + 1;
|
|
4726
|
-
return out;
|
|
4727
|
-
}
|
|
4728
|
-
var decode2 = read;
|
|
4729
|
-
var MSB$1 = 128;
|
|
4730
|
-
var REST$1 = 127;
|
|
4731
|
-
function read(buf, offset) {
|
|
4732
|
-
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
4733
|
-
do {
|
|
4734
|
-
if (counter >= l) {
|
|
4735
|
-
read.bytes = 0;
|
|
4736
|
-
throw new RangeError("Could not decode varint");
|
|
4737
|
-
}
|
|
4738
|
-
b = buf[counter++];
|
|
4739
|
-
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
4740
|
-
shift += 7;
|
|
4741
|
-
} while (b >= MSB$1);
|
|
4742
|
-
read.bytes = counter - offset;
|
|
4743
|
-
return res;
|
|
4744
|
-
}
|
|
4745
|
-
var N1 = Math.pow(2, 7);
|
|
4746
|
-
var N2 = Math.pow(2, 14);
|
|
4747
|
-
var N3 = Math.pow(2, 21);
|
|
4748
|
-
var N4 = Math.pow(2, 28);
|
|
4749
|
-
var N5 = Math.pow(2, 35);
|
|
4750
|
-
var N6 = Math.pow(2, 42);
|
|
4751
|
-
var N7 = Math.pow(2, 49);
|
|
4752
|
-
var N8 = Math.pow(2, 56);
|
|
4753
|
-
var N9 = Math.pow(2, 63);
|
|
4754
|
-
var length = function(value) {
|
|
4755
|
-
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
|
|
4756
|
-
};
|
|
4757
|
-
var varint = {
|
|
4758
|
-
encode: encode_1,
|
|
4759
|
-
decode: decode2,
|
|
4760
|
-
encodingLength: length
|
|
4761
4711
|
};
|
|
4762
|
-
var _brrp_varint = varint;
|
|
4763
|
-
var varint_default = _brrp_varint;
|
|
4764
|
-
|
|
4765
|
-
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
|
|
4766
|
-
function decode3(data, offset = 0) {
|
|
4767
|
-
const code = varint_default.decode(data, offset);
|
|
4768
|
-
return [code, varint_default.decode.bytes];
|
|
4769
|
-
}
|
|
4770
|
-
function encodeTo(int, target, offset = 0) {
|
|
4771
|
-
varint_default.encode(int, target, offset);
|
|
4772
|
-
return target;
|
|
4773
|
-
}
|
|
4774
|
-
function encodingLength(int) {
|
|
4775
|
-
return varint_default.encodingLength(int);
|
|
4776
|
-
}
|
|
4777
4712
|
|
|
4778
|
-
//
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4713
|
+
// src/create/mint-from-create.ts
|
|
4714
|
+
import { parseEther as parseEther3, zeroAddress as zeroAddress6 } from "viem";
|
|
4715
|
+
async function toSalesStrategyFromSubgraph({
|
|
4716
|
+
minter,
|
|
4717
|
+
salesConfig,
|
|
4718
|
+
getContractMintFee
|
|
4719
|
+
}) {
|
|
4720
|
+
if (salesConfig.type === "timed") {
|
|
4721
|
+
return {
|
|
4722
|
+
saleType: "timed",
|
|
4723
|
+
address: minter,
|
|
4724
|
+
// for now we hardcode this
|
|
4725
|
+
mintFeePerQuantity: parseEther3("0.000111"),
|
|
4726
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
4727
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
4728
|
+
// the following are not needed for now but we wanna satisfy concrete
|
|
4729
|
+
erc20Z: zeroAddress6,
|
|
4730
|
+
mintFee: 0n,
|
|
4731
|
+
pool: zeroAddress6,
|
|
4732
|
+
secondaryActivated: false
|
|
4733
|
+
};
|
|
4796
4734
|
}
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4735
|
+
if (salesConfig.type === "erc20Mint") {
|
|
4736
|
+
return {
|
|
4737
|
+
saleType: "erc20",
|
|
4738
|
+
address: minter,
|
|
4739
|
+
mintFeePerQuantity: 0n,
|
|
4740
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
4741
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
4742
|
+
currency: salesConfig.currency,
|
|
4743
|
+
pricePerToken: salesConfig.pricePerToken,
|
|
4744
|
+
maxTokensPerAddress: salesConfig.maxTokensPerAddress
|
|
4745
|
+
};
|
|
4746
|
+
}
|
|
4747
|
+
const contractMintFee = await getContractMintFee();
|
|
4748
|
+
if (salesConfig.type === "fixedPrice") {
|
|
4749
|
+
return {
|
|
4750
|
+
saleType: "fixedPrice",
|
|
4751
|
+
address: minter,
|
|
4752
|
+
maxTokensPerAddress: salesConfig.maxTokensPerAddress,
|
|
4753
|
+
mintFeePerQuantity: contractMintFee,
|
|
4754
|
+
pricePerToken: salesConfig.pricePerToken,
|
|
4755
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
4756
|
+
saleEnd: salesConfig.saleEnd.toString()
|
|
4757
|
+
};
|
|
4805
4758
|
}
|
|
4759
|
+
return {
|
|
4760
|
+
saleType: "allowlist",
|
|
4761
|
+
address: minter,
|
|
4762
|
+
saleStart: salesConfig.saleStart.toString(),
|
|
4763
|
+
saleEnd: salesConfig.saleEnd.toString(),
|
|
4764
|
+
merkleRoot: salesConfig.presaleMerkleRoot,
|
|
4765
|
+
mintFeePerQuantity: contractMintFee
|
|
4766
|
+
};
|
|
4806
4767
|
}
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4768
|
+
function makeOnchainPrepareMintFromCreate({
|
|
4769
|
+
contractAddress,
|
|
4770
|
+
tokenId,
|
|
4771
|
+
result,
|
|
4772
|
+
minter,
|
|
4773
|
+
getContractMintFee,
|
|
4774
|
+
contractVersion
|
|
4775
|
+
}) {
|
|
4776
|
+
return async (params) => {
|
|
4777
|
+
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
4778
|
+
minter,
|
|
4779
|
+
getContractMintFee,
|
|
4780
|
+
salesConfig: result
|
|
4781
|
+
});
|
|
4782
|
+
return {
|
|
4783
|
+
parameters: makePrepareMint1155TokenParams({
|
|
4784
|
+
salesConfigAndTokenInfo: {
|
|
4785
|
+
salesConfig: subgraphSalesConfig,
|
|
4786
|
+
contractVersion
|
|
4787
|
+
},
|
|
4788
|
+
...params,
|
|
4789
|
+
tokenContract: contractAddress,
|
|
4790
|
+
tokenId
|
|
4791
|
+
}),
|
|
4792
|
+
costs: parseMintCosts({
|
|
4793
|
+
allowListEntry: params.allowListEntry,
|
|
4794
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
4795
|
+
salesConfig: subgraphSalesConfig
|
|
4796
|
+
}),
|
|
4797
|
+
erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
|
|
4798
|
+
};
|
|
4799
|
+
};
|
|
4800
|
+
}
|
|
4801
|
+
|
|
4802
|
+
// src/create/1155-create-helper.ts
|
|
4803
|
+
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
4804
|
+
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
4805
|
+
for (const data of receipt.logs) {
|
|
4806
|
+
try {
|
|
4807
|
+
const decodedLog = decodeEventLog2({
|
|
4808
|
+
abi: zoraCreator1155ImplABI6,
|
|
4809
|
+
eventName: "SetupNewToken",
|
|
4810
|
+
...data
|
|
4811
|
+
});
|
|
4812
|
+
if (decodedLog && decodedLog.eventName === "SetupNewToken") {
|
|
4813
|
+
return decodedLog.args.tokenId;
|
|
4814
|
+
}
|
|
4815
|
+
} catch (err) {
|
|
4816
|
+
}
|
|
4820
4817
|
}
|
|
4818
|
+
throw new Error(
|
|
4819
|
+
"No event found in receipt that could be used to get tokenId"
|
|
4820
|
+
);
|
|
4821
4821
|
};
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4822
|
+
var getContractAddressFromReceipt = (receipt) => {
|
|
4823
|
+
for (const data of receipt.logs) {
|
|
4824
|
+
try {
|
|
4825
|
+
const decodedLog = decodeEventLog2({
|
|
4826
|
+
abi: zoraCreator1155FactoryImplABI2,
|
|
4827
|
+
eventName: "SetupNewContract",
|
|
4828
|
+
...data
|
|
4829
|
+
});
|
|
4830
|
+
if (decodedLog && decodedLog.eventName === "SetupNewContract") {
|
|
4831
|
+
return decodedLog.args.newContract;
|
|
4832
|
+
}
|
|
4833
|
+
} catch (err) {
|
|
4834
|
+
}
|
|
4831
4835
|
}
|
|
4836
|
+
throw new Error(
|
|
4837
|
+
"No event found in receipt that could be used to get contract address"
|
|
4838
|
+
);
|
|
4839
|
+
};
|
|
4840
|
+
function makeCreateContractAndTokenCall({
|
|
4841
|
+
account,
|
|
4842
|
+
contract,
|
|
4843
|
+
royaltyBPS,
|
|
4844
|
+
fundsRecipient,
|
|
4845
|
+
tokenSetupActions,
|
|
4846
|
+
chainId
|
|
4847
|
+
}) {
|
|
4848
|
+
const accountAddress = typeof account === "string" ? account : account.address;
|
|
4849
|
+
return makeContractParameters({
|
|
4850
|
+
abi: zoraCreator1155FactoryImplABI2,
|
|
4851
|
+
functionName: "createContractDeterministic",
|
|
4852
|
+
account,
|
|
4853
|
+
address: zoraCreator1155FactoryImplAddress2[chainId],
|
|
4854
|
+
args: [
|
|
4855
|
+
contract.uri,
|
|
4856
|
+
contract.name,
|
|
4857
|
+
{
|
|
4858
|
+
// deprecated
|
|
4859
|
+
royaltyMintSchedule: 0,
|
|
4860
|
+
royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
4861
|
+
royaltyRecipient: fundsRecipient || accountAddress
|
|
4862
|
+
},
|
|
4863
|
+
contract.defaultAdmin || accountAddress,
|
|
4864
|
+
tokenSetupActions
|
|
4865
|
+
]
|
|
4866
|
+
});
|
|
4832
4867
|
}
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4868
|
+
function makeCreateTokenCall({
|
|
4869
|
+
contractAddress,
|
|
4870
|
+
account,
|
|
4871
|
+
tokenSetupActions
|
|
4872
|
+
}) {
|
|
4873
|
+
return makeContractParameters({
|
|
4874
|
+
abi: zoraCreator1155ImplABI6,
|
|
4875
|
+
functionName: "multicall",
|
|
4876
|
+
account,
|
|
4877
|
+
address: contractAddress,
|
|
4878
|
+
args: [tokenSetupActions]
|
|
4879
|
+
});
|
|
4842
4880
|
}
|
|
4843
|
-
var
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
__publicField(this, "version");
|
|
4853
|
-
__publicField(this, "multihash");
|
|
4854
|
-
__publicField(this, "bytes");
|
|
4855
|
-
__publicField(this, "/");
|
|
4856
|
-
__publicField(this, _a, "CID");
|
|
4857
|
-
this.code = code;
|
|
4858
|
-
this.version = version;
|
|
4859
|
-
this.multihash = multihash;
|
|
4860
|
-
this.bytes = bytes;
|
|
4861
|
-
this["/"] = bytes;
|
|
4862
|
-
}
|
|
4863
|
-
/**
|
|
4864
|
-
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
4865
|
-
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
4866
|
-
*
|
|
4867
|
-
* @deprecated
|
|
4868
|
-
*/
|
|
4869
|
-
get asCID() {
|
|
4870
|
-
return this;
|
|
4881
|
+
var Create1155Client = class {
|
|
4882
|
+
constructor({
|
|
4883
|
+
chainId,
|
|
4884
|
+
publicClient,
|
|
4885
|
+
contractGetter
|
|
4886
|
+
}) {
|
|
4887
|
+
this.chainId = chainId;
|
|
4888
|
+
this.publicClient = publicClient;
|
|
4889
|
+
this.contractGetter = contractGetter;
|
|
4871
4890
|
}
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4891
|
+
async createNew1155(props) {
|
|
4892
|
+
return createNew1155ContractAndToken({
|
|
4893
|
+
...props,
|
|
4894
|
+
publicClient: this.publicClient,
|
|
4895
|
+
chainId: this.chainId
|
|
4896
|
+
});
|
|
4875
4897
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4898
|
+
async createNew1155OnExistingContract({
|
|
4899
|
+
contractAddress: contract,
|
|
4900
|
+
account,
|
|
4901
|
+
token,
|
|
4902
|
+
getAdditionalSetupActions
|
|
4903
|
+
}) {
|
|
4904
|
+
return createNew1155Token({
|
|
4905
|
+
contractAddress: contract,
|
|
4906
|
+
account,
|
|
4907
|
+
token,
|
|
4908
|
+
getAdditionalSetupActions,
|
|
4909
|
+
publicClient: this.publicClient,
|
|
4910
|
+
chainId: this.chainId,
|
|
4911
|
+
contractGetter: this.contractGetter
|
|
4912
|
+
});
|
|
4879
4913
|
}
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4914
|
+
};
|
|
4915
|
+
async function createNew1155ContractAndToken({
|
|
4916
|
+
contract,
|
|
4917
|
+
account,
|
|
4918
|
+
chainId,
|
|
4919
|
+
token,
|
|
4920
|
+
publicClient,
|
|
4921
|
+
getAdditionalSetupActions
|
|
4922
|
+
}) {
|
|
4923
|
+
const nextTokenId = 1n;
|
|
4924
|
+
const contractVersion = new1155ContractVersion(chainId);
|
|
4925
|
+
const {
|
|
4926
|
+
minter,
|
|
4927
|
+
newToken,
|
|
4928
|
+
setupActions: tokenSetupActions
|
|
4929
|
+
} = await prepareSetupActions({
|
|
4930
|
+
chainId,
|
|
4931
|
+
account,
|
|
4932
|
+
contractVersion,
|
|
4933
|
+
nextTokenId,
|
|
4934
|
+
token,
|
|
4935
|
+
getAdditionalSetupActions,
|
|
4936
|
+
contractName: contract.name
|
|
4937
|
+
});
|
|
4938
|
+
const request = makeCreateContractAndTokenCall({
|
|
4939
|
+
contract,
|
|
4940
|
+
account,
|
|
4941
|
+
chainId,
|
|
4942
|
+
tokenSetupActions,
|
|
4943
|
+
fundsRecipient: token.payoutRecipient,
|
|
4944
|
+
royaltyBPS: token.royaltyBPS
|
|
4945
|
+
});
|
|
4946
|
+
const contractAddress = await getDeterministicContractAddress({
|
|
4947
|
+
account,
|
|
4948
|
+
publicClient,
|
|
4949
|
+
setupActions: tokenSetupActions,
|
|
4950
|
+
chainId,
|
|
4951
|
+
contract
|
|
4952
|
+
});
|
|
4953
|
+
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
4954
|
+
contractAddress,
|
|
4955
|
+
contractVersion,
|
|
4956
|
+
minter,
|
|
4957
|
+
result: newToken.salesConfig,
|
|
4958
|
+
tokenId: nextTokenId,
|
|
4959
|
+
// to get the contract wide mint fee, we get what it would be for a new contract
|
|
4960
|
+
getContractMintFee: async () => getNewContractMintFee({
|
|
4961
|
+
publicClient,
|
|
4962
|
+
chainId
|
|
4963
|
+
})
|
|
4964
|
+
});
|
|
4965
|
+
return {
|
|
4966
|
+
parameters: request,
|
|
4967
|
+
tokenSetupActions,
|
|
4968
|
+
newTokenId: nextTokenId,
|
|
4969
|
+
newToken,
|
|
4970
|
+
contractAddress,
|
|
4971
|
+
contractVersion,
|
|
4972
|
+
minter,
|
|
4973
|
+
prepareMint
|
|
4974
|
+
};
|
|
4975
|
+
}
|
|
4976
|
+
async function createNew1155Token({
|
|
4977
|
+
contractAddress,
|
|
4978
|
+
account,
|
|
4979
|
+
getAdditionalSetupActions,
|
|
4980
|
+
token,
|
|
4981
|
+
chainId,
|
|
4982
|
+
contractGetter
|
|
4983
|
+
}) {
|
|
4984
|
+
const { nextTokenId, contractVersion, mintFee, name } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
|
|
4985
|
+
const {
|
|
4986
|
+
minter,
|
|
4987
|
+
newToken,
|
|
4988
|
+
setupActions: tokenSetupActions
|
|
4989
|
+
} = await prepareSetupActions({
|
|
4990
|
+
chainId,
|
|
4991
|
+
account,
|
|
4992
|
+
contractVersion,
|
|
4993
|
+
nextTokenId,
|
|
4994
|
+
token,
|
|
4995
|
+
getAdditionalSetupActions,
|
|
4996
|
+
contractName: name
|
|
4997
|
+
});
|
|
4998
|
+
const request = makeCreateTokenCall({
|
|
4999
|
+
contractAddress,
|
|
5000
|
+
account,
|
|
5001
|
+
tokenSetupActions
|
|
5002
|
+
});
|
|
5003
|
+
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
5004
|
+
contractAddress,
|
|
5005
|
+
contractVersion,
|
|
5006
|
+
minter,
|
|
5007
|
+
result: newToken.salesConfig,
|
|
5008
|
+
tokenId: nextTokenId,
|
|
5009
|
+
getContractMintFee: async () => mintFee
|
|
5010
|
+
});
|
|
5011
|
+
return {
|
|
5012
|
+
parameters: request,
|
|
5013
|
+
tokenSetupActions,
|
|
5014
|
+
newTokenId: nextTokenId,
|
|
5015
|
+
newToken,
|
|
5016
|
+
contractVersion,
|
|
5017
|
+
minter,
|
|
5018
|
+
prepareMint
|
|
5019
|
+
};
|
|
5020
|
+
}
|
|
5021
|
+
async function prepareSetupActions({
|
|
5022
|
+
chainId,
|
|
5023
|
+
account,
|
|
5024
|
+
contractVersion,
|
|
5025
|
+
nextTokenId,
|
|
5026
|
+
token,
|
|
5027
|
+
contractName,
|
|
5028
|
+
getAdditionalSetupActions
|
|
5029
|
+
}) {
|
|
5030
|
+
const {
|
|
5031
|
+
minter,
|
|
5032
|
+
newToken,
|
|
5033
|
+
setupActions: tokenSetupActions
|
|
5034
|
+
} = await constructCreate1155TokenCalls({
|
|
5035
|
+
chainId,
|
|
5036
|
+
ownerAddress: account,
|
|
5037
|
+
contractVersion,
|
|
5038
|
+
nextTokenId,
|
|
5039
|
+
...token,
|
|
5040
|
+
contractName
|
|
5041
|
+
});
|
|
5042
|
+
const setupActions = getAdditionalSetupActions ? [
|
|
5043
|
+
...getAdditionalSetupActions({
|
|
5044
|
+
tokenId: nextTokenId
|
|
5045
|
+
}),
|
|
5046
|
+
...tokenSetupActions
|
|
5047
|
+
] : tokenSetupActions;
|
|
5048
|
+
return { minter, newToken, setupActions };
|
|
5049
|
+
}
|
|
5050
|
+
|
|
5051
|
+
// src/sparks/mints-queries.ts
|
|
5052
|
+
var getMintsAccountBalanceWithPriceQuery = (account) => {
|
|
5053
|
+
const query = `
|
|
5054
|
+
query GetMintAccountBalances($account: String!) {
|
|
5055
|
+
mintAccountBalances(where: { account: $account }) {
|
|
5056
|
+
balance
|
|
5057
|
+
mintToken {
|
|
5058
|
+
id
|
|
5059
|
+
pricePerToken
|
|
4892
5060
|
}
|
|
4893
|
-
return _CID.createV0(multihash);
|
|
4894
|
-
}
|
|
4895
|
-
default: {
|
|
4896
|
-
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
4897
|
-
}
|
|
4898
|
-
}
|
|
4899
|
-
}
|
|
4900
|
-
toV1() {
|
|
4901
|
-
switch (this.version) {
|
|
4902
|
-
case 0: {
|
|
4903
|
-
const { code, digest } = this.multihash;
|
|
4904
|
-
const multihash = create(code, digest);
|
|
4905
|
-
return _CID.createV1(this.code, multihash);
|
|
4906
|
-
}
|
|
4907
|
-
case 1: {
|
|
4908
|
-
return this;
|
|
4909
|
-
}
|
|
4910
|
-
default: {
|
|
4911
|
-
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
4912
5061
|
}
|
|
4913
5062
|
}
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
return { "/": format(this) };
|
|
4927
|
-
}
|
|
4928
|
-
link() {
|
|
4929
|
-
return this;
|
|
4930
|
-
}
|
|
4931
|
-
// Legacy
|
|
4932
|
-
[(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
|
|
4933
|
-
return `CID(${this.toString()})`;
|
|
4934
|
-
}
|
|
4935
|
-
/**
|
|
4936
|
-
* Takes any input `value` and returns a `CID` instance if it was
|
|
4937
|
-
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
4938
|
-
* it will return value back. If `value` is not instance of this CID
|
|
4939
|
-
* class, but is compatible CID it will return new instance of this
|
|
4940
|
-
* `CID` class. Otherwise returns null.
|
|
4941
|
-
*
|
|
4942
|
-
* This allows two different incompatible versions of CID library to
|
|
4943
|
-
* co-exist and interop as long as binary interface is compatible.
|
|
4944
|
-
*/
|
|
4945
|
-
static asCID(input) {
|
|
4946
|
-
if (input == null) {
|
|
4947
|
-
return null;
|
|
4948
|
-
}
|
|
4949
|
-
const value = input;
|
|
4950
|
-
if (value instanceof _CID) {
|
|
4951
|
-
return value;
|
|
4952
|
-
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
4953
|
-
const { version, code, multihash, bytes } = value;
|
|
4954
|
-
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
4955
|
-
} else if (value[cidSymbol] === true) {
|
|
4956
|
-
const { version, multihash, code } = value;
|
|
4957
|
-
const digest = decode4(multihash);
|
|
4958
|
-
return _CID.create(version, code, digest);
|
|
4959
|
-
} else {
|
|
4960
|
-
return null;
|
|
4961
|
-
}
|
|
4962
|
-
}
|
|
4963
|
-
/**
|
|
4964
|
-
* @param version - Version of the CID
|
|
4965
|
-
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
4966
|
-
* @param digest - (Multi)hash of the of the content.
|
|
4967
|
-
*/
|
|
4968
|
-
static create(version, code, digest) {
|
|
4969
|
-
if (typeof code !== "number") {
|
|
4970
|
-
throw new Error("String codecs are no longer supported");
|
|
4971
|
-
}
|
|
4972
|
-
if (!(digest.bytes instanceof Uint8Array)) {
|
|
4973
|
-
throw new Error("Invalid digest");
|
|
4974
|
-
}
|
|
4975
|
-
switch (version) {
|
|
4976
|
-
case 0: {
|
|
4977
|
-
if (code !== DAG_PB_CODE) {
|
|
4978
|
-
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
4979
|
-
} else {
|
|
4980
|
-
return new _CID(version, code, digest, digest.bytes);
|
|
4981
|
-
}
|
|
4982
|
-
}
|
|
4983
|
-
case 1: {
|
|
4984
|
-
const bytes = encodeCID(version, code, digest.bytes);
|
|
4985
|
-
return new _CID(version, code, digest, bytes);
|
|
4986
|
-
}
|
|
4987
|
-
default: {
|
|
4988
|
-
throw new Error("Invalid version");
|
|
4989
|
-
}
|
|
4990
|
-
}
|
|
4991
|
-
}
|
|
4992
|
-
/**
|
|
4993
|
-
* Simplified version of `create` for CIDv0.
|
|
4994
|
-
*/
|
|
4995
|
-
static createV0(digest) {
|
|
4996
|
-
return _CID.create(0, DAG_PB_CODE, digest);
|
|
4997
|
-
}
|
|
4998
|
-
/**
|
|
4999
|
-
* Simplified version of `create` for CIDv1.
|
|
5000
|
-
*
|
|
5001
|
-
* @param code - Content encoding format code.
|
|
5002
|
-
* @param digest - Multihash of the content.
|
|
5003
|
-
*/
|
|
5004
|
-
static createV1(code, digest) {
|
|
5005
|
-
return _CID.create(1, code, digest);
|
|
5006
|
-
}
|
|
5007
|
-
/**
|
|
5008
|
-
* Decoded a CID from its binary representation. The byte array must contain
|
|
5009
|
-
* only the CID with no additional bytes.
|
|
5010
|
-
*
|
|
5011
|
-
* An error will be thrown if the bytes provided do not contain a valid
|
|
5012
|
-
* binary representation of a CID.
|
|
5013
|
-
*/
|
|
5014
|
-
static decode(bytes) {
|
|
5015
|
-
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
5016
|
-
if (remainder.length !== 0) {
|
|
5017
|
-
throw new Error("Incorrect length");
|
|
5018
|
-
}
|
|
5019
|
-
return cid;
|
|
5020
|
-
}
|
|
5021
|
-
/**
|
|
5022
|
-
* Decoded a CID from its binary representation at the beginning of a byte
|
|
5023
|
-
* array.
|
|
5024
|
-
*
|
|
5025
|
-
* Returns an array with the first element containing the CID and the second
|
|
5026
|
-
* element containing the remainder of the original byte array. The remainder
|
|
5027
|
-
* will be a zero-length byte array if the provided bytes only contained a
|
|
5028
|
-
* binary CID representation.
|
|
5029
|
-
*/
|
|
5030
|
-
static decodeFirst(bytes) {
|
|
5031
|
-
const specs = _CID.inspectBytes(bytes);
|
|
5032
|
-
const prefixSize = specs.size - specs.multihashSize;
|
|
5033
|
-
const multihashBytes = coerce2(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
5034
|
-
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
5035
|
-
throw new Error("Incorrect length");
|
|
5036
|
-
}
|
|
5037
|
-
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
5038
|
-
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
5039
|
-
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
5040
|
-
return [cid, bytes.subarray(specs.size)];
|
|
5041
|
-
}
|
|
5042
|
-
/**
|
|
5043
|
-
* Inspect the initial bytes of a CID to determine its properties.
|
|
5044
|
-
*
|
|
5045
|
-
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
5046
|
-
* bytes but for larger multicodec code values and larger multihash digest
|
|
5047
|
-
* lengths these varints can be quite large. It is recommended that at least
|
|
5048
|
-
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
5049
|
-
* inspection.
|
|
5050
|
-
*/
|
|
5051
|
-
static inspectBytes(initialBytes) {
|
|
5052
|
-
let offset = 0;
|
|
5053
|
-
const next = () => {
|
|
5054
|
-
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
5055
|
-
offset += length2;
|
|
5056
|
-
return i;
|
|
5063
|
+
`;
|
|
5064
|
+
return {
|
|
5065
|
+
query,
|
|
5066
|
+
variables: { account }
|
|
5067
|
+
};
|
|
5068
|
+
};
|
|
5069
|
+
var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
|
|
5070
|
+
const parsed = mintAccountBalances.map((r) => {
|
|
5071
|
+
return {
|
|
5072
|
+
tokenId: BigInt(r.mintToken.id),
|
|
5073
|
+
quantity: BigInt(r.balance),
|
|
5074
|
+
pricePerToken: BigInt(r.mintToken.pricePerToken)
|
|
5057
5075
|
};
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
if (
|
|
5061
|
-
|
|
5062
|
-
offset = 0;
|
|
5063
|
-
} else {
|
|
5064
|
-
codec = next();
|
|
5065
|
-
}
|
|
5066
|
-
if (version !== 0 && version !== 1) {
|
|
5067
|
-
throw new RangeError(`Invalid CID version ${version}`);
|
|
5076
|
+
});
|
|
5077
|
+
const sorted = parsed.sort((a, b) => {
|
|
5078
|
+
if (a.pricePerToken < b.pricePerToken) {
|
|
5079
|
+
return -1;
|
|
5068
5080
|
}
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
* decoder is not provided will use a default from the configuration. It will
|
|
5079
|
-
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
5080
|
-
* a default decoder).
|
|
5081
|
-
*/
|
|
5082
|
-
static parse(source, base3) {
|
|
5083
|
-
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
5084
|
-
const cid = _CID.decode(bytes);
|
|
5085
|
-
if (cid.version === 0 && source[0] !== "Q") {
|
|
5086
|
-
throw Error("Version 0 CID string must not include multibase prefix");
|
|
5081
|
+
return 1;
|
|
5082
|
+
});
|
|
5083
|
+
let remainingQuantity = quantityToCollect;
|
|
5084
|
+
const tokenIds = [];
|
|
5085
|
+
const quantities = [];
|
|
5086
|
+
while (remainingQuantity > 0) {
|
|
5087
|
+
const next = sorted.shift();
|
|
5088
|
+
if (!next) {
|
|
5089
|
+
throw new Error("Not enough MINTs to collect with");
|
|
5087
5090
|
}
|
|
5088
|
-
|
|
5089
|
-
|
|
5091
|
+
const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
|
|
5092
|
+
tokenIds.push(next.tokenId);
|
|
5093
|
+
quantities.push(quantityToUse);
|
|
5094
|
+
remainingQuantity -= quantityToUse;
|
|
5090
5095
|
}
|
|
5096
|
+
return {
|
|
5097
|
+
tokenIds,
|
|
5098
|
+
quantities
|
|
5099
|
+
};
|
|
5100
|
+
};
|
|
5101
|
+
var sumBalances = (mintAccountBalances) => {
|
|
5102
|
+
return mintAccountBalances.reduce((acc, curr) => {
|
|
5103
|
+
return acc + BigInt(curr.balance);
|
|
5104
|
+
}, BigInt(0));
|
|
5091
5105
|
};
|
|
5092
|
-
function parseCIDtoBytes(source, base3) {
|
|
5093
|
-
switch (source[0]) {
|
|
5094
|
-
case "Q": {
|
|
5095
|
-
const decoder = base3 ?? base58btc;
|
|
5096
|
-
return [
|
|
5097
|
-
base58btc.prefix,
|
|
5098
|
-
decoder.decode(`${base58btc.prefix}${source}`)
|
|
5099
|
-
];
|
|
5100
|
-
}
|
|
5101
|
-
case base58btc.prefix: {
|
|
5102
|
-
const decoder = base3 ?? base58btc;
|
|
5103
|
-
return [base58btc.prefix, decoder.decode(source)];
|
|
5104
|
-
}
|
|
5105
|
-
case base32.prefix: {
|
|
5106
|
-
const decoder = base3 ?? base32;
|
|
5107
|
-
return [base32.prefix, decoder.decode(source)];
|
|
5108
|
-
}
|
|
5109
|
-
default: {
|
|
5110
|
-
if (base3 == null) {
|
|
5111
|
-
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
5112
|
-
}
|
|
5113
|
-
return [source[0], base3.decode(source)];
|
|
5114
|
-
}
|
|
5115
|
-
}
|
|
5116
|
-
}
|
|
5117
|
-
function toStringV0(bytes, cache2, base3) {
|
|
5118
|
-
const { prefix } = base3;
|
|
5119
|
-
if (prefix !== base58btc.prefix) {
|
|
5120
|
-
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
5121
|
-
}
|
|
5122
|
-
const cid = cache2.get(prefix);
|
|
5123
|
-
if (cid == null) {
|
|
5124
|
-
const cid2 = base3.encode(bytes).slice(1);
|
|
5125
|
-
cache2.set(prefix, cid2);
|
|
5126
|
-
return cid2;
|
|
5127
|
-
} else {
|
|
5128
|
-
return cid;
|
|
5129
|
-
}
|
|
5130
|
-
}
|
|
5131
|
-
function toStringV1(bytes, cache2, base3) {
|
|
5132
|
-
const { prefix } = base3;
|
|
5133
|
-
const cid = cache2.get(prefix);
|
|
5134
|
-
if (cid == null) {
|
|
5135
|
-
const cid2 = base3.encode(bytes);
|
|
5136
|
-
cache2.set(prefix, cid2);
|
|
5137
|
-
return cid2;
|
|
5138
|
-
} else {
|
|
5139
|
-
return cid;
|
|
5140
|
-
}
|
|
5141
|
-
}
|
|
5142
|
-
var DAG_PB_CODE = 112;
|
|
5143
|
-
var SHA_256_CODE = 18;
|
|
5144
|
-
function encodeCID(version, code, multihash) {
|
|
5145
|
-
const codeOffset = encodingLength(version);
|
|
5146
|
-
const hashOffset = codeOffset + encodingLength(code);
|
|
5147
|
-
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
5148
|
-
encodeTo(version, bytes, 0);
|
|
5149
|
-
encodeTo(code, bytes, codeOffset);
|
|
5150
|
-
bytes.set(multihash, hashOffset);
|
|
5151
|
-
return bytes;
|
|
5152
|
-
}
|
|
5153
|
-
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
5154
5106
|
|
|
5155
|
-
// src/
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5107
|
+
// src/sparks/sparks-contracts.ts
|
|
5108
|
+
import {
|
|
5109
|
+
mintsSafeTransferBatchTypedDataDefinition,
|
|
5110
|
+
mintsSafeTransferTypedDataDefinition,
|
|
5111
|
+
zoraMints1155Config,
|
|
5112
|
+
zoraMintsManagerImplABI,
|
|
5113
|
+
zoraMintsManagerImplAddress,
|
|
5114
|
+
zoraMintsManagerImplConfig,
|
|
5115
|
+
zoraSparksManagerImplABI,
|
|
5116
|
+
zoraSparksManagerImplAddress
|
|
5117
|
+
} from "@zoralabs/protocol-deployments";
|
|
5118
|
+
import {
|
|
5119
|
+
decodeErrorResult,
|
|
5120
|
+
encodeFunctionData as encodeFunctionData3,
|
|
5121
|
+
zeroAddress as zeroAddress7
|
|
5122
|
+
} from "viem";
|
|
5123
|
+
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
5124
|
+
var mintWithEthParams = ({
|
|
5125
|
+
tokenId,
|
|
5126
|
+
quantity,
|
|
5127
|
+
recipient,
|
|
5128
|
+
chainId,
|
|
5129
|
+
pricePerMint,
|
|
5130
|
+
account
|
|
5131
|
+
}) => makeContractParameters({
|
|
5132
|
+
abi: zoraSparksManagerImplABI,
|
|
5133
|
+
address: zoraSparksManagerImplAddress[chainId],
|
|
5134
|
+
functionName: "mintWithEth",
|
|
5135
|
+
args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
|
|
5136
|
+
value: pricePerMint * quantity,
|
|
5137
|
+
account
|
|
5138
|
+
});
|
|
5139
|
+
var getPaidMintValue = (quantities, pricePerMint) => {
|
|
5140
|
+
if (!pricePerMint || pricePerMint === 0n)
|
|
5141
|
+
return;
|
|
5142
|
+
return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
|
|
5143
|
+
};
|
|
5144
|
+
var mintsBalanceOfAccountParams = ({
|
|
5145
|
+
account,
|
|
5146
|
+
chainId
|
|
5147
|
+
}) => ({
|
|
5148
|
+
abi: zoraMints1155Config.abi,
|
|
5149
|
+
address: zoraMints1155Config.address[chainId],
|
|
5150
|
+
functionName: "balanceOfAccount",
|
|
5151
|
+
args: [account]
|
|
5152
|
+
});
|
|
5153
|
+
var encodeCollectOnManager = ({
|
|
5154
|
+
zoraCreator1155Contract,
|
|
5155
|
+
minter,
|
|
5156
|
+
zoraCreator1155TokenId,
|
|
5157
|
+
mintArguments
|
|
5158
|
+
}) => encodeFunctionData3({
|
|
5159
|
+
abi: zoraMintsManagerImplConfig.abi,
|
|
5160
|
+
functionName: "collect",
|
|
5161
|
+
args: [
|
|
5162
|
+
zoraCreator1155Contract,
|
|
5163
|
+
minter,
|
|
5164
|
+
zoraCreator1155TokenId,
|
|
5165
|
+
mintArguments
|
|
5166
|
+
]
|
|
5167
|
+
});
|
|
5168
|
+
function collectWithMintsParams({
|
|
5169
|
+
tokenIds,
|
|
5170
|
+
quantities,
|
|
5171
|
+
chainId,
|
|
5172
|
+
paidMintPricePerToken,
|
|
5173
|
+
account,
|
|
5174
|
+
mintArguments,
|
|
5175
|
+
minter,
|
|
5176
|
+
zoraCreator1155Contract,
|
|
5177
|
+
zoraCreator1155TokenId
|
|
5178
|
+
}) {
|
|
5179
|
+
const call = encodeCollectOnManager({
|
|
5180
|
+
tokenIds,
|
|
5181
|
+
quantities,
|
|
5182
|
+
zoraCreator1155Contract,
|
|
5183
|
+
zoraCreator1155TokenId,
|
|
5184
|
+
minter,
|
|
5185
|
+
mintArguments
|
|
5186
|
+
});
|
|
5187
|
+
return makeContractParameters({
|
|
5188
|
+
abi: zoraMints1155Config.abi,
|
|
5189
|
+
address: zoraMints1155Config.address[chainId],
|
|
5190
|
+
functionName: "transferBatchToManagerAndCall",
|
|
5191
|
+
args: [tokenIds, quantities, call],
|
|
5192
|
+
// if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
|
|
5193
|
+
// for the paid mint cost.
|
|
5194
|
+
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
5195
|
+
account
|
|
5196
|
+
});
|
|
5188
5197
|
}
|
|
5189
|
-
function
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
}
|
|
5195
|
-
return false;
|
|
5196
|
-
}
|
|
5198
|
+
function getMintsEthPrice({
|
|
5199
|
+
publicClient
|
|
5200
|
+
}) {
|
|
5201
|
+
const chainId = publicClient.chain?.id;
|
|
5202
|
+
if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
|
|
5203
|
+
throw new Error(`Chain id ${chainId} not supported`);
|
|
5197
5204
|
}
|
|
5198
|
-
return
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
}
|
|
5203
|
-
function isNormalizeableIPFSUrl(url) {
|
|
5204
|
-
return url ? isIPFSUrl(url) || isCID(url) : false;
|
|
5205
|
-
}
|
|
5206
|
-
|
|
5207
|
-
// src/ipfs/gateway.ts
|
|
5208
|
-
var IPFS_GATEWAY = "https://magic.decentralized-content.com";
|
|
5209
|
-
var ARWEAVE_GATEWAY = "https://arweave.net";
|
|
5210
|
-
function arweaveGatewayUrl(normalizedArweaveUrl) {
|
|
5211
|
-
if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
|
|
5212
|
-
return null;
|
|
5213
|
-
return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
|
|
5205
|
+
return publicClient.readContract({
|
|
5206
|
+
abi: zoraMintsManagerImplABI,
|
|
5207
|
+
address: zoraMintsManagerImplAddress[chainId],
|
|
5208
|
+
functionName: "getEthPrice"
|
|
5209
|
+
});
|
|
5214
5210
|
}
|
|
5215
|
-
function
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5211
|
+
function makePermitTransferBatchAndTypeData({
|
|
5212
|
+
tokenIds,
|
|
5213
|
+
quantities,
|
|
5214
|
+
chainId,
|
|
5215
|
+
mintsOwner,
|
|
5216
|
+
to,
|
|
5217
|
+
nonce,
|
|
5218
|
+
deadline,
|
|
5219
|
+
safeTransferData
|
|
5220
|
+
}) {
|
|
5221
|
+
const permit = {
|
|
5222
|
+
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
5223
|
+
to,
|
|
5224
|
+
tokenIds,
|
|
5225
|
+
quantities,
|
|
5226
|
+
deadline,
|
|
5227
|
+
nonce,
|
|
5228
|
+
safeTransferData
|
|
5229
|
+
};
|
|
5230
|
+
const typedData = {
|
|
5231
|
+
...mintsSafeTransferBatchTypedDataDefinition({
|
|
5232
|
+
chainId,
|
|
5233
|
+
message: permit
|
|
5234
|
+
}),
|
|
5235
|
+
account: mintsOwner
|
|
5236
|
+
};
|
|
5237
|
+
return {
|
|
5238
|
+
permit,
|
|
5239
|
+
typedData
|
|
5240
|
+
};
|
|
5223
5241
|
}
|
|
5224
|
-
function
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5242
|
+
function makePermitTransferTypeData({
|
|
5243
|
+
tokenId,
|
|
5244
|
+
quantity,
|
|
5245
|
+
chainId,
|
|
5246
|
+
mintsOwner,
|
|
5247
|
+
to,
|
|
5248
|
+
nonce,
|
|
5249
|
+
deadline,
|
|
5250
|
+
safeTransferData
|
|
5251
|
+
}) {
|
|
5252
|
+
const permit = {
|
|
5253
|
+
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
5254
|
+
to,
|
|
5255
|
+
tokenId,
|
|
5256
|
+
quantity,
|
|
5257
|
+
deadline,
|
|
5258
|
+
nonce,
|
|
5259
|
+
safeTransferData
|
|
5260
|
+
};
|
|
5261
|
+
const typedData = {
|
|
5262
|
+
...mintsSafeTransferTypedDataDefinition({
|
|
5263
|
+
chainId,
|
|
5264
|
+
message: permit
|
|
5265
|
+
}),
|
|
5266
|
+
account: mintsOwner
|
|
5267
|
+
};
|
|
5268
|
+
return {
|
|
5269
|
+
permit,
|
|
5270
|
+
typedData
|
|
5271
|
+
};
|
|
5239
5272
|
}
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
var
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
var GLB_EXT = ".glb";
|
|
5289
|
-
var JSON_MIME_TYPE = "application/json";
|
|
5290
|
-
var ZIP = "application/zip";
|
|
5291
|
-
var mimeToMediaType = {
|
|
5292
|
-
[HTML]: "HTML" /* HTML */,
|
|
5293
|
-
[JPG]: "IMAGE" /* IMAGE */,
|
|
5294
|
-
[JPEG]: "IMAGE" /* IMAGE */,
|
|
5295
|
-
[PNG]: "IMAGE" /* IMAGE */,
|
|
5296
|
-
[WEBP]: "IMAGE" /* IMAGE */,
|
|
5297
|
-
[SVG]: "IMAGE" /* IMAGE */,
|
|
5298
|
-
[TIFF]: "TIFF" /* TIFF */,
|
|
5299
|
-
[GIF]: "IMAGE" /* IMAGE */,
|
|
5300
|
-
[MP4]: "VIDEO" /* VIDEO */,
|
|
5301
|
-
[WEBM]: "VIDEO" /* VIDEO */,
|
|
5302
|
-
[QUICKTIME]: "VIDEO" /* VIDEO */,
|
|
5303
|
-
[M4V]: "VIDEO" /* VIDEO */,
|
|
5304
|
-
[MPEG]: "AUDIO" /* AUDIO */,
|
|
5305
|
-
[MP3]: "AUDIO" /* AUDIO */,
|
|
5306
|
-
[M4A]: "AUDIO" /* AUDIO */,
|
|
5307
|
-
[VND_WAV]: "AUDIO" /* AUDIO */,
|
|
5308
|
-
[VND_WAVE]: "AUDIO" /* AUDIO */,
|
|
5309
|
-
[WAV]: "AUDIO" /* AUDIO */,
|
|
5310
|
-
[WAVE]: "AUDIO" /* AUDIO */,
|
|
5311
|
-
[X_WAV]: "AUDIO" /* AUDIO */,
|
|
5312
|
-
[AIFF]: "AUDIO" /* AUDIO */,
|
|
5313
|
-
[TEXT_PLAIN]: "TEXT" /* TEXT */,
|
|
5314
|
-
[TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
|
|
5315
|
-
[MARKDOWN]: "TEXT" /* TEXT */,
|
|
5316
|
-
[MARKDOWN_UTF8]: "TEXT" /* TEXT */,
|
|
5317
|
-
[CSV]: "CSV" /* CSV */,
|
|
5318
|
-
[NUMBERS]: "NUMBERS" /* NUMBERS */,
|
|
5319
|
-
[EXCEL]: "EXCEL" /* EXCEL */,
|
|
5320
|
-
[PDF]: "PDF" /* PDF */,
|
|
5321
|
-
[ZIP]: "ZIP" /* ZIP */,
|
|
5322
|
-
[GLTF]: "MODEL" /* MODEL */,
|
|
5323
|
-
[GLTF_EXT]: "MODEL" /* MODEL */,
|
|
5324
|
-
[GLB]: "MODEL" /* MODEL */,
|
|
5325
|
-
// GLTF returns 'application/json' as the mimetype,
|
|
5326
|
-
// and as the only JSON-encoded media we currently support,
|
|
5327
|
-
// we assume that if the mimetype is JSON, it's a GLTF
|
|
5328
|
-
[JSON_MIME_TYPE]: "MODEL" /* MODEL */,
|
|
5329
|
-
[GLB_EXT]: "MODEL" /* MODEL */
|
|
5273
|
+
var encodePremintOnManager = ({
|
|
5274
|
+
contractCreationConfig,
|
|
5275
|
+
premintConfig,
|
|
5276
|
+
premintSignature,
|
|
5277
|
+
mintArguments,
|
|
5278
|
+
signerContract = zeroAddress7
|
|
5279
|
+
}) => encodeFunctionData3({
|
|
5280
|
+
abi: zoraMintsManagerImplConfig.abi,
|
|
5281
|
+
functionName: "collectPremintV2",
|
|
5282
|
+
args: [
|
|
5283
|
+
contractCreationConfig,
|
|
5284
|
+
premintConfig,
|
|
5285
|
+
premintSignature,
|
|
5286
|
+
mintArguments,
|
|
5287
|
+
signerContract
|
|
5288
|
+
]
|
|
5289
|
+
});
|
|
5290
|
+
var makePermitToCollectPremintOrNonPremint = ({
|
|
5291
|
+
mintsOwner,
|
|
5292
|
+
chainId,
|
|
5293
|
+
deadline,
|
|
5294
|
+
tokenIds,
|
|
5295
|
+
// this quantity of MINTs will be used to collect premint
|
|
5296
|
+
// and will be burned. This same quantity is the quantity of
|
|
5297
|
+
// premint to collect.
|
|
5298
|
+
quantities,
|
|
5299
|
+
nonce,
|
|
5300
|
+
premint,
|
|
5301
|
+
collect
|
|
5302
|
+
}) => {
|
|
5303
|
+
let safeTransferData;
|
|
5304
|
+
if (premint) {
|
|
5305
|
+
safeTransferData = encodePremintOnManager(premint);
|
|
5306
|
+
} else if (collect) {
|
|
5307
|
+
safeTransferData = encodeCollectOnManager(collect);
|
|
5308
|
+
} else {
|
|
5309
|
+
throw new Error("Invalid operation");
|
|
5310
|
+
}
|
|
5311
|
+
return makePermitTransferBatchAndTypeData({
|
|
5312
|
+
tokenIds,
|
|
5313
|
+
quantities,
|
|
5314
|
+
chainId,
|
|
5315
|
+
mintsOwner,
|
|
5316
|
+
nonce,
|
|
5317
|
+
deadline,
|
|
5318
|
+
safeTransferData,
|
|
5319
|
+
to: zoraMintsManagerImplConfig.address[chainId]
|
|
5320
|
+
});
|
|
5330
5321
|
};
|
|
5331
|
-
function
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5322
|
+
function collectPremintV2WithMintsParams({
|
|
5323
|
+
tokenIds,
|
|
5324
|
+
quantities,
|
|
5325
|
+
paidMintPricePerToken,
|
|
5326
|
+
account,
|
|
5327
|
+
chainId,
|
|
5328
|
+
...rest
|
|
5329
|
+
}) {
|
|
5330
|
+
const call = encodePremintOnManager({
|
|
5331
|
+
...rest
|
|
5332
|
+
});
|
|
5333
|
+
return makeContractParameters({
|
|
5334
|
+
abi: zoraMints1155Config.abi,
|
|
5335
|
+
address: zoraMints1155Config.address[chainId],
|
|
5336
|
+
functionName: "transferBatchToManagerAndCall",
|
|
5337
|
+
args: [tokenIds, quantities, call],
|
|
5338
|
+
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
5339
|
+
account
|
|
5340
|
+
});
|
|
5335
5341
|
}
|
|
5336
|
-
|
|
5337
|
-
if (
|
|
5338
|
-
|
|
5339
|
-
const
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
+
function decodeCallFailedError(error) {
|
|
5343
|
+
if (error.data?.errorName !== "CallFailed")
|
|
5344
|
+
throw new Error("Not a CallFailed error");
|
|
5345
|
+
const internalErrorData = error.data?.args?.[0];
|
|
5346
|
+
return decodeErrorResult({
|
|
5347
|
+
abi: zoraMintsManagerImplABI,
|
|
5348
|
+
data: internalErrorData
|
|
5349
|
+
});
|
|
5342
5350
|
}
|
|
5343
5351
|
|
|
5344
|
-
// src/
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
mime: TEXT_PLAIN,
|
|
5349
|
-
uri: textFileUrl
|
|
5350
|
-
} : null;
|
|
5351
|
-
const image = thumbnailUrl;
|
|
5352
|
-
const animation_url = textFileUrl;
|
|
5353
|
-
return {
|
|
5354
|
-
name,
|
|
5355
|
-
image,
|
|
5356
|
-
animation_url,
|
|
5357
|
-
content,
|
|
5358
|
-
attributes
|
|
5359
|
-
};
|
|
5360
|
-
};
|
|
5361
|
-
var makeMediaTokenMetadata = async ({
|
|
5362
|
-
name,
|
|
5363
|
-
description,
|
|
5364
|
-
attributes = [],
|
|
5365
|
-
mediaUrl,
|
|
5366
|
-
thumbnailUrl
|
|
5367
|
-
}) => {
|
|
5368
|
-
const contentUrl = mediaUrl;
|
|
5369
|
-
const fetchableContentUrl = getFetchableUrl(contentUrl);
|
|
5370
|
-
if (!fetchableContentUrl)
|
|
5371
|
-
throw new Error(`Content url (${contentUrl}) is not fetchable`);
|
|
5372
|
-
const mimeType = await getMimeType(fetchableContentUrl);
|
|
5373
|
-
const mediaType = mimeTypeToMedia(mimeType);
|
|
5374
|
-
let image = void 0;
|
|
5375
|
-
let animation_url = null;
|
|
5376
|
-
if (isImage(mimeType)) {
|
|
5377
|
-
image = contentUrl;
|
|
5378
|
-
} else {
|
|
5379
|
-
image = thumbnailUrl;
|
|
5380
|
-
animation_url = mediaUrl;
|
|
5381
|
-
}
|
|
5382
|
-
if (!image)
|
|
5383
|
-
image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
|
|
5384
|
-
const content = contentUrl ? {
|
|
5385
|
-
mime: mimeType || "application/octet-stream",
|
|
5386
|
-
uri: contentUrl
|
|
5387
|
-
} : null;
|
|
5352
|
+
// src/create/subgraph-queries.ts
|
|
5353
|
+
function buildContractInfoQuery({
|
|
5354
|
+
contractAddress
|
|
5355
|
+
}) {
|
|
5388
5356
|
return {
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5357
|
+
query: `
|
|
5358
|
+
query ($contractAddress: Bytes!) {
|
|
5359
|
+
zoraCreateContract(id: $contractAddress) {
|
|
5360
|
+
contractVersion
|
|
5361
|
+
name
|
|
5362
|
+
mintFeePerQuantity
|
|
5363
|
+
tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
|
|
5364
|
+
tokenId
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
}
|
|
5368
|
+
`,
|
|
5369
|
+
variables: {
|
|
5370
|
+
contractAddress: contractAddress.toLowerCase()
|
|
5371
|
+
},
|
|
5372
|
+
parseResponseData: (responseData) => responseData.zoraCreateContract
|
|
5395
5373
|
};
|
|
5396
|
-
};
|
|
5397
|
-
async function fetchTokenMetadata(tokenMetadataURI) {
|
|
5398
|
-
const fetchableUrl = getFetchableUrl(tokenMetadataURI);
|
|
5399
|
-
if (!fetchableUrl) {
|
|
5400
|
-
throw new Error(`Invalid token metadata URI: ${tokenMetadataURI}`);
|
|
5401
|
-
}
|
|
5402
|
-
const json = await (await fetch(fetchableUrl)).json();
|
|
5403
|
-
if (!json) {
|
|
5404
|
-
throw new Error(`Failed to fetch metadata from ${fetchableUrl}`);
|
|
5405
|
-
}
|
|
5406
|
-
return json;
|
|
5407
5374
|
}
|
|
5408
5375
|
|
|
5409
|
-
// src/create/
|
|
5410
|
-
var
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
// This is the end of uint64, plenty of time
|
|
5415
|
-
saleEnd: SALE_END_FOREVER
|
|
5416
|
-
};
|
|
5417
|
-
var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
|
|
5418
|
-
maxTokensPerAddress: 0n
|
|
5419
|
-
};
|
|
5420
|
-
var erc20SaleSettingsWithDefaults = (params) => ({
|
|
5421
|
-
...DEFAULT_SALE_START_AND_END,
|
|
5422
|
-
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
5423
|
-
...params
|
|
5424
|
-
});
|
|
5425
|
-
var allowListWithDefaults = (allowlist) => {
|
|
5426
|
-
return {
|
|
5427
|
-
...DEFAULT_SALE_START_AND_END,
|
|
5428
|
-
...allowlist
|
|
5429
|
-
};
|
|
5430
|
-
};
|
|
5431
|
-
var fixedPriceSettingsWithDefaults = (params) => ({
|
|
5432
|
-
...DEFAULT_SALE_START_AND_END,
|
|
5433
|
-
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
5434
|
-
type: "fixedPrice",
|
|
5435
|
-
...params
|
|
5436
|
-
});
|
|
5437
|
-
var parseNameIntoSymbol = (name) => {
|
|
5438
|
-
if (name === "") {
|
|
5439
|
-
throw new Error("Name must be provided to generate a symbol");
|
|
5440
|
-
}
|
|
5441
|
-
const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
|
|
5442
|
-
if (result === "$") {
|
|
5443
|
-
throw new Error("Not enough valid characters to generate a symbol");
|
|
5444
|
-
}
|
|
5445
|
-
return result;
|
|
5446
|
-
};
|
|
5447
|
-
async function fetchTokenNameFromMetadata(tokenMetadataURI) {
|
|
5448
|
-
const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
|
|
5449
|
-
if (!tokenMetadata.name) {
|
|
5450
|
-
throw new Error("No name found in token metadata");
|
|
5451
|
-
}
|
|
5452
|
-
return tokenMetadata.name;
|
|
5453
|
-
}
|
|
5454
|
-
var timedSaleSettingsWithDefaults = async (params, tokenMetadataURI) => {
|
|
5455
|
-
const erc20Name = params.erc20Name || await fetchTokenNameFromMetadata(tokenMetadataURI);
|
|
5456
|
-
const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
|
|
5457
|
-
return {
|
|
5458
|
-
type: "timed",
|
|
5459
|
-
...DEFAULT_SALE_START_AND_END,
|
|
5460
|
-
erc20Name,
|
|
5461
|
-
erc20Symbol: symbol
|
|
5462
|
-
};
|
|
5463
|
-
};
|
|
5464
|
-
var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
5465
|
-
var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
5466
|
-
var isFixedPrice = (salesConfig) => {
|
|
5467
|
-
return salesConfig.pricePerToken > 0n;
|
|
5468
|
-
};
|
|
5469
|
-
var getSalesConfigWithDefaults = async (salesConfig, tokenMetadataURI) => {
|
|
5470
|
-
if (!salesConfig)
|
|
5471
|
-
return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
|
|
5472
|
-
if (isAllowList(salesConfig)) {
|
|
5473
|
-
return allowListWithDefaults(salesConfig);
|
|
5376
|
+
// src/create/contract-getter.ts
|
|
5377
|
+
var SubgraphContractGetter = class {
|
|
5378
|
+
constructor(chainId, subgraphQuerier) {
|
|
5379
|
+
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
5380
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
5474
5381
|
}
|
|
5475
|
-
|
|
5476
|
-
|
|
5382
|
+
async querySubgraphWithRetries({
|
|
5383
|
+
query,
|
|
5384
|
+
variables,
|
|
5385
|
+
parseResponseData
|
|
5386
|
+
}) {
|
|
5387
|
+
const responseData = await this.subgraphQuerier.query({
|
|
5388
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
5389
|
+
query,
|
|
5390
|
+
variables
|
|
5391
|
+
});
|
|
5392
|
+
return parseResponseData(responseData);
|
|
5477
5393
|
}
|
|
5478
|
-
|
|
5479
|
-
|
|
5394
|
+
async getContractInfo({
|
|
5395
|
+
contractAddress,
|
|
5396
|
+
retries: retries2 = 1
|
|
5397
|
+
}) {
|
|
5398
|
+
const tryFn = async () => {
|
|
5399
|
+
const responseData2 = await this.querySubgraphWithRetries(
|
|
5400
|
+
buildContractInfoQuery({ contractAddress })
|
|
5401
|
+
);
|
|
5402
|
+
if (!responseData2) {
|
|
5403
|
+
console.log("could not find contract");
|
|
5404
|
+
throw new Error("Cannot find contract");
|
|
5405
|
+
}
|
|
5406
|
+
return responseData2;
|
|
5407
|
+
};
|
|
5408
|
+
const responseData = await retriesGeneric({
|
|
5409
|
+
tryFn,
|
|
5410
|
+
maxTries: retries2,
|
|
5411
|
+
linearBackoffMS: 1e3
|
|
5412
|
+
});
|
|
5413
|
+
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
5414
|
+
return {
|
|
5415
|
+
name: responseData.name,
|
|
5416
|
+
contractVersion: responseData.contractVersion,
|
|
5417
|
+
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
5418
|
+
nextTokenId
|
|
5419
|
+
};
|
|
5480
5420
|
}
|
|
5481
|
-
return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
|
|
5482
5421
|
};
|
|
5483
5422
|
|
|
5484
|
-
// src/
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2,
|
|
5491
|
-
zoraCreatorMerkleMinterStrategyABI,
|
|
5492
|
-
zoraCreatorMerkleMinterStrategyAddress,
|
|
5493
|
-
zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI2,
|
|
5494
|
-
zoraTimedSaleStrategyAddress
|
|
5495
|
-
} from "@zoralabs/protocol-deployments";
|
|
5496
|
-
import { encodeFunctionData } from "viem";
|
|
5497
|
-
var PERMISSION_BITS = {
|
|
5498
|
-
MINTER: 2n ** 2n
|
|
5499
|
-
};
|
|
5500
|
-
function setupErc20Minter({
|
|
5501
|
-
pricePerToken,
|
|
5502
|
-
chainId,
|
|
5503
|
-
tokenId: nextTokenId,
|
|
5504
|
-
currency,
|
|
5505
|
-
saleStart,
|
|
5506
|
-
saleEnd,
|
|
5507
|
-
maxTokensPerAddress: mintLimit,
|
|
5508
|
-
fundsRecipient
|
|
5509
|
-
}) {
|
|
5510
|
-
const erc20MinterAddress = erc20MinterAddresses[chainId];
|
|
5511
|
-
if (!erc20MinterAddress)
|
|
5512
|
-
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
5513
|
-
const erc20MinterApproval = encodeFunctionData({
|
|
5514
|
-
abi: zoraCreator1155ImplABI4,
|
|
5515
|
-
functionName: "addPermission",
|
|
5516
|
-
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
5517
|
-
});
|
|
5518
|
-
const saleData = encodeFunctionData({
|
|
5519
|
-
abi: erc20MinterABI2,
|
|
5520
|
-
functionName: "setSale",
|
|
5521
|
-
args: [
|
|
5522
|
-
BigInt(nextTokenId),
|
|
5523
|
-
{
|
|
5524
|
-
saleStart: saleStart || BigInt(0),
|
|
5525
|
-
saleEnd: saleEnd || BigInt(0),
|
|
5526
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
5527
|
-
pricePerToken,
|
|
5528
|
-
fundsRecipient,
|
|
5529
|
-
currency
|
|
5530
|
-
}
|
|
5531
|
-
]
|
|
5423
|
+
// src/sdk.ts
|
|
5424
|
+
function createCreatorClient(clientConfig) {
|
|
5425
|
+
const premintClient = new PremintClient({
|
|
5426
|
+
chainId: clientConfig.chainId,
|
|
5427
|
+
publicClient: clientConfig.publicClient,
|
|
5428
|
+
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
5532
5429
|
});
|
|
5533
|
-
const
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5430
|
+
const create1155CreatorClient = new Create1155Client({
|
|
5431
|
+
chainId: clientConfig.chainId,
|
|
5432
|
+
publicClient: clientConfig.publicClient,
|
|
5433
|
+
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
5537
5434
|
});
|
|
5538
5435
|
return {
|
|
5539
|
-
|
|
5540
|
-
|
|
5436
|
+
createPremint: (p) => premintClient.createPremint(p),
|
|
5437
|
+
updatePremint: (p) => premintClient.updatePremint(p),
|
|
5438
|
+
deletePremint: (p) => premintClient.deletePremint(p),
|
|
5439
|
+
create1155: (p) => create1155CreatorClient.createNew1155(p),
|
|
5440
|
+
create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
|
|
5541
5441
|
};
|
|
5542
5442
|
}
|
|
5543
|
-
function
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
fundsRecipient
|
|
5551
|
-
}) {
|
|
5552
|
-
const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
|
|
5553
|
-
const fixedPriceApproval = encodeFunctionData({
|
|
5554
|
-
abi: zoraCreator1155ImplABI4,
|
|
5555
|
-
functionName: "addPermission",
|
|
5556
|
-
args: [
|
|
5557
|
-
BigInt(nextTokenId),
|
|
5558
|
-
fixedPriceStrategyAddress,
|
|
5559
|
-
PERMISSION_BITS.MINTER
|
|
5560
|
-
]
|
|
5561
|
-
});
|
|
5562
|
-
const saleData = encodeFunctionData({
|
|
5563
|
-
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
5564
|
-
functionName: "setSale",
|
|
5565
|
-
args: [
|
|
5566
|
-
BigInt(nextTokenId),
|
|
5567
|
-
{
|
|
5568
|
-
pricePerToken: price,
|
|
5569
|
-
saleStart: saleStart || BigInt(0),
|
|
5570
|
-
saleEnd: saleEnd || BigInt(0),
|
|
5571
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
5572
|
-
fundsRecipient
|
|
5573
|
-
}
|
|
5574
|
-
]
|
|
5575
|
-
});
|
|
5576
|
-
const callSale = encodeFunctionData({
|
|
5577
|
-
abi: zoraCreator1155ImplABI4,
|
|
5578
|
-
functionName: "callSale",
|
|
5579
|
-
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
5443
|
+
function createCollectorClient(params) {
|
|
5444
|
+
const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
|
|
5445
|
+
const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
|
|
5446
|
+
const mintClient = new MintClient({
|
|
5447
|
+
publicClient: params.publicClient,
|
|
5448
|
+
premintGetter: premintGetterToUse,
|
|
5449
|
+
mintGetter: mintGetterToUse
|
|
5580
5450
|
});
|
|
5581
5451
|
return {
|
|
5582
|
-
|
|
5583
|
-
|
|
5452
|
+
getPremint: (p) => premintGetterToUse.get({
|
|
5453
|
+
collectionAddress: p.address,
|
|
5454
|
+
uid: p.uid
|
|
5455
|
+
}),
|
|
5456
|
+
getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
|
|
5457
|
+
getToken: (p) => mintClient.get(p),
|
|
5458
|
+
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
5459
|
+
mint: (p) => mintClient.mint(p),
|
|
5460
|
+
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
5584
5461
|
};
|
|
5585
5462
|
}
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
erc20Symbol: erc20zSymbol,
|
|
5591
|
-
saleStart,
|
|
5592
|
-
saleEnd
|
|
5593
|
-
}) {
|
|
5594
|
-
const minterAddress = zoraTimedSaleStrategyAddress[chainId];
|
|
5595
|
-
const fixedPriceApproval = encodeFunctionData({
|
|
5596
|
-
abi: zoraCreator1155ImplABI4,
|
|
5597
|
-
functionName: "addPermission",
|
|
5598
|
-
args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
|
|
5599
|
-
});
|
|
5600
|
-
const saleData = encodeFunctionData({
|
|
5601
|
-
abi: zoraTimedSaleStrategyABI2,
|
|
5602
|
-
functionName: "setSale",
|
|
5603
|
-
args: [
|
|
5604
|
-
BigInt(tokenId),
|
|
5605
|
-
{
|
|
5606
|
-
saleStart,
|
|
5607
|
-
saleEnd,
|
|
5608
|
-
name: erc20zName,
|
|
5609
|
-
symbol: erc20zSymbol
|
|
5610
|
-
}
|
|
5611
|
-
]
|
|
5612
|
-
});
|
|
5613
|
-
const callSale = encodeFunctionData({
|
|
5614
|
-
abi: zoraCreator1155ImplABI4,
|
|
5615
|
-
functionName: "callSale",
|
|
5616
|
-
args: [BigInt(tokenId), minterAddress, saleData]
|
|
5617
|
-
});
|
|
5618
|
-
return {
|
|
5619
|
-
minter: minterAddress,
|
|
5620
|
-
setupActions: [fixedPriceApproval, callSale]
|
|
5621
|
-
};
|
|
5622
|
-
}
|
|
5623
|
-
function setupAllowListMinter({
|
|
5624
|
-
chainId,
|
|
5625
|
-
tokenId: nextTokenId,
|
|
5626
|
-
allowlist,
|
|
5627
|
-
fundsRecipient
|
|
5628
|
-
}) {
|
|
5629
|
-
const merkleSaleStrategyAddress = zoraCreatorMerkleMinterStrategyAddress[chainId];
|
|
5630
|
-
const merkleApproval = encodeFunctionData({
|
|
5631
|
-
abi: zoraCreator1155ImplABI4,
|
|
5632
|
-
functionName: "addPermission",
|
|
5633
|
-
args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
|
|
5634
|
-
});
|
|
5635
|
-
const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
|
|
5636
|
-
const saleData = encodeFunctionData({
|
|
5637
|
-
abi: zoraCreatorMerkleMinterStrategyABI,
|
|
5638
|
-
functionName: "setSale",
|
|
5639
|
-
args: [
|
|
5640
|
-
BigInt(nextTokenId),
|
|
5641
|
-
{
|
|
5642
|
-
presaleStart: allowlist.saleStart,
|
|
5643
|
-
presaleEnd: allowlist.saleEnd,
|
|
5644
|
-
merkleRoot,
|
|
5645
|
-
fundsRecipient
|
|
5646
|
-
}
|
|
5647
|
-
]
|
|
5648
|
-
});
|
|
5649
|
-
const callSaleMerkle = encodeFunctionData({
|
|
5650
|
-
abi: zoraCreator1155ImplABI4,
|
|
5651
|
-
functionName: "callSale",
|
|
5652
|
-
args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
|
|
5653
|
-
});
|
|
5654
|
-
return {
|
|
5655
|
-
minter: merkleSaleStrategyAddress,
|
|
5656
|
-
setupActions: [merkleApproval, callSaleMerkle]
|
|
5657
|
-
};
|
|
5658
|
-
}
|
|
5659
|
-
var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
5660
|
-
var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
|
|
5661
|
-
var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
|
|
5662
|
-
function setupMinters({ salesConfig, ...rest }) {
|
|
5663
|
-
if (isErc202(salesConfig)) {
|
|
5664
|
-
return setupErc20Minter({
|
|
5665
|
-
...salesConfig,
|
|
5666
|
-
...rest
|
|
5667
|
-
});
|
|
5668
|
-
}
|
|
5669
|
-
if (isAllowList2(salesConfig)) {
|
|
5670
|
-
return setupAllowListMinter({
|
|
5671
|
-
allowlist: salesConfig,
|
|
5672
|
-
...rest
|
|
5673
|
-
});
|
|
5674
|
-
}
|
|
5675
|
-
if (isFixedPrice2(salesConfig))
|
|
5676
|
-
return setupFixedPriceMinter({
|
|
5677
|
-
...salesConfig,
|
|
5678
|
-
...rest
|
|
5679
|
-
});
|
|
5680
|
-
return setupTimedSaleMinter({
|
|
5681
|
-
...salesConfig,
|
|
5682
|
-
...rest
|
|
5683
|
-
});
|
|
5463
|
+
|
|
5464
|
+
// src/ipfs/arweave.ts
|
|
5465
|
+
function isArweaveURL(url) {
|
|
5466
|
+
return url && typeof url === "string" ? url.startsWith("ar://") : false;
|
|
5684
5467
|
}
|
|
5685
5468
|
|
|
5686
|
-
// src/
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
5694
|
-
royaltyBPS: props.royaltyBPS || 1e3,
|
|
5695
|
-
tokenMetadataURI: props.tokenMetadataURI,
|
|
5696
|
-
salesConfig: await getSalesConfigWithDefaults(
|
|
5697
|
-
props.salesConfig,
|
|
5698
|
-
props.tokenMetadataURI
|
|
5699
|
-
)
|
|
5700
|
-
};
|
|
5701
|
-
}
|
|
5702
|
-
function buildSetupNewToken({
|
|
5703
|
-
tokenURI,
|
|
5704
|
-
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
5705
|
-
createReferral = zeroAddress5,
|
|
5706
|
-
contractVersion
|
|
5707
|
-
}) {
|
|
5708
|
-
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
5709
|
-
return encodeFunctionData2({
|
|
5710
|
-
abi: zoraCreator1155ImplABI5,
|
|
5711
|
-
functionName: "setupNewTokenWithCreateReferral",
|
|
5712
|
-
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
5713
|
-
});
|
|
5714
|
-
}
|
|
5715
|
-
if (createReferral !== zeroAddress5) {
|
|
5716
|
-
throw new Error(
|
|
5717
|
-
"Contract does not support create referral, but one was provided"
|
|
5718
|
-
);
|
|
5469
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
|
|
5470
|
+
var empty = new Uint8Array(0);
|
|
5471
|
+
function equals(aa, bb) {
|
|
5472
|
+
if (aa === bb)
|
|
5473
|
+
return true;
|
|
5474
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
5475
|
+
return false;
|
|
5719
5476
|
}
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
});
|
|
5725
|
-
}
|
|
5726
|
-
function setupRoyaltyConfig({
|
|
5727
|
-
royaltyBPS,
|
|
5728
|
-
royaltyRecipient,
|
|
5729
|
-
nextTokenId
|
|
5730
|
-
}) {
|
|
5731
|
-
if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
|
|
5732
|
-
return encodeFunctionData2({
|
|
5733
|
-
abi: zoraCreator1155ImplABI5,
|
|
5734
|
-
functionName: "updateRoyaltiesForToken",
|
|
5735
|
-
args: [
|
|
5736
|
-
nextTokenId,
|
|
5737
|
-
{
|
|
5738
|
-
royaltyBPS,
|
|
5739
|
-
royaltyRecipient,
|
|
5740
|
-
royaltyMintSchedule: 0
|
|
5741
|
-
}
|
|
5742
|
-
]
|
|
5743
|
-
});
|
|
5477
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
5478
|
+
if (aa[ii] !== bb[ii]) {
|
|
5479
|
+
return false;
|
|
5480
|
+
}
|
|
5744
5481
|
}
|
|
5745
|
-
return
|
|
5482
|
+
return true;
|
|
5746
5483
|
}
|
|
5747
|
-
function
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
if (
|
|
5753
|
-
return
|
|
5484
|
+
function coerce3(o) {
|
|
5485
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
5486
|
+
return o;
|
|
5487
|
+
if (o instanceof ArrayBuffer)
|
|
5488
|
+
return new Uint8Array(o);
|
|
5489
|
+
if (ArrayBuffer.isView(o)) {
|
|
5490
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
5754
5491
|
}
|
|
5755
|
-
|
|
5756
|
-
abi: zoraCreator1155ImplABI5,
|
|
5757
|
-
functionName: "adminMint",
|
|
5758
|
-
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
|
|
5759
|
-
});
|
|
5760
|
-
}
|
|
5761
|
-
async function constructCreate1155TokenCalls(props) {
|
|
5762
|
-
const {
|
|
5763
|
-
chainId,
|
|
5764
|
-
nextTokenId,
|
|
5765
|
-
mintToCreatorCount,
|
|
5766
|
-
ownerAddress,
|
|
5767
|
-
contractVersion
|
|
5768
|
-
} = props;
|
|
5769
|
-
const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
|
|
5770
|
-
props,
|
|
5771
|
-
ownerAddress
|
|
5772
|
-
);
|
|
5773
|
-
const verifyTokenIdExpected = encodeFunctionData2({
|
|
5774
|
-
abi: zoraCreator1155ImplABI5,
|
|
5775
|
-
functionName: "assumeLastTokenIdMatches",
|
|
5776
|
-
args: [nextTokenId - 1n]
|
|
5777
|
-
});
|
|
5778
|
-
const setupNewToken = buildSetupNewToken({
|
|
5779
|
-
tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
|
|
5780
|
-
maxSupply: new1155TokenPropsWithDefaults.maxSupply,
|
|
5781
|
-
createReferral: new1155TokenPropsWithDefaults.createReferral,
|
|
5782
|
-
contractVersion
|
|
5783
|
-
});
|
|
5784
|
-
const royaltyConfig = setupRoyaltyConfig({
|
|
5785
|
-
royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
|
|
5786
|
-
royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
5787
|
-
nextTokenId
|
|
5788
|
-
});
|
|
5789
|
-
const { minter, setupActions: mintersSetup } = setupMinters({
|
|
5790
|
-
tokenId: nextTokenId,
|
|
5791
|
-
chainId,
|
|
5792
|
-
fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
5793
|
-
salesConfig: new1155TokenPropsWithDefaults.salesConfig
|
|
5794
|
-
});
|
|
5795
|
-
const adminMintCall = makeAdminMintCall({
|
|
5796
|
-
ownerAddress,
|
|
5797
|
-
mintQuantity: mintToCreatorCount,
|
|
5798
|
-
nextTokenId
|
|
5799
|
-
});
|
|
5800
|
-
const setupActions = [
|
|
5801
|
-
verifyTokenIdExpected,
|
|
5802
|
-
setupNewToken,
|
|
5803
|
-
...mintersSetup,
|
|
5804
|
-
royaltyConfig,
|
|
5805
|
-
adminMintCall
|
|
5806
|
-
].filter((item) => item !== null);
|
|
5807
|
-
return {
|
|
5808
|
-
setupActions,
|
|
5809
|
-
minter,
|
|
5810
|
-
newToken: new1155TokenPropsWithDefaults
|
|
5811
|
-
};
|
|
5492
|
+
throw new Error("Unknown type, must be binary type");
|
|
5812
5493
|
}
|
|
5813
|
-
var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
5814
|
-
if (!contractStandard || !contractVersion) {
|
|
5815
|
-
return false;
|
|
5816
|
-
}
|
|
5817
|
-
const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
|
|
5818
|
-
if (!semVerContractVersion)
|
|
5819
|
-
return false;
|
|
5820
|
-
if (contractStandard === "ERC1155") {
|
|
5821
|
-
return semver2.gte(semVerContractVersion, "1.3.5");
|
|
5822
|
-
} else {
|
|
5823
|
-
return semver2.gte(semVerContractVersion, "14.0.0");
|
|
5824
|
-
}
|
|
5825
|
-
};
|
|
5826
5494
|
|
|
5827
|
-
// src/
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
salesConfig,
|
|
5832
|
-
getContractMintFee
|
|
5833
|
-
}) {
|
|
5834
|
-
if (salesConfig.type === "timed") {
|
|
5835
|
-
return {
|
|
5836
|
-
saleType: "timed",
|
|
5837
|
-
address: minter,
|
|
5838
|
-
// for now we hardcode this
|
|
5839
|
-
mintFeePerQuantity: parseEther3("0.000111"),
|
|
5840
|
-
saleStart: salesConfig.saleStart.toString(),
|
|
5841
|
-
saleEnd: salesConfig.saleEnd.toString(),
|
|
5842
|
-
// the following are not needed for now but we wanna satisfy concrete
|
|
5843
|
-
erc20Z: zeroAddress6,
|
|
5844
|
-
mintFee: 0n,
|
|
5845
|
-
pool: zeroAddress6,
|
|
5846
|
-
secondaryActivated: false
|
|
5847
|
-
};
|
|
5495
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
5496
|
+
function base2(ALPHABET, name) {
|
|
5497
|
+
if (ALPHABET.length >= 255) {
|
|
5498
|
+
throw new TypeError("Alphabet too long");
|
|
5848
5499
|
}
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
address: minter,
|
|
5853
|
-
mintFeePerQuantity: 0n,
|
|
5854
|
-
saleStart: salesConfig.saleStart.toString(),
|
|
5855
|
-
saleEnd: salesConfig.saleEnd.toString(),
|
|
5856
|
-
currency: salesConfig.currency,
|
|
5857
|
-
pricePerToken: salesConfig.pricePerToken,
|
|
5858
|
-
maxTokensPerAddress: salesConfig.maxTokensPerAddress
|
|
5859
|
-
};
|
|
5500
|
+
var BASE_MAP = new Uint8Array(256);
|
|
5501
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
5502
|
+
BASE_MAP[j] = 255;
|
|
5860
5503
|
}
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5504
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
5505
|
+
var x = ALPHABET.charAt(i);
|
|
5506
|
+
var xc = x.charCodeAt(0);
|
|
5507
|
+
if (BASE_MAP[xc] !== 255) {
|
|
5508
|
+
throw new TypeError(x + " is ambiguous");
|
|
5509
|
+
}
|
|
5510
|
+
BASE_MAP[xc] = i;
|
|
5511
|
+
}
|
|
5512
|
+
var BASE = ALPHABET.length;
|
|
5513
|
+
var LEADER = ALPHABET.charAt(0);
|
|
5514
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
5515
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
5516
|
+
function encode3(source) {
|
|
5517
|
+
if (source instanceof Uint8Array)
|
|
5518
|
+
;
|
|
5519
|
+
else if (ArrayBuffer.isView(source)) {
|
|
5520
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
5521
|
+
} else if (Array.isArray(source)) {
|
|
5522
|
+
source = Uint8Array.from(source);
|
|
5523
|
+
}
|
|
5524
|
+
if (!(source instanceof Uint8Array)) {
|
|
5525
|
+
throw new TypeError("Expected Uint8Array");
|
|
5526
|
+
}
|
|
5527
|
+
if (source.length === 0) {
|
|
5528
|
+
return "";
|
|
5529
|
+
}
|
|
5530
|
+
var zeroes = 0;
|
|
5531
|
+
var length2 = 0;
|
|
5532
|
+
var pbegin = 0;
|
|
5533
|
+
var pend = source.length;
|
|
5534
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
5535
|
+
pbegin++;
|
|
5536
|
+
zeroes++;
|
|
5537
|
+
}
|
|
5538
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
5539
|
+
var b58 = new Uint8Array(size);
|
|
5540
|
+
while (pbegin !== pend) {
|
|
5541
|
+
var carry = source[pbegin];
|
|
5542
|
+
var i2 = 0;
|
|
5543
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
5544
|
+
carry += 256 * b58[it1] >>> 0;
|
|
5545
|
+
b58[it1] = carry % BASE >>> 0;
|
|
5546
|
+
carry = carry / BASE >>> 0;
|
|
5547
|
+
}
|
|
5548
|
+
if (carry !== 0) {
|
|
5549
|
+
throw new Error("Non-zero carry");
|
|
5550
|
+
}
|
|
5551
|
+
length2 = i2;
|
|
5552
|
+
pbegin++;
|
|
5553
|
+
}
|
|
5554
|
+
var it2 = size - length2;
|
|
5555
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
5556
|
+
it2++;
|
|
5557
|
+
}
|
|
5558
|
+
var str = LEADER.repeat(zeroes);
|
|
5559
|
+
for (; it2 < size; ++it2) {
|
|
5560
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
5561
|
+
}
|
|
5562
|
+
return str;
|
|
5563
|
+
}
|
|
5564
|
+
function decodeUnsafe(source) {
|
|
5565
|
+
if (typeof source !== "string") {
|
|
5566
|
+
throw new TypeError("Expected String");
|
|
5567
|
+
}
|
|
5568
|
+
if (source.length === 0) {
|
|
5569
|
+
return new Uint8Array();
|
|
5570
|
+
}
|
|
5571
|
+
var psz = 0;
|
|
5572
|
+
if (source[psz] === " ") {
|
|
5573
|
+
return;
|
|
5574
|
+
}
|
|
5575
|
+
var zeroes = 0;
|
|
5576
|
+
var length2 = 0;
|
|
5577
|
+
while (source[psz] === LEADER) {
|
|
5578
|
+
zeroes++;
|
|
5579
|
+
psz++;
|
|
5580
|
+
}
|
|
5581
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
5582
|
+
var b256 = new Uint8Array(size);
|
|
5583
|
+
while (source[psz]) {
|
|
5584
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
5585
|
+
if (carry === 255) {
|
|
5586
|
+
return;
|
|
5587
|
+
}
|
|
5588
|
+
var i2 = 0;
|
|
5589
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
5590
|
+
carry += BASE * b256[it3] >>> 0;
|
|
5591
|
+
b256[it3] = carry % 256 >>> 0;
|
|
5592
|
+
carry = carry / 256 >>> 0;
|
|
5593
|
+
}
|
|
5594
|
+
if (carry !== 0) {
|
|
5595
|
+
throw new Error("Non-zero carry");
|
|
5596
|
+
}
|
|
5597
|
+
length2 = i2;
|
|
5598
|
+
psz++;
|
|
5599
|
+
}
|
|
5600
|
+
if (source[psz] === " ") {
|
|
5601
|
+
return;
|
|
5602
|
+
}
|
|
5603
|
+
var it4 = size - length2;
|
|
5604
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
5605
|
+
it4++;
|
|
5606
|
+
}
|
|
5607
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
5608
|
+
var j2 = zeroes;
|
|
5609
|
+
while (it4 !== size) {
|
|
5610
|
+
vch[j2++] = b256[it4++];
|
|
5611
|
+
}
|
|
5612
|
+
return vch;
|
|
5613
|
+
}
|
|
5614
|
+
function decode5(string) {
|
|
5615
|
+
var buffer = decodeUnsafe(string);
|
|
5616
|
+
if (buffer) {
|
|
5617
|
+
return buffer;
|
|
5618
|
+
}
|
|
5619
|
+
throw new Error(`Non-${name} character`);
|
|
5872
5620
|
}
|
|
5873
5621
|
return {
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
saleEnd: salesConfig.saleEnd.toString(),
|
|
5878
|
-
merkleRoot: salesConfig.presaleMerkleRoot,
|
|
5879
|
-
mintFeePerQuantity: contractMintFee
|
|
5880
|
-
};
|
|
5881
|
-
}
|
|
5882
|
-
function makeOnchainPrepareMintFromCreate({
|
|
5883
|
-
contractAddress,
|
|
5884
|
-
tokenId,
|
|
5885
|
-
result,
|
|
5886
|
-
minter,
|
|
5887
|
-
getContractMintFee,
|
|
5888
|
-
contractVersion
|
|
5889
|
-
}) {
|
|
5890
|
-
return async (params) => {
|
|
5891
|
-
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
5892
|
-
minter,
|
|
5893
|
-
getContractMintFee,
|
|
5894
|
-
salesConfig: result
|
|
5895
|
-
});
|
|
5896
|
-
return {
|
|
5897
|
-
parameters: makePrepareMint1155TokenParams({
|
|
5898
|
-
salesConfigAndTokenInfo: {
|
|
5899
|
-
salesConfig: subgraphSalesConfig,
|
|
5900
|
-
contractVersion
|
|
5901
|
-
},
|
|
5902
|
-
...params,
|
|
5903
|
-
tokenContract: contractAddress,
|
|
5904
|
-
tokenId
|
|
5905
|
-
}),
|
|
5906
|
-
costs: parseMintCosts({
|
|
5907
|
-
allowListEntry: params.allowListEntry,
|
|
5908
|
-
quantityToMint: BigInt(params.quantityToMint),
|
|
5909
|
-
salesConfig: subgraphSalesConfig
|
|
5910
|
-
}),
|
|
5911
|
-
erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
|
|
5912
|
-
};
|
|
5622
|
+
encode: encode3,
|
|
5623
|
+
decodeUnsafe,
|
|
5624
|
+
decode: decode5
|
|
5913
5625
|
};
|
|
5914
5626
|
}
|
|
5627
|
+
var src = base2;
|
|
5628
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
5629
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
5915
5630
|
|
|
5916
|
-
// src/
|
|
5917
|
-
var
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
}
|
|
5929
|
-
}
|
|
5631
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
|
|
5632
|
+
var Encoder = class {
|
|
5633
|
+
constructor(name, prefix, baseEncode) {
|
|
5634
|
+
__publicField(this, "name");
|
|
5635
|
+
__publicField(this, "prefix");
|
|
5636
|
+
__publicField(this, "baseEncode");
|
|
5637
|
+
this.name = name;
|
|
5638
|
+
this.prefix = prefix;
|
|
5639
|
+
this.baseEncode = baseEncode;
|
|
5640
|
+
}
|
|
5641
|
+
encode(bytes) {
|
|
5642
|
+
if (bytes instanceof Uint8Array) {
|
|
5643
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
5644
|
+
} else {
|
|
5645
|
+
throw Error("Unknown type, must be binary type");
|
|
5930
5646
|
}
|
|
5931
5647
|
}
|
|
5932
|
-
throw new Error(
|
|
5933
|
-
"No event found in receipt that could be used to get tokenId"
|
|
5934
|
-
);
|
|
5935
5648
|
};
|
|
5936
|
-
var
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5649
|
+
var Decoder = class {
|
|
5650
|
+
constructor(name, prefix, baseDecode) {
|
|
5651
|
+
__publicField(this, "name");
|
|
5652
|
+
__publicField(this, "prefix");
|
|
5653
|
+
__publicField(this, "baseDecode");
|
|
5654
|
+
__publicField(this, "prefixCodePoint");
|
|
5655
|
+
this.name = name;
|
|
5656
|
+
this.prefix = prefix;
|
|
5657
|
+
if (prefix.codePointAt(0) === void 0) {
|
|
5658
|
+
throw new Error("Invalid prefix character");
|
|
5659
|
+
}
|
|
5660
|
+
this.prefixCodePoint = prefix.codePointAt(0);
|
|
5661
|
+
this.baseDecode = baseDecode;
|
|
5662
|
+
}
|
|
5663
|
+
decode(text) {
|
|
5664
|
+
if (typeof text === "string") {
|
|
5665
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
5666
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
5946
5667
|
}
|
|
5947
|
-
|
|
5668
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
5669
|
+
} else {
|
|
5670
|
+
throw Error("Can only multibase decode strings");
|
|
5948
5671
|
}
|
|
5949
5672
|
}
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5673
|
+
or(decoder) {
|
|
5674
|
+
return or(this, decoder);
|
|
5675
|
+
}
|
|
5953
5676
|
};
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
}
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
},
|
|
5977
|
-
contract.defaultAdmin || accountAddress,
|
|
5978
|
-
tokenSetupActions
|
|
5979
|
-
]
|
|
5980
|
-
});
|
|
5981
|
-
}
|
|
5982
|
-
function makeCreateTokenCall({
|
|
5983
|
-
contractAddress,
|
|
5984
|
-
account,
|
|
5985
|
-
tokenSetupActions
|
|
5986
|
-
}) {
|
|
5987
|
-
return makeContractParameters({
|
|
5988
|
-
abi: zoraCreator1155ImplABI6,
|
|
5989
|
-
functionName: "multicall",
|
|
5990
|
-
account,
|
|
5991
|
-
address: contractAddress,
|
|
5992
|
-
args: [tokenSetupActions]
|
|
5677
|
+
var ComposedDecoder = class {
|
|
5678
|
+
constructor(decoders) {
|
|
5679
|
+
__publicField(this, "decoders");
|
|
5680
|
+
this.decoders = decoders;
|
|
5681
|
+
}
|
|
5682
|
+
or(decoder) {
|
|
5683
|
+
return or(this, decoder);
|
|
5684
|
+
}
|
|
5685
|
+
decode(input) {
|
|
5686
|
+
const prefix = input[0];
|
|
5687
|
+
const decoder = this.decoders[prefix];
|
|
5688
|
+
if (decoder != null) {
|
|
5689
|
+
return decoder.decode(input);
|
|
5690
|
+
} else {
|
|
5691
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
};
|
|
5695
|
+
function or(left, right) {
|
|
5696
|
+
return new ComposedDecoder({
|
|
5697
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
5698
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
5993
5699
|
});
|
|
5994
5700
|
}
|
|
5995
|
-
var
|
|
5996
|
-
constructor({
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
this
|
|
6002
|
-
this
|
|
6003
|
-
this.
|
|
5701
|
+
var Codec = class {
|
|
5702
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
5703
|
+
__publicField(this, "name");
|
|
5704
|
+
__publicField(this, "prefix");
|
|
5705
|
+
__publicField(this, "baseEncode");
|
|
5706
|
+
__publicField(this, "baseDecode");
|
|
5707
|
+
__publicField(this, "encoder");
|
|
5708
|
+
__publicField(this, "decoder");
|
|
5709
|
+
this.name = name;
|
|
5710
|
+
this.prefix = prefix;
|
|
5711
|
+
this.baseEncode = baseEncode;
|
|
5712
|
+
this.baseDecode = baseDecode;
|
|
5713
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
5714
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
6004
5715
|
}
|
|
6005
|
-
|
|
6006
|
-
return
|
|
6007
|
-
...props,
|
|
6008
|
-
publicClient: this.publicClient,
|
|
6009
|
-
chainId: this.chainId
|
|
6010
|
-
});
|
|
5716
|
+
encode(input) {
|
|
5717
|
+
return this.encoder.encode(input);
|
|
6011
5718
|
}
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
account,
|
|
6015
|
-
token,
|
|
6016
|
-
getAdditionalSetupActions
|
|
6017
|
-
}) {
|
|
6018
|
-
return createNew1155Token({
|
|
6019
|
-
contractAddress: contract,
|
|
6020
|
-
account,
|
|
6021
|
-
token,
|
|
6022
|
-
getAdditionalSetupActions,
|
|
6023
|
-
publicClient: this.publicClient,
|
|
6024
|
-
chainId: this.chainId,
|
|
6025
|
-
contractGetter: this.contractGetter
|
|
6026
|
-
});
|
|
5719
|
+
decode(input) {
|
|
5720
|
+
return this.decoder.decode(input);
|
|
6027
5721
|
}
|
|
6028
5722
|
};
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
account,
|
|
6032
|
-
chainId,
|
|
6033
|
-
token,
|
|
6034
|
-
publicClient,
|
|
6035
|
-
getAdditionalSetupActions
|
|
6036
|
-
}) {
|
|
6037
|
-
const nextTokenId = 1n;
|
|
6038
|
-
const contractVersion = new1155ContractVersion(chainId);
|
|
6039
|
-
const {
|
|
6040
|
-
minter,
|
|
6041
|
-
newToken,
|
|
6042
|
-
setupActions: tokenSetupActions
|
|
6043
|
-
} = await prepareSetupActions({
|
|
6044
|
-
chainId,
|
|
6045
|
-
account,
|
|
6046
|
-
contractVersion,
|
|
6047
|
-
nextTokenId,
|
|
6048
|
-
token,
|
|
6049
|
-
getAdditionalSetupActions
|
|
6050
|
-
});
|
|
6051
|
-
const request = makeCreateContractAndTokenCall({
|
|
6052
|
-
contract,
|
|
6053
|
-
account,
|
|
6054
|
-
chainId,
|
|
6055
|
-
tokenSetupActions,
|
|
6056
|
-
fundsRecipient: token.payoutRecipient,
|
|
6057
|
-
royaltyBPS: token.royaltyBPS
|
|
6058
|
-
});
|
|
6059
|
-
const contractAddress = await getDeterministicContractAddress({
|
|
6060
|
-
account,
|
|
6061
|
-
publicClient,
|
|
6062
|
-
setupActions: tokenSetupActions,
|
|
6063
|
-
chainId,
|
|
6064
|
-
contract
|
|
6065
|
-
});
|
|
6066
|
-
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
6067
|
-
contractAddress,
|
|
6068
|
-
contractVersion,
|
|
6069
|
-
minter,
|
|
6070
|
-
result: newToken.salesConfig,
|
|
6071
|
-
tokenId: nextTokenId,
|
|
6072
|
-
// to get the contract wide mint fee, we get what it would be for a new contract
|
|
6073
|
-
getContractMintFee: async () => getNewContractMintFee({
|
|
6074
|
-
publicClient,
|
|
6075
|
-
chainId
|
|
6076
|
-
})
|
|
6077
|
-
});
|
|
6078
|
-
return {
|
|
6079
|
-
parameters: request,
|
|
6080
|
-
tokenSetupActions,
|
|
6081
|
-
newTokenId: nextTokenId,
|
|
6082
|
-
newToken,
|
|
6083
|
-
contractAddress,
|
|
6084
|
-
contractVersion,
|
|
6085
|
-
minter,
|
|
6086
|
-
prepareMint
|
|
6087
|
-
};
|
|
5723
|
+
function from({ name, prefix, encode: encode3, decode: decode5 }) {
|
|
5724
|
+
return new Codec(name, prefix, encode3, decode5);
|
|
6088
5725
|
}
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
}) {
|
|
6097
|
-
const { nextTokenId, contractVersion, mintFee } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
|
|
6098
|
-
const {
|
|
6099
|
-
minter,
|
|
6100
|
-
newToken,
|
|
6101
|
-
setupActions: tokenSetupActions
|
|
6102
|
-
} = await prepareSetupActions({
|
|
6103
|
-
chainId,
|
|
6104
|
-
account,
|
|
6105
|
-
contractVersion,
|
|
6106
|
-
nextTokenId,
|
|
6107
|
-
token,
|
|
6108
|
-
getAdditionalSetupActions
|
|
6109
|
-
});
|
|
6110
|
-
const request = makeCreateTokenCall({
|
|
6111
|
-
contractAddress,
|
|
6112
|
-
account,
|
|
6113
|
-
tokenSetupActions
|
|
6114
|
-
});
|
|
6115
|
-
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
6116
|
-
contractAddress,
|
|
6117
|
-
contractVersion,
|
|
6118
|
-
minter,
|
|
6119
|
-
result: newToken.salesConfig,
|
|
6120
|
-
tokenId: nextTokenId,
|
|
6121
|
-
getContractMintFee: async () => mintFee
|
|
5726
|
+
function baseX({ name, prefix, alphabet }) {
|
|
5727
|
+
const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
|
|
5728
|
+
return from({
|
|
5729
|
+
prefix,
|
|
5730
|
+
name,
|
|
5731
|
+
encode: encode3,
|
|
5732
|
+
decode: (text) => coerce3(decode5(text))
|
|
6122
5733
|
});
|
|
6123
|
-
return {
|
|
6124
|
-
parameters: request,
|
|
6125
|
-
tokenSetupActions,
|
|
6126
|
-
newTokenId: nextTokenId,
|
|
6127
|
-
newToken,
|
|
6128
|
-
contractVersion,
|
|
6129
|
-
minter,
|
|
6130
|
-
prepareMint
|
|
6131
|
-
};
|
|
6132
5734
|
}
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
5735
|
+
function decode(string, alphabet, bitsPerChar, name) {
|
|
5736
|
+
const codes = {};
|
|
5737
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
5738
|
+
codes[alphabet[i]] = i;
|
|
5739
|
+
}
|
|
5740
|
+
let end = string.length;
|
|
5741
|
+
while (string[end - 1] === "=") {
|
|
5742
|
+
--end;
|
|
5743
|
+
}
|
|
5744
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
5745
|
+
let bits = 0;
|
|
5746
|
+
let buffer = 0;
|
|
5747
|
+
let written = 0;
|
|
5748
|
+
for (let i = 0; i < end; ++i) {
|
|
5749
|
+
const value = codes[string[i]];
|
|
5750
|
+
if (value === void 0) {
|
|
5751
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
5752
|
+
}
|
|
5753
|
+
buffer = buffer << bitsPerChar | value;
|
|
5754
|
+
bits += bitsPerChar;
|
|
5755
|
+
if (bits >= 8) {
|
|
5756
|
+
bits -= 8;
|
|
5757
|
+
out[written++] = 255 & buffer >> bits;
|
|
5758
|
+
}
|
|
5759
|
+
}
|
|
5760
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
5761
|
+
throw new SyntaxError("Unexpected end of data");
|
|
5762
|
+
}
|
|
5763
|
+
return out;
|
|
6159
5764
|
}
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
5765
|
+
function encode(data, alphabet, bitsPerChar) {
|
|
5766
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
5767
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
5768
|
+
let out = "";
|
|
5769
|
+
let bits = 0;
|
|
5770
|
+
let buffer = 0;
|
|
5771
|
+
for (let i = 0; i < data.length; ++i) {
|
|
5772
|
+
buffer = buffer << 8 | data[i];
|
|
5773
|
+
bits += 8;
|
|
5774
|
+
while (bits > bitsPerChar) {
|
|
5775
|
+
bits -= bitsPerChar;
|
|
5776
|
+
out += alphabet[mask & buffer >> bits];
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
if (bits !== 0) {
|
|
5780
|
+
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
5781
|
+
}
|
|
5782
|
+
if (pad) {
|
|
5783
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
5784
|
+
out += "=";
|
|
5785
|
+
}
|
|
5786
|
+
}
|
|
5787
|
+
return out;
|
|
5788
|
+
}
|
|
5789
|
+
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
5790
|
+
return from({
|
|
5791
|
+
prefix,
|
|
5792
|
+
name,
|
|
5793
|
+
encode(input) {
|
|
5794
|
+
return encode(input, alphabet, bitsPerChar);
|
|
5795
|
+
},
|
|
5796
|
+
decode(input) {
|
|
5797
|
+
return decode(input, alphabet, bitsPerChar, name);
|
|
5798
|
+
}
|
|
5799
|
+
});
|
|
5800
|
+
}
|
|
5801
|
+
|
|
5802
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
|
|
5803
|
+
var base32 = rfc4648({
|
|
5804
|
+
prefix: "b",
|
|
5805
|
+
name: "base32",
|
|
5806
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
5807
|
+
bitsPerChar: 5
|
|
5808
|
+
});
|
|
5809
|
+
var base32upper = rfc4648({
|
|
5810
|
+
prefix: "B",
|
|
5811
|
+
name: "base32upper",
|
|
5812
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
5813
|
+
bitsPerChar: 5
|
|
5814
|
+
});
|
|
5815
|
+
var base32pad = rfc4648({
|
|
5816
|
+
prefix: "c",
|
|
5817
|
+
name: "base32pad",
|
|
5818
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
5819
|
+
bitsPerChar: 5
|
|
5820
|
+
});
|
|
5821
|
+
var base32padupper = rfc4648({
|
|
5822
|
+
prefix: "C",
|
|
5823
|
+
name: "base32padupper",
|
|
5824
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
5825
|
+
bitsPerChar: 5
|
|
5826
|
+
});
|
|
5827
|
+
var base32hex = rfc4648({
|
|
5828
|
+
prefix: "v",
|
|
5829
|
+
name: "base32hex",
|
|
5830
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
5831
|
+
bitsPerChar: 5
|
|
5832
|
+
});
|
|
5833
|
+
var base32hexupper = rfc4648({
|
|
5834
|
+
prefix: "V",
|
|
5835
|
+
name: "base32hexupper",
|
|
5836
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
5837
|
+
bitsPerChar: 5
|
|
5838
|
+
});
|
|
5839
|
+
var base32hexpad = rfc4648({
|
|
5840
|
+
prefix: "t",
|
|
5841
|
+
name: "base32hexpad",
|
|
5842
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
5843
|
+
bitsPerChar: 5
|
|
5844
|
+
});
|
|
5845
|
+
var base32hexpadupper = rfc4648({
|
|
5846
|
+
prefix: "T",
|
|
5847
|
+
name: "base32hexpadupper",
|
|
5848
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
5849
|
+
bitsPerChar: 5
|
|
5850
|
+
});
|
|
5851
|
+
var base32z = rfc4648({
|
|
5852
|
+
prefix: "h",
|
|
5853
|
+
name: "base32z",
|
|
5854
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
5855
|
+
bitsPerChar: 5
|
|
5856
|
+
});
|
|
5857
|
+
|
|
5858
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
5859
|
+
var base58btc = baseX({
|
|
5860
|
+
name: "base58btc",
|
|
5861
|
+
prefix: "z",
|
|
5862
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
5863
|
+
});
|
|
5864
|
+
var base58flickr = baseX({
|
|
5865
|
+
name: "base58flickr",
|
|
5866
|
+
prefix: "Z",
|
|
5867
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
5868
|
+
});
|
|
5869
|
+
|
|
5870
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
5871
|
+
var encode_1 = encode2;
|
|
5872
|
+
var MSB = 128;
|
|
5873
|
+
var REST = 127;
|
|
5874
|
+
var MSBALL = ~REST;
|
|
5875
|
+
var INT = Math.pow(2, 31);
|
|
5876
|
+
function encode2(num, out, offset) {
|
|
5877
|
+
out = out || [];
|
|
5878
|
+
offset = offset || 0;
|
|
5879
|
+
var oldOffset = offset;
|
|
5880
|
+
while (num >= INT) {
|
|
5881
|
+
out[offset++] = num & 255 | MSB;
|
|
5882
|
+
num /= 128;
|
|
5883
|
+
}
|
|
5884
|
+
while (num & MSBALL) {
|
|
5885
|
+
out[offset++] = num & 255 | MSB;
|
|
5886
|
+
num >>>= 7;
|
|
5887
|
+
}
|
|
5888
|
+
out[offset] = num | 0;
|
|
5889
|
+
encode2.bytes = offset - oldOffset + 1;
|
|
5890
|
+
return out;
|
|
5891
|
+
}
|
|
5892
|
+
var decode2 = read;
|
|
5893
|
+
var MSB$1 = 128;
|
|
5894
|
+
var REST$1 = 127;
|
|
5895
|
+
function read(buf, offset) {
|
|
5896
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
5897
|
+
do {
|
|
5898
|
+
if (counter >= l) {
|
|
5899
|
+
read.bytes = 0;
|
|
5900
|
+
throw new RangeError("Could not decode varint");
|
|
5901
|
+
}
|
|
5902
|
+
b = buf[counter++];
|
|
5903
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
5904
|
+
shift += 7;
|
|
5905
|
+
} while (b >= MSB$1);
|
|
5906
|
+
read.bytes = counter - offset;
|
|
5907
|
+
return res;
|
|
5908
|
+
}
|
|
5909
|
+
var N1 = Math.pow(2, 7);
|
|
5910
|
+
var N2 = Math.pow(2, 14);
|
|
5911
|
+
var N3 = Math.pow(2, 21);
|
|
5912
|
+
var N4 = Math.pow(2, 28);
|
|
5913
|
+
var N5 = Math.pow(2, 35);
|
|
5914
|
+
var N6 = Math.pow(2, 42);
|
|
5915
|
+
var N7 = Math.pow(2, 49);
|
|
5916
|
+
var N8 = Math.pow(2, 56);
|
|
5917
|
+
var N9 = Math.pow(2, 63);
|
|
5918
|
+
var length = function(value) {
|
|
5919
|
+
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
|
|
5920
|
+
};
|
|
5921
|
+
var varint = {
|
|
5922
|
+
encode: encode_1,
|
|
5923
|
+
decode: decode2,
|
|
5924
|
+
encodingLength: length
|
|
5925
|
+
};
|
|
5926
|
+
var _brrp_varint = varint;
|
|
5927
|
+
var varint_default = _brrp_varint;
|
|
5928
|
+
|
|
5929
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
|
|
5930
|
+
function decode3(data, offset = 0) {
|
|
5931
|
+
const code = varint_default.decode(data, offset);
|
|
5932
|
+
return [code, varint_default.decode.bytes];
|
|
5933
|
+
}
|
|
5934
|
+
function encodeTo(int, target, offset = 0) {
|
|
5935
|
+
varint_default.encode(int, target, offset);
|
|
5936
|
+
return target;
|
|
5937
|
+
}
|
|
5938
|
+
function encodingLength(int) {
|
|
5939
|
+
return varint_default.encodingLength(int);
|
|
5940
|
+
}
|
|
5941
|
+
|
|
5942
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
|
|
5943
|
+
function create(code, digest) {
|
|
5944
|
+
const size = digest.byteLength;
|
|
5945
|
+
const sizeOffset = encodingLength(code);
|
|
5946
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
5947
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
5948
|
+
encodeTo(code, bytes, 0);
|
|
5949
|
+
encodeTo(size, bytes, sizeOffset);
|
|
5950
|
+
bytes.set(digest, digestOffset);
|
|
5951
|
+
return new Digest(code, size, digest, bytes);
|
|
5952
|
+
}
|
|
5953
|
+
function decode4(multihash) {
|
|
5954
|
+
const bytes = coerce3(multihash);
|
|
5955
|
+
const [code, sizeOffset] = decode3(bytes);
|
|
5956
|
+
const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
|
|
5957
|
+
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
5958
|
+
if (digest.byteLength !== size) {
|
|
5959
|
+
throw new Error("Incorrect length");
|
|
5960
|
+
}
|
|
5961
|
+
return new Digest(code, size, digest, bytes);
|
|
5962
|
+
}
|
|
5963
|
+
function equals2(a, b) {
|
|
5964
|
+
if (a === b) {
|
|
5965
|
+
return true;
|
|
5966
|
+
} else {
|
|
5967
|
+
const data = b;
|
|
5968
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
5969
|
+
}
|
|
5970
|
+
}
|
|
5971
|
+
var Digest = class {
|
|
5972
|
+
/**
|
|
5973
|
+
* Creates a multihash digest.
|
|
5974
|
+
*/
|
|
5975
|
+
constructor(code, size, digest, bytes) {
|
|
5976
|
+
__publicField(this, "code");
|
|
5977
|
+
__publicField(this, "size");
|
|
5978
|
+
__publicField(this, "digest");
|
|
5979
|
+
__publicField(this, "bytes");
|
|
5980
|
+
this.code = code;
|
|
5981
|
+
this.size = size;
|
|
5982
|
+
this.digest = digest;
|
|
5983
|
+
this.bytes = bytes;
|
|
5984
|
+
}
|
|
5985
|
+
};
|
|
5986
|
+
|
|
5987
|
+
// ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
|
|
5988
|
+
function format(link, base3) {
|
|
5989
|
+
const { bytes, version } = link;
|
|
5990
|
+
switch (version) {
|
|
5991
|
+
case 0:
|
|
5992
|
+
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
5993
|
+
default:
|
|
5994
|
+
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
5995
|
+
}
|
|
5996
|
+
}
|
|
5997
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
5998
|
+
function baseCache(cid) {
|
|
5999
|
+
const baseCache2 = cache.get(cid);
|
|
6000
|
+
if (baseCache2 == null) {
|
|
6001
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
6002
|
+
cache.set(cid, baseCache3);
|
|
6003
|
+
return baseCache3;
|
|
6004
|
+
}
|
|
6005
|
+
return baseCache2;
|
|
6006
|
+
}
|
|
6007
|
+
var _a;
|
|
6008
|
+
var CID = class _CID {
|
|
6009
|
+
/**
|
|
6010
|
+
* @param version - Version of the CID
|
|
6011
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
6012
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
6013
|
+
*/
|
|
6014
|
+
constructor(version, code, multihash, bytes) {
|
|
6015
|
+
__publicField(this, "code");
|
|
6016
|
+
__publicField(this, "version");
|
|
6017
|
+
__publicField(this, "multihash");
|
|
6018
|
+
__publicField(this, "bytes");
|
|
6019
|
+
__publicField(this, "/");
|
|
6020
|
+
__publicField(this, _a, "CID");
|
|
6021
|
+
this.code = code;
|
|
6022
|
+
this.version = version;
|
|
6023
|
+
this.multihash = multihash;
|
|
6024
|
+
this.bytes = bytes;
|
|
6025
|
+
this["/"] = bytes;
|
|
6026
|
+
}
|
|
6027
|
+
/**
|
|
6028
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
6029
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
6030
|
+
*
|
|
6031
|
+
* @deprecated
|
|
6032
|
+
*/
|
|
6033
|
+
get asCID() {
|
|
6034
|
+
return this;
|
|
6035
|
+
}
|
|
6036
|
+
// ArrayBufferView
|
|
6037
|
+
get byteOffset() {
|
|
6038
|
+
return this.bytes.byteOffset;
|
|
6039
|
+
}
|
|
6040
|
+
// ArrayBufferView
|
|
6041
|
+
get byteLength() {
|
|
6042
|
+
return this.bytes.byteLength;
|
|
6043
|
+
}
|
|
6044
|
+
toV0() {
|
|
6045
|
+
switch (this.version) {
|
|
6046
|
+
case 0: {
|
|
6047
|
+
return this;
|
|
6048
|
+
}
|
|
6049
|
+
case 1: {
|
|
6050
|
+
const { code, multihash } = this;
|
|
6051
|
+
if (code !== DAG_PB_CODE) {
|
|
6052
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
6053
|
+
}
|
|
6054
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
6055
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
6056
|
+
}
|
|
6057
|
+
return _CID.createV0(multihash);
|
|
6058
|
+
}
|
|
6059
|
+
default: {
|
|
6060
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
6061
|
+
}
|
|
6062
|
+
}
|
|
6063
|
+
}
|
|
6064
|
+
toV1() {
|
|
6065
|
+
switch (this.version) {
|
|
6066
|
+
case 0: {
|
|
6067
|
+
const { code, digest } = this.multihash;
|
|
6068
|
+
const multihash = create(code, digest);
|
|
6069
|
+
return _CID.createV1(this.code, multihash);
|
|
6070
|
+
}
|
|
6071
|
+
case 1: {
|
|
6072
|
+
return this;
|
|
6073
|
+
}
|
|
6074
|
+
default: {
|
|
6075
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
6076
|
+
}
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
equals(other) {
|
|
6080
|
+
return _CID.equals(this, other);
|
|
6081
|
+
}
|
|
6082
|
+
static equals(self, other) {
|
|
6083
|
+
const unknown = other;
|
|
6084
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
6085
|
+
}
|
|
6086
|
+
toString(base3) {
|
|
6087
|
+
return format(this, base3);
|
|
6088
|
+
}
|
|
6089
|
+
toJSON() {
|
|
6090
|
+
return { "/": format(this) };
|
|
6091
|
+
}
|
|
6092
|
+
link() {
|
|
6093
|
+
return this;
|
|
6094
|
+
}
|
|
6095
|
+
// Legacy
|
|
6096
|
+
[(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
|
|
6097
|
+
return `CID(${this.toString()})`;
|
|
6098
|
+
}
|
|
6099
|
+
/**
|
|
6100
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
6101
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
6102
|
+
* it will return value back. If `value` is not instance of this CID
|
|
6103
|
+
* class, but is compatible CID it will return new instance of this
|
|
6104
|
+
* `CID` class. Otherwise returns null.
|
|
6105
|
+
*
|
|
6106
|
+
* This allows two different incompatible versions of CID library to
|
|
6107
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
6108
|
+
*/
|
|
6109
|
+
static asCID(input) {
|
|
6110
|
+
if (input == null) {
|
|
6111
|
+
return null;
|
|
6112
|
+
}
|
|
6113
|
+
const value = input;
|
|
6114
|
+
if (value instanceof _CID) {
|
|
6115
|
+
return value;
|
|
6116
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
6117
|
+
const { version, code, multihash, bytes } = value;
|
|
6118
|
+
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
6119
|
+
} else if (value[cidSymbol] === true) {
|
|
6120
|
+
const { version, multihash, code } = value;
|
|
6121
|
+
const digest = decode4(multihash);
|
|
6122
|
+
return _CID.create(version, code, digest);
|
|
6123
|
+
} else {
|
|
6124
|
+
return null;
|
|
6125
|
+
}
|
|
6126
|
+
}
|
|
6127
|
+
/**
|
|
6128
|
+
* @param version - Version of the CID
|
|
6129
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
6130
|
+
* @param digest - (Multi)hash of the of the content.
|
|
6131
|
+
*/
|
|
6132
|
+
static create(version, code, digest) {
|
|
6133
|
+
if (typeof code !== "number") {
|
|
6134
|
+
throw new Error("String codecs are no longer supported");
|
|
6135
|
+
}
|
|
6136
|
+
if (!(digest.bytes instanceof Uint8Array)) {
|
|
6137
|
+
throw new Error("Invalid digest");
|
|
6138
|
+
}
|
|
6139
|
+
switch (version) {
|
|
6140
|
+
case 0: {
|
|
6141
|
+
if (code !== DAG_PB_CODE) {
|
|
6142
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
6143
|
+
} else {
|
|
6144
|
+
return new _CID(version, code, digest, digest.bytes);
|
|
6170
6145
|
}
|
|
6171
6146
|
}
|
|
6147
|
+
case 1: {
|
|
6148
|
+
const bytes = encodeCID(version, code, digest.bytes);
|
|
6149
|
+
return new _CID(version, code, digest, bytes);
|
|
6150
|
+
}
|
|
6151
|
+
default: {
|
|
6152
|
+
throw new Error("Invalid version");
|
|
6153
|
+
}
|
|
6172
6154
|
}
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6155
|
+
}
|
|
6156
|
+
/**
|
|
6157
|
+
* Simplified version of `create` for CIDv0.
|
|
6158
|
+
*/
|
|
6159
|
+
static createV0(digest) {
|
|
6160
|
+
return _CID.create(0, DAG_PB_CODE, digest);
|
|
6161
|
+
}
|
|
6162
|
+
/**
|
|
6163
|
+
* Simplified version of `create` for CIDv1.
|
|
6164
|
+
*
|
|
6165
|
+
* @param code - Content encoding format code.
|
|
6166
|
+
* @param digest - Multihash of the content.
|
|
6167
|
+
*/
|
|
6168
|
+
static createV1(code, digest) {
|
|
6169
|
+
return _CID.create(1, code, digest);
|
|
6170
|
+
}
|
|
6171
|
+
/**
|
|
6172
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
6173
|
+
* only the CID with no additional bytes.
|
|
6174
|
+
*
|
|
6175
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
6176
|
+
* binary representation of a CID.
|
|
6177
|
+
*/
|
|
6178
|
+
static decode(bytes) {
|
|
6179
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
6180
|
+
if (remainder.length !== 0) {
|
|
6181
|
+
throw new Error("Incorrect length");
|
|
6182
|
+
}
|
|
6183
|
+
return cid;
|
|
6184
|
+
}
|
|
6185
|
+
/**
|
|
6186
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
6187
|
+
* array.
|
|
6188
|
+
*
|
|
6189
|
+
* Returns an array with the first element containing the CID and the second
|
|
6190
|
+
* element containing the remainder of the original byte array. The remainder
|
|
6191
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
6192
|
+
* binary CID representation.
|
|
6193
|
+
*/
|
|
6194
|
+
static decodeFirst(bytes) {
|
|
6195
|
+
const specs = _CID.inspectBytes(bytes);
|
|
6196
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
6197
|
+
const multihashBytes = coerce3(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
6198
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
6199
|
+
throw new Error("Incorrect length");
|
|
6200
|
+
}
|
|
6201
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
6202
|
+
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
6203
|
+
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
6204
|
+
return [cid, bytes.subarray(specs.size)];
|
|
6205
|
+
}
|
|
6206
|
+
/**
|
|
6207
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
6208
|
+
*
|
|
6209
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
6210
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
6211
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
6212
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
6213
|
+
* inspection.
|
|
6214
|
+
*/
|
|
6215
|
+
static inspectBytes(initialBytes) {
|
|
6216
|
+
let offset = 0;
|
|
6217
|
+
const next = () => {
|
|
6218
|
+
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
6219
|
+
offset += length2;
|
|
6220
|
+
return i;
|
|
6185
6221
|
};
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
if (
|
|
6189
|
-
|
|
6222
|
+
let version = next();
|
|
6223
|
+
let codec = DAG_PB_CODE;
|
|
6224
|
+
if (version === 18) {
|
|
6225
|
+
version = 0;
|
|
6226
|
+
offset = 0;
|
|
6227
|
+
} else {
|
|
6228
|
+
codec = next();
|
|
6190
6229
|
}
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
let remainingQuantity = quantityToCollect;
|
|
6194
|
-
const tokenIds = [];
|
|
6195
|
-
const quantities = [];
|
|
6196
|
-
while (remainingQuantity > 0) {
|
|
6197
|
-
const next = sorted.shift();
|
|
6198
|
-
if (!next) {
|
|
6199
|
-
throw new Error("Not enough MINTs to collect with");
|
|
6230
|
+
if (version !== 0 && version !== 1) {
|
|
6231
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
6200
6232
|
}
|
|
6201
|
-
const
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6233
|
+
const prefixSize = offset;
|
|
6234
|
+
const multihashCode = next();
|
|
6235
|
+
const digestSize = next();
|
|
6236
|
+
const size = offset + digestSize;
|
|
6237
|
+
const multihashSize = size - prefixSize;
|
|
6238
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
6239
|
+
}
|
|
6240
|
+
/**
|
|
6241
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
6242
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
6243
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
6244
|
+
* a default decoder).
|
|
6245
|
+
*/
|
|
6246
|
+
static parse(source, base3) {
|
|
6247
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
6248
|
+
const cid = _CID.decode(bytes);
|
|
6249
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
6250
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
6251
|
+
}
|
|
6252
|
+
baseCache(cid).set(prefix, source);
|
|
6253
|
+
return cid;
|
|
6205
6254
|
}
|
|
6206
|
-
return {
|
|
6207
|
-
tokenIds,
|
|
6208
|
-
quantities
|
|
6209
|
-
};
|
|
6210
|
-
};
|
|
6211
|
-
var sumBalances = (mintAccountBalances) => {
|
|
6212
|
-
return mintAccountBalances.reduce((acc, curr) => {
|
|
6213
|
-
return acc + BigInt(curr.balance);
|
|
6214
|
-
}, BigInt(0));
|
|
6215
|
-
};
|
|
6216
|
-
|
|
6217
|
-
// src/sparks/sparks-contracts.ts
|
|
6218
|
-
import {
|
|
6219
|
-
mintsSafeTransferBatchTypedDataDefinition,
|
|
6220
|
-
mintsSafeTransferTypedDataDefinition,
|
|
6221
|
-
zoraMints1155Config,
|
|
6222
|
-
zoraMintsManagerImplABI,
|
|
6223
|
-
zoraMintsManagerImplAddress,
|
|
6224
|
-
zoraMintsManagerImplConfig,
|
|
6225
|
-
zoraSparksManagerImplABI,
|
|
6226
|
-
zoraSparksManagerImplAddress
|
|
6227
|
-
} from "@zoralabs/protocol-deployments";
|
|
6228
|
-
import {
|
|
6229
|
-
decodeErrorResult,
|
|
6230
|
-
encodeFunctionData as encodeFunctionData3,
|
|
6231
|
-
zeroAddress as zeroAddress7
|
|
6232
|
-
} from "viem";
|
|
6233
|
-
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
6234
|
-
var mintWithEthParams = ({
|
|
6235
|
-
tokenId,
|
|
6236
|
-
quantity,
|
|
6237
|
-
recipient,
|
|
6238
|
-
chainId,
|
|
6239
|
-
pricePerMint,
|
|
6240
|
-
account
|
|
6241
|
-
}) => makeContractParameters({
|
|
6242
|
-
abi: zoraSparksManagerImplABI,
|
|
6243
|
-
address: zoraSparksManagerImplAddress[chainId],
|
|
6244
|
-
functionName: "mintWithEth",
|
|
6245
|
-
args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
|
|
6246
|
-
value: pricePerMint * quantity,
|
|
6247
|
-
account
|
|
6248
|
-
});
|
|
6249
|
-
var getPaidMintValue = (quantities, pricePerMint) => {
|
|
6250
|
-
if (!pricePerMint || pricePerMint === 0n)
|
|
6251
|
-
return;
|
|
6252
|
-
return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
|
|
6253
6255
|
};
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
}
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
});
|
|
6278
|
-
function collectWithMintsParams({
|
|
6279
|
-
tokenIds,
|
|
6280
|
-
quantities,
|
|
6281
|
-
chainId,
|
|
6282
|
-
paidMintPricePerToken,
|
|
6283
|
-
account,
|
|
6284
|
-
mintArguments,
|
|
6285
|
-
minter,
|
|
6286
|
-
zoraCreator1155Contract,
|
|
6287
|
-
zoraCreator1155TokenId
|
|
6288
|
-
}) {
|
|
6289
|
-
const call = encodeCollectOnManager({
|
|
6290
|
-
tokenIds,
|
|
6291
|
-
quantities,
|
|
6292
|
-
zoraCreator1155Contract,
|
|
6293
|
-
zoraCreator1155TokenId,
|
|
6294
|
-
minter,
|
|
6295
|
-
mintArguments
|
|
6296
|
-
});
|
|
6297
|
-
return makeContractParameters({
|
|
6298
|
-
abi: zoraMints1155Config.abi,
|
|
6299
|
-
address: zoraMints1155Config.address[chainId],
|
|
6300
|
-
functionName: "transferBatchToManagerAndCall",
|
|
6301
|
-
args: [tokenIds, quantities, call],
|
|
6302
|
-
// if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
|
|
6303
|
-
// for the paid mint cost.
|
|
6304
|
-
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
6305
|
-
account
|
|
6306
|
-
});
|
|
6307
|
-
}
|
|
6308
|
-
function getMintsEthPrice({
|
|
6309
|
-
publicClient
|
|
6310
|
-
}) {
|
|
6311
|
-
const chainId = publicClient.chain?.id;
|
|
6312
|
-
if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
|
|
6313
|
-
throw new Error(`Chain id ${chainId} not supported`);
|
|
6256
|
+
function parseCIDtoBytes(source, base3) {
|
|
6257
|
+
switch (source[0]) {
|
|
6258
|
+
case "Q": {
|
|
6259
|
+
const decoder = base3 ?? base58btc;
|
|
6260
|
+
return [
|
|
6261
|
+
base58btc.prefix,
|
|
6262
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
6263
|
+
];
|
|
6264
|
+
}
|
|
6265
|
+
case base58btc.prefix: {
|
|
6266
|
+
const decoder = base3 ?? base58btc;
|
|
6267
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
6268
|
+
}
|
|
6269
|
+
case base32.prefix: {
|
|
6270
|
+
const decoder = base3 ?? base32;
|
|
6271
|
+
return [base32.prefix, decoder.decode(source)];
|
|
6272
|
+
}
|
|
6273
|
+
default: {
|
|
6274
|
+
if (base3 == null) {
|
|
6275
|
+
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
|
|
6276
|
+
}
|
|
6277
|
+
return [source[0], base3.decode(source)];
|
|
6278
|
+
}
|
|
6314
6279
|
}
|
|
6315
|
-
return publicClient.readContract({
|
|
6316
|
-
abi: zoraMintsManagerImplABI,
|
|
6317
|
-
address: zoraMintsManagerImplAddress[chainId],
|
|
6318
|
-
functionName: "getEthPrice"
|
|
6319
|
-
});
|
|
6320
|
-
}
|
|
6321
|
-
function makePermitTransferBatchAndTypeData({
|
|
6322
|
-
tokenIds,
|
|
6323
|
-
quantities,
|
|
6324
|
-
chainId,
|
|
6325
|
-
mintsOwner,
|
|
6326
|
-
to,
|
|
6327
|
-
nonce,
|
|
6328
|
-
deadline,
|
|
6329
|
-
safeTransferData
|
|
6330
|
-
}) {
|
|
6331
|
-
const permit = {
|
|
6332
|
-
owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
|
|
6333
|
-
to,
|
|
6334
|
-
tokenIds,
|
|
6335
|
-
quantities,
|
|
6336
|
-
deadline,
|
|
6337
|
-
nonce,
|
|
6338
|
-
safeTransferData
|
|
6339
|
-
};
|
|
6340
|
-
const typedData = {
|
|
6341
|
-
...mintsSafeTransferBatchTypedDataDefinition({
|
|
6342
|
-
chainId,
|
|
6343
|
-
message: permit
|
|
6344
|
-
}),
|
|
6345
|
-
account: mintsOwner
|
|
6346
|
-
};
|
|
6347
|
-
return {
|
|
6348
|
-
permit,
|
|
6349
|
-
typedData
|
|
6350
|
-
};
|
|
6351
6280
|
}
|
|
6352
|
-
function
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
tokenId,
|
|
6366
|
-
quantity,
|
|
6367
|
-
deadline,
|
|
6368
|
-
nonce,
|
|
6369
|
-
safeTransferData
|
|
6370
|
-
};
|
|
6371
|
-
const typedData = {
|
|
6372
|
-
...mintsSafeTransferTypedDataDefinition({
|
|
6373
|
-
chainId,
|
|
6374
|
-
message: permit
|
|
6375
|
-
}),
|
|
6376
|
-
account: mintsOwner
|
|
6377
|
-
};
|
|
6378
|
-
return {
|
|
6379
|
-
permit,
|
|
6380
|
-
typedData
|
|
6381
|
-
};
|
|
6281
|
+
function toStringV0(bytes, cache2, base3) {
|
|
6282
|
+
const { prefix } = base3;
|
|
6283
|
+
if (prefix !== base58btc.prefix) {
|
|
6284
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
6285
|
+
}
|
|
6286
|
+
const cid = cache2.get(prefix);
|
|
6287
|
+
if (cid == null) {
|
|
6288
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
6289
|
+
cache2.set(prefix, cid2);
|
|
6290
|
+
return cid2;
|
|
6291
|
+
} else {
|
|
6292
|
+
return cid;
|
|
6293
|
+
}
|
|
6382
6294
|
}
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
abi: zoraMintsManagerImplConfig.abi,
|
|
6391
|
-
functionName: "collectPremintV2",
|
|
6392
|
-
args: [
|
|
6393
|
-
contractCreationConfig,
|
|
6394
|
-
premintConfig,
|
|
6395
|
-
premintSignature,
|
|
6396
|
-
mintArguments,
|
|
6397
|
-
signerContract
|
|
6398
|
-
]
|
|
6399
|
-
});
|
|
6400
|
-
var makePermitToCollectPremintOrNonPremint = ({
|
|
6401
|
-
mintsOwner,
|
|
6402
|
-
chainId,
|
|
6403
|
-
deadline,
|
|
6404
|
-
tokenIds,
|
|
6405
|
-
// this quantity of MINTs will be used to collect premint
|
|
6406
|
-
// and will be burned. This same quantity is the quantity of
|
|
6407
|
-
// premint to collect.
|
|
6408
|
-
quantities,
|
|
6409
|
-
nonce,
|
|
6410
|
-
premint,
|
|
6411
|
-
collect
|
|
6412
|
-
}) => {
|
|
6413
|
-
let safeTransferData;
|
|
6414
|
-
if (premint) {
|
|
6415
|
-
safeTransferData = encodePremintOnManager(premint);
|
|
6416
|
-
} else if (collect) {
|
|
6417
|
-
safeTransferData = encodeCollectOnManager(collect);
|
|
6295
|
+
function toStringV1(bytes, cache2, base3) {
|
|
6296
|
+
const { prefix } = base3;
|
|
6297
|
+
const cid = cache2.get(prefix);
|
|
6298
|
+
if (cid == null) {
|
|
6299
|
+
const cid2 = base3.encode(bytes);
|
|
6300
|
+
cache2.set(prefix, cid2);
|
|
6301
|
+
return cid2;
|
|
6418
6302
|
} else {
|
|
6419
|
-
|
|
6303
|
+
return cid;
|
|
6420
6304
|
}
|
|
6421
|
-
return makePermitTransferBatchAndTypeData({
|
|
6422
|
-
tokenIds,
|
|
6423
|
-
quantities,
|
|
6424
|
-
chainId,
|
|
6425
|
-
mintsOwner,
|
|
6426
|
-
nonce,
|
|
6427
|
-
deadline,
|
|
6428
|
-
safeTransferData,
|
|
6429
|
-
to: zoraMintsManagerImplConfig.address[chainId]
|
|
6430
|
-
});
|
|
6431
|
-
};
|
|
6432
|
-
function collectPremintV2WithMintsParams({
|
|
6433
|
-
tokenIds,
|
|
6434
|
-
quantities,
|
|
6435
|
-
paidMintPricePerToken,
|
|
6436
|
-
account,
|
|
6437
|
-
chainId,
|
|
6438
|
-
...rest
|
|
6439
|
-
}) {
|
|
6440
|
-
const call = encodePremintOnManager({
|
|
6441
|
-
...rest
|
|
6442
|
-
});
|
|
6443
|
-
return makeContractParameters({
|
|
6444
|
-
abi: zoraMints1155Config.abi,
|
|
6445
|
-
address: zoraMints1155Config.address[chainId],
|
|
6446
|
-
functionName: "transferBatchToManagerAndCall",
|
|
6447
|
-
args: [tokenIds, quantities, call],
|
|
6448
|
-
value: getPaidMintValue(quantities, paidMintPricePerToken),
|
|
6449
|
-
account
|
|
6450
|
-
});
|
|
6451
6305
|
}
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
const
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6306
|
+
var DAG_PB_CODE = 112;
|
|
6307
|
+
var SHA_256_CODE = 18;
|
|
6308
|
+
function encodeCID(version, code, multihash) {
|
|
6309
|
+
const codeOffset = encodingLength(version);
|
|
6310
|
+
const hashOffset = codeOffset + encodingLength(code);
|
|
6311
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
6312
|
+
encodeTo(version, bytes, 0);
|
|
6313
|
+
encodeTo(code, bytes, codeOffset);
|
|
6314
|
+
bytes.set(multihash, hashOffset);
|
|
6315
|
+
return bytes;
|
|
6460
6316
|
}
|
|
6317
|
+
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
6461
6318
|
|
|
6462
|
-
// src/
|
|
6463
|
-
function
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6319
|
+
// src/ipfs/ipfs.ts
|
|
6320
|
+
function isCID(str) {
|
|
6321
|
+
if (!str)
|
|
6322
|
+
return false;
|
|
6323
|
+
try {
|
|
6324
|
+
CID.parse(str);
|
|
6325
|
+
return true;
|
|
6326
|
+
} catch (e) {
|
|
6327
|
+
if (/^(bafy|Qm)/.test(str))
|
|
6328
|
+
return true;
|
|
6329
|
+
return false;
|
|
6330
|
+
}
|
|
6331
|
+
}
|
|
6332
|
+
function normalizeIPFSUrl(url) {
|
|
6333
|
+
if (!url || typeof url !== "string")
|
|
6334
|
+
return null;
|
|
6335
|
+
url = url.replace(/"/g, "");
|
|
6336
|
+
if (isNormalizedIPFSURL(url))
|
|
6337
|
+
return url;
|
|
6338
|
+
if (isCID(url))
|
|
6339
|
+
return `ipfs://${url}`;
|
|
6340
|
+
if (!isIPFSUrl(url))
|
|
6341
|
+
return null;
|
|
6342
|
+
if (isGatewayIPFSUrl(url)) {
|
|
6343
|
+
const parsed = new URL(url.replace(/^\/\//, "http://"));
|
|
6344
|
+
parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
|
|
6345
|
+
const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
|
|
6346
|
+
return `ipfs://${cid}`;
|
|
6347
|
+
}
|
|
6348
|
+
return null;
|
|
6349
|
+
}
|
|
6350
|
+
function isNormalizedIPFSURL(url) {
|
|
6351
|
+
return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
|
|
6352
|
+
}
|
|
6353
|
+
function isGatewayIPFSUrl(url) {
|
|
6354
|
+
if (url && typeof url === "string") {
|
|
6355
|
+
try {
|
|
6356
|
+
const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
|
|
6357
|
+
return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
|
|
6358
|
+
} catch {
|
|
6359
|
+
return false;
|
|
6477
6360
|
}
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6361
|
+
}
|
|
6362
|
+
return false;
|
|
6363
|
+
}
|
|
6364
|
+
function isIPFSUrl(url) {
|
|
6365
|
+
return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
|
|
6366
|
+
}
|
|
6367
|
+
function isNormalizeableIPFSUrl(url) {
|
|
6368
|
+
return url ? isIPFSUrl(url) || isCID(url) : false;
|
|
6369
|
+
}
|
|
6370
|
+
|
|
6371
|
+
// src/ipfs/gateway.ts
|
|
6372
|
+
var IPFS_GATEWAY = "https://magic.decentralized-content.com";
|
|
6373
|
+
var ARWEAVE_GATEWAY = "https://arweave.net";
|
|
6374
|
+
function arweaveGatewayUrl(normalizedArweaveUrl) {
|
|
6375
|
+
if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
|
|
6376
|
+
return null;
|
|
6377
|
+
return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
|
|
6484
6378
|
}
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6379
|
+
function ipfsGatewayUrl(url) {
|
|
6380
|
+
if (!url || typeof url !== "string")
|
|
6381
|
+
return null;
|
|
6382
|
+
const normalizedIPFSUrl = normalizeIPFSUrl(url);
|
|
6383
|
+
if (normalizedIPFSUrl) {
|
|
6384
|
+
return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
|
|
6491
6385
|
}
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
});
|
|
6502
|
-
return parseResponseData(responseData);
|
|
6386
|
+
return null;
|
|
6387
|
+
}
|
|
6388
|
+
function getFetchableUrl(uri) {
|
|
6389
|
+
if (!uri || typeof uri !== "string")
|
|
6390
|
+
return null;
|
|
6391
|
+
if (uri.startsWith("http://"))
|
|
6392
|
+
return null;
|
|
6393
|
+
if (isNormalizeableIPFSUrl(uri)) {
|
|
6394
|
+
return ipfsGatewayUrl(uri);
|
|
6503
6395
|
}
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
retries: retries2 = 1
|
|
6507
|
-
}) {
|
|
6508
|
-
const tryFn = async () => {
|
|
6509
|
-
const responseData2 = await this.querySubgraphWithRetries(
|
|
6510
|
-
buildContractInfoQuery({ contractAddress })
|
|
6511
|
-
);
|
|
6512
|
-
if (!responseData2) {
|
|
6513
|
-
console.log("could not find contract");
|
|
6514
|
-
throw new Error("Cannot find contract");
|
|
6515
|
-
}
|
|
6516
|
-
return responseData2;
|
|
6517
|
-
};
|
|
6518
|
-
const responseData = await retriesGeneric({
|
|
6519
|
-
tryFn,
|
|
6520
|
-
maxTries: retries2,
|
|
6521
|
-
linearBackoffMS: 1e3
|
|
6522
|
-
});
|
|
6523
|
-
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
6524
|
-
return {
|
|
6525
|
-
name: responseData.name,
|
|
6526
|
-
contractVersion: responseData.contractVersion,
|
|
6527
|
-
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
6528
|
-
nextTokenId
|
|
6529
|
-
};
|
|
6396
|
+
if (isArweaveURL(uri)) {
|
|
6397
|
+
return arweaveGatewayUrl(uri);
|
|
6530
6398
|
}
|
|
6399
|
+
if (/^(https|data|blob):/.test(uri)) {
|
|
6400
|
+
return uri;
|
|
6401
|
+
}
|
|
6402
|
+
return null;
|
|
6403
|
+
}
|
|
6404
|
+
|
|
6405
|
+
// src/ipfs/mimeTypes.ts
|
|
6406
|
+
var HTML = "text/html";
|
|
6407
|
+
var MARKDOWN = "text/markdown";
|
|
6408
|
+
var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
|
|
6409
|
+
var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
|
|
6410
|
+
var TEXT_PLAIN = "text/plain";
|
|
6411
|
+
var CSV = "text/csv";
|
|
6412
|
+
var NUMBERS = ".numbers";
|
|
6413
|
+
var EXCEL = ".xlsx";
|
|
6414
|
+
var PDF = "application/pdf";
|
|
6415
|
+
var JPG = "image/jpg";
|
|
6416
|
+
var JPEG = "image/jpeg";
|
|
6417
|
+
var PNG = "image/png";
|
|
6418
|
+
var WEBP = "image/webp";
|
|
6419
|
+
var SVG = "image/svg+xml";
|
|
6420
|
+
var TIFF = "image/tiff";
|
|
6421
|
+
var GIF = "image/gif";
|
|
6422
|
+
var isImage = (mimeType) => {
|
|
6423
|
+
if (!mimeType)
|
|
6424
|
+
return false;
|
|
6425
|
+
return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
|
|
6426
|
+
};
|
|
6427
|
+
var DEFAULT_THUMBNAIL_CID_HASHES = {
|
|
6428
|
+
["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
|
|
6429
|
+
["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
|
|
6430
|
+
["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
|
|
6431
|
+
["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
|
|
6432
|
+
// assuming all zip files are html directories
|
|
6433
|
+
["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
|
|
6434
|
+
default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
|
|
6435
|
+
};
|
|
6436
|
+
var MP4 = "video/mp4";
|
|
6437
|
+
var QUICKTIME = "video/quicktime";
|
|
6438
|
+
var M4V = "video/x-m4v";
|
|
6439
|
+
var WEBM = "video/webm";
|
|
6440
|
+
var M4A = "audio/x-m4a";
|
|
6441
|
+
var MPEG = "audio/mpeg";
|
|
6442
|
+
var MP3 = "audio/mp3";
|
|
6443
|
+
var WAV = "audio/wav";
|
|
6444
|
+
var VND_WAV = "audio/vnd.wav";
|
|
6445
|
+
var VND_WAVE = "audio/vnd.wave";
|
|
6446
|
+
var WAVE = "audio/wave";
|
|
6447
|
+
var X_WAV = "audio/x-wav";
|
|
6448
|
+
var AIFF = "audio/aiff";
|
|
6449
|
+
var GLTF = "model/gltf+json";
|
|
6450
|
+
var GLB = "model/gltf-binary";
|
|
6451
|
+
var GLTF_EXT = ".gltf";
|
|
6452
|
+
var GLB_EXT = ".glb";
|
|
6453
|
+
var JSON_MIME_TYPE = "application/json";
|
|
6454
|
+
var ZIP = "application/zip";
|
|
6455
|
+
var mimeToMediaType = {
|
|
6456
|
+
[HTML]: "HTML" /* HTML */,
|
|
6457
|
+
[JPG]: "IMAGE" /* IMAGE */,
|
|
6458
|
+
[JPEG]: "IMAGE" /* IMAGE */,
|
|
6459
|
+
[PNG]: "IMAGE" /* IMAGE */,
|
|
6460
|
+
[WEBP]: "IMAGE" /* IMAGE */,
|
|
6461
|
+
[SVG]: "IMAGE" /* IMAGE */,
|
|
6462
|
+
[TIFF]: "TIFF" /* TIFF */,
|
|
6463
|
+
[GIF]: "IMAGE" /* IMAGE */,
|
|
6464
|
+
[MP4]: "VIDEO" /* VIDEO */,
|
|
6465
|
+
[WEBM]: "VIDEO" /* VIDEO */,
|
|
6466
|
+
[QUICKTIME]: "VIDEO" /* VIDEO */,
|
|
6467
|
+
[M4V]: "VIDEO" /* VIDEO */,
|
|
6468
|
+
[MPEG]: "AUDIO" /* AUDIO */,
|
|
6469
|
+
[MP3]: "AUDIO" /* AUDIO */,
|
|
6470
|
+
[M4A]: "AUDIO" /* AUDIO */,
|
|
6471
|
+
[VND_WAV]: "AUDIO" /* AUDIO */,
|
|
6472
|
+
[VND_WAVE]: "AUDIO" /* AUDIO */,
|
|
6473
|
+
[WAV]: "AUDIO" /* AUDIO */,
|
|
6474
|
+
[WAVE]: "AUDIO" /* AUDIO */,
|
|
6475
|
+
[X_WAV]: "AUDIO" /* AUDIO */,
|
|
6476
|
+
[AIFF]: "AUDIO" /* AUDIO */,
|
|
6477
|
+
[TEXT_PLAIN]: "TEXT" /* TEXT */,
|
|
6478
|
+
[TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
|
|
6479
|
+
[MARKDOWN]: "TEXT" /* TEXT */,
|
|
6480
|
+
[MARKDOWN_UTF8]: "TEXT" /* TEXT */,
|
|
6481
|
+
[CSV]: "CSV" /* CSV */,
|
|
6482
|
+
[NUMBERS]: "NUMBERS" /* NUMBERS */,
|
|
6483
|
+
[EXCEL]: "EXCEL" /* EXCEL */,
|
|
6484
|
+
[PDF]: "PDF" /* PDF */,
|
|
6485
|
+
[ZIP]: "ZIP" /* ZIP */,
|
|
6486
|
+
[GLTF]: "MODEL" /* MODEL */,
|
|
6487
|
+
[GLTF_EXT]: "MODEL" /* MODEL */,
|
|
6488
|
+
[GLB]: "MODEL" /* MODEL */,
|
|
6489
|
+
// GLTF returns 'application/json' as the mimetype,
|
|
6490
|
+
// and as the only JSON-encoded media we currently support,
|
|
6491
|
+
// we assume that if the mimetype is JSON, it's a GLTF
|
|
6492
|
+
[JSON_MIME_TYPE]: "MODEL" /* MODEL */,
|
|
6493
|
+
[GLB_EXT]: "MODEL" /* MODEL */
|
|
6531
6494
|
};
|
|
6495
|
+
function mimeTypeToMedia(mimeType) {
|
|
6496
|
+
if (!mimeType)
|
|
6497
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
6498
|
+
return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
|
|
6499
|
+
}
|
|
6500
|
+
async function getMimeType(uri) {
|
|
6501
|
+
if (!uri)
|
|
6502
|
+
return uri;
|
|
6503
|
+
const res = await fetch(uri, { method: "HEAD" });
|
|
6504
|
+
let mimeType = res.headers.get("content-type");
|
|
6505
|
+
return mimeType;
|
|
6506
|
+
}
|
|
6532
6507
|
|
|
6533
|
-
// src/
|
|
6534
|
-
|
|
6535
|
-
const
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
}
|
|
6540
|
-
const
|
|
6541
|
-
|
|
6542
|
-
publicClient: clientConfig.publicClient,
|
|
6543
|
-
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
6544
|
-
});
|
|
6508
|
+
// src/ipfs/token-metadata.ts
|
|
6509
|
+
var makeTextTokenMetadata = (parameters) => {
|
|
6510
|
+
const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
|
|
6511
|
+
const content = textFileUrl ? {
|
|
6512
|
+
mime: TEXT_PLAIN,
|
|
6513
|
+
uri: textFileUrl
|
|
6514
|
+
} : null;
|
|
6515
|
+
const image = thumbnailUrl;
|
|
6516
|
+
const animation_url = textFileUrl;
|
|
6545
6517
|
return {
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6518
|
+
name,
|
|
6519
|
+
image,
|
|
6520
|
+
animation_url,
|
|
6521
|
+
content,
|
|
6522
|
+
attributes
|
|
6551
6523
|
};
|
|
6552
|
-
}
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6524
|
+
};
|
|
6525
|
+
var makeMediaTokenMetadata = async ({
|
|
6526
|
+
name,
|
|
6527
|
+
description,
|
|
6528
|
+
attributes = [],
|
|
6529
|
+
mediaUrl,
|
|
6530
|
+
thumbnailUrl
|
|
6531
|
+
}) => {
|
|
6532
|
+
const contentUrl = mediaUrl;
|
|
6533
|
+
const fetchableContentUrl = getFetchableUrl(contentUrl);
|
|
6534
|
+
if (!fetchableContentUrl)
|
|
6535
|
+
throw new Error(`Content url (${contentUrl}) is not fetchable`);
|
|
6536
|
+
const mimeType = await getMimeType(fetchableContentUrl);
|
|
6537
|
+
const mediaType = mimeTypeToMedia(mimeType);
|
|
6538
|
+
let image = void 0;
|
|
6539
|
+
let animation_url = null;
|
|
6540
|
+
if (isImage(mimeType)) {
|
|
6541
|
+
image = contentUrl;
|
|
6542
|
+
} else {
|
|
6543
|
+
image = thumbnailUrl;
|
|
6544
|
+
animation_url = mediaUrl;
|
|
6545
|
+
}
|
|
6546
|
+
if (!image)
|
|
6547
|
+
image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
|
|
6548
|
+
const content = contentUrl ? {
|
|
6549
|
+
mime: mimeType || "application/octet-stream",
|
|
6550
|
+
uri: contentUrl
|
|
6551
|
+
} : null;
|
|
6561
6552
|
return {
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
6569
|
-
mint: (p) => mintClient.mint(p),
|
|
6570
|
-
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
6553
|
+
name,
|
|
6554
|
+
description,
|
|
6555
|
+
image,
|
|
6556
|
+
animation_url,
|
|
6557
|
+
content,
|
|
6558
|
+
attributes
|
|
6571
6559
|
};
|
|
6572
|
-
}
|
|
6560
|
+
};
|
|
6573
6561
|
|
|
6574
6562
|
// src/ipfs/text-metadata.ts
|
|
6575
6563
|
var CHAR_LIMIT = 1111;
|