@zoralabs/coins-sdk 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/actions/createCoin.d.ts +1 -0
- package/dist/actions/createCoin.d.ts.map +1 -1
- package/dist/actions/getOnchainCoinDetails.d.ts +0 -20
- package/dist/actions/getOnchainCoinDetails.d.ts.map +1 -1
- package/dist/actions/tradeCoin.d.ts +1 -1
- package/dist/actions/tradeCoin.d.ts.map +1 -1
- package/dist/api/explore.d.ts +2 -0
- package/dist/api/explore.d.ts.map +1 -1
- package/dist/client/sdk.gen.d.ts +30 -0
- package/dist/client/sdk.gen.d.ts.map +1 -1
- package/dist/client/types.gen.d.ts +67 -1
- package/dist/client/types.gen.d.ts.map +1 -1
- package/dist/index.cjs +47 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -139
- package/dist/index.js.map +1 -1
- package/dist/utils/getChainFromId.d.ts +3 -0
- package/dist/utils/getChainFromId.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/actions/createCoin.ts +2 -0
- package/src/actions/getOnchainCoinDetails.ts +9 -177
- package/src/actions/tradeCoin.ts +16 -5
- package/src/api/explore.ts +12 -0
- package/src/client/types.gen.ts +69 -1
- package/src/utils/getChainFromId.ts +12 -0
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,6 @@ var _chains = require('viem/chains');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
var COIN_FACTORY_ADDRESS = _protocoldeployments.coinFactoryAddress["8453"];
|
|
15
|
-
var SUPERCHAIN_WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
16
15
|
var USDC_WETH_POOLS_BY_CHAIN = {
|
|
17
16
|
[_chains.base.id]: "0xd0b53D9277642d899DF5C87A3966A349A798F224"
|
|
18
17
|
};
|
|
@@ -215,6 +214,18 @@ var getPrepurchaseHook = async ({
|
|
|
215
214
|
});
|
|
216
215
|
};
|
|
217
216
|
|
|
217
|
+
// src/utils/getChainFromId.ts
|
|
218
|
+
|
|
219
|
+
function getChainFromId(chainId) {
|
|
220
|
+
if (chainId === _chains.base.id) {
|
|
221
|
+
return _chains.base;
|
|
222
|
+
}
|
|
223
|
+
if (chainId === _chains.baseSepolia.id) {
|
|
224
|
+
return _chains.baseSepolia;
|
|
225
|
+
}
|
|
226
|
+
throw new Error(`Chain ID ${chainId} not supported`);
|
|
227
|
+
}
|
|
228
|
+
|
|
218
229
|
// src/actions/createCoin.ts
|
|
219
230
|
var DeployCurrency = /* @__PURE__ */ ((DeployCurrency2) => {
|
|
220
231
|
DeployCurrency2[DeployCurrency2["ZORA"] = 1] = "ZORA";
|
|
@@ -314,154 +325,47 @@ async function createCoin(call, walletClient, publicClient, options) {
|
|
|
314
325
|
hash,
|
|
315
326
|
receipt,
|
|
316
327
|
address: _optionalChain([deployment, 'optionalAccess', _8 => _8.coin]),
|
|
317
|
-
deployment
|
|
328
|
+
deployment,
|
|
329
|
+
chain: getChainFromId(publicClient.chain.id)
|
|
318
330
|
};
|
|
319
331
|
}
|
|
320
332
|
|
|
321
333
|
// src/actions/getOnchainCoinDetails.ts
|
|
322
334
|
|
|
323
335
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
336
|
async function getOnchainCoinDetails({
|
|
330
337
|
coin,
|
|
331
338
|
user = _viem.zeroAddress,
|
|
332
339
|
publicClient
|
|
333
340
|
}) {
|
|
334
341
|
validateClientNetwork(publicClient);
|
|
335
|
-
const [balance,
|
|
336
|
-
{
|
|
337
|
-
contracts: [
|
|
338
|
-
{
|
|
339
|
-
address: coin,
|
|
340
|
-
abi: _protocoldeployments.coinABI,
|
|
341
|
-
functionName: "balanceOf",
|
|
342
|
-
args: [user]
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
address: coin,
|
|
346
|
-
abi: _protocoldeployments.coinABI,
|
|
347
|
-
functionName: "poolAddress"
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
address: coin,
|
|
351
|
-
abi: _protocoldeployments.coinABI,
|
|
352
|
-
functionName: "owners"
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
address: coin,
|
|
356
|
-
abi: _protocoldeployments.coinABI,
|
|
357
|
-
functionName: "payoutRecipient"
|
|
358
|
-
}
|
|
359
|
-
],
|
|
360
|
-
allowFailure: false
|
|
361
|
-
}
|
|
362
|
-
);
|
|
363
|
-
const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[_optionalChain([publicClient, 'access', _9 => _9.chain, 'optionalAccess', _10 => _10.id]) || 0];
|
|
364
|
-
const [
|
|
365
|
-
coinWethPoolSlot0,
|
|
366
|
-
coinWethPoolToken0,
|
|
367
|
-
coinReservesRaw,
|
|
368
|
-
coinTotalSupply,
|
|
369
|
-
wethReservesRaw,
|
|
370
|
-
usdcWethSlot0
|
|
371
|
-
] = await publicClient.multicall({
|
|
342
|
+
const [balance, owners, payoutRecipient] = await publicClient.multicall({
|
|
372
343
|
contracts: [
|
|
373
|
-
{
|
|
374
|
-
address: pool,
|
|
375
|
-
abi: _protocoldeployments.iUniswapV3PoolABI,
|
|
376
|
-
functionName: "slot0"
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
address: pool,
|
|
380
|
-
abi: _protocoldeployments.iUniswapV3PoolABI,
|
|
381
|
-
functionName: "token0"
|
|
382
|
-
},
|
|
383
344
|
{
|
|
384
345
|
address: coin,
|
|
385
|
-
abi:
|
|
346
|
+
abi: _protocoldeployments.coinABI,
|
|
386
347
|
functionName: "balanceOf",
|
|
387
|
-
args: [
|
|
348
|
+
args: [user]
|
|
388
349
|
},
|
|
389
350
|
{
|
|
390
351
|
address: coin,
|
|
391
352
|
abi: _protocoldeployments.coinABI,
|
|
392
|
-
functionName: "
|
|
353
|
+
functionName: "owners"
|
|
393
354
|
},
|
|
394
355
|
{
|
|
395
|
-
address:
|
|
396
|
-
abi:
|
|
397
|
-
functionName: "
|
|
398
|
-
args: [pool]
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
address: _nullishCoalesce(USDC_WETH_POOL, () => ( coin)),
|
|
402
|
-
abi: _protocoldeployments.iUniswapV3PoolABI,
|
|
403
|
-
functionName: "slot0"
|
|
356
|
+
address: coin,
|
|
357
|
+
abi: _protocoldeployments.coinABI,
|
|
358
|
+
functionName: "payoutRecipient"
|
|
404
359
|
}
|
|
405
360
|
],
|
|
406
361
|
allowFailure: false
|
|
407
362
|
});
|
|
408
|
-
const wethPriceInUsdc = USDC_WETH_POOL ? uniswapV3SqrtPriceToBigIntScaled(
|
|
409
|
-
usdcWethSlot0.sqrtPriceX96,
|
|
410
|
-
18,
|
|
411
|
-
6,
|
|
412
|
-
true,
|
|
413
|
-
18
|
|
414
|
-
) : null;
|
|
415
|
-
const coinPriceInWeth = uniswapV3SqrtPriceToBigIntScaled(
|
|
416
|
-
coinWethPoolSlot0.sqrtPriceX96,
|
|
417
|
-
18,
|
|
418
|
-
18,
|
|
419
|
-
_viem.isAddressEqual.call(void 0, coinWethPoolToken0, coin),
|
|
420
|
-
18
|
|
421
|
-
);
|
|
422
|
-
const marketCap = coinPriceInWeth * coinTotalSupply / 10n ** 18n;
|
|
423
|
-
const wethLiquidity = wethReservesRaw;
|
|
424
|
-
const tokenLiquidity = coinReservesRaw * coinPriceInWeth / 10n ** 18n;
|
|
425
363
|
return {
|
|
426
364
|
balance,
|
|
427
|
-
pool,
|
|
428
365
|
owners,
|
|
429
|
-
payoutRecipient
|
|
430
|
-
marketCap: convertEthOutput(marketCap, wethPriceInUsdc),
|
|
431
|
-
liquidity: convertEthOutput(
|
|
432
|
-
wethLiquidity + tokenLiquidity,
|
|
433
|
-
wethPriceInUsdc
|
|
434
|
-
),
|
|
435
|
-
poolState: coinWethPoolSlot0
|
|
366
|
+
payoutRecipient
|
|
436
367
|
};
|
|
437
368
|
}
|
|
438
|
-
function convertEthOutput(amountETH, wethToUsdc) {
|
|
439
|
-
return {
|
|
440
|
-
eth: amountETH,
|
|
441
|
-
ethDecimal: parseFloat(_viem.formatEther.call(void 0, amountETH)),
|
|
442
|
-
usdc: wethToUsdc ? amountETH * wethToUsdc : null,
|
|
443
|
-
usdcDecimal: wethToUsdc ? parseFloat(_viem.formatEther.call(void 0, amountETH * wethToUsdc / 10n ** 18n)) : null
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
function uniswapV3SqrtPriceToBigIntScaled(sqrtPriceX96, token0Decimals, token1Decimals, isToken0Coin, scaleDecimals = 18) {
|
|
447
|
-
const numerator = sqrtPriceX96 * sqrtPriceX96;
|
|
448
|
-
const denominator = 2n ** 192n;
|
|
449
|
-
const scaleFactor = 10n ** BigInt(scaleDecimals);
|
|
450
|
-
let ratioScaled = numerator * scaleFactor / denominator;
|
|
451
|
-
const decimalsDiff = BigInt(token0Decimals - token1Decimals);
|
|
452
|
-
if (decimalsDiff > 0n) {
|
|
453
|
-
ratioScaled *= 10n ** decimalsDiff;
|
|
454
|
-
} else if (decimalsDiff < 0n) {
|
|
455
|
-
ratioScaled /= 10n ** -decimalsDiff;
|
|
456
|
-
}
|
|
457
|
-
if (!isToken0Coin) {
|
|
458
|
-
if (ratioScaled === 0n) {
|
|
459
|
-
return 0n;
|
|
460
|
-
}
|
|
461
|
-
ratioScaled = scaleFactor * scaleFactor / ratioScaled;
|
|
462
|
-
}
|
|
463
|
-
return ratioScaled;
|
|
464
|
-
}
|
|
465
369
|
|
|
466
370
|
// src/actions/updateCoinURI.ts
|
|
467
371
|
|
|
@@ -589,7 +493,7 @@ var getCoins = (options) => {
|
|
|
589
493
|
});
|
|
590
494
|
};
|
|
591
495
|
var setCreateUploadJwt = (options) => {
|
|
592
|
-
return (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
496
|
+
return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.client]), () => ( client))).post({
|
|
593
497
|
security: [
|
|
594
498
|
{
|
|
595
499
|
name: "api-key",
|
|
@@ -600,7 +504,7 @@ var setCreateUploadJwt = (options) => {
|
|
|
600
504
|
...options,
|
|
601
505
|
headers: {
|
|
602
506
|
"Content-Type": "application/json",
|
|
603
|
-
..._optionalChain([options, 'optionalAccess',
|
|
507
|
+
..._optionalChain([options, 'optionalAccess', _10 => _10.headers])
|
|
604
508
|
}
|
|
605
509
|
});
|
|
606
510
|
};
|
|
@@ -653,7 +557,7 @@ var getProfileCoins = (options) => {
|
|
|
653
557
|
});
|
|
654
558
|
};
|
|
655
559
|
var postQuote = (options) => {
|
|
656
|
-
return (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
560
|
+
return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.client]), () => ( client))).post({
|
|
657
561
|
security: [
|
|
658
562
|
{
|
|
659
563
|
name: "api-key",
|
|
@@ -664,7 +568,7 @@ var postQuote = (options) => {
|
|
|
664
568
|
...options,
|
|
665
569
|
headers: {
|
|
666
570
|
"Content-Type": "application/json",
|
|
667
|
-
..._optionalChain([options, 'optionalAccess',
|
|
571
|
+
..._optionalChain([options, 'optionalAccess', _12 => _12.headers])
|
|
668
572
|
}
|
|
669
573
|
});
|
|
670
574
|
};
|
|
@@ -701,8 +605,14 @@ async function tradeCoin({
|
|
|
701
605
|
validateTransaction = true
|
|
702
606
|
}) {
|
|
703
607
|
const quote = await createTradeCall(tradeParameters);
|
|
608
|
+
if (!account) {
|
|
609
|
+
account = walletClient.account;
|
|
610
|
+
}
|
|
611
|
+
if (!account) {
|
|
612
|
+
throw new Error("Account is required");
|
|
613
|
+
}
|
|
704
614
|
if (!tradeParameters.recipient) {
|
|
705
|
-
tradeParameters.recipient = account.address;
|
|
615
|
+
tradeParameters.recipient = typeof account === "string" ? account : account.address;
|
|
706
616
|
}
|
|
707
617
|
const signatures = [];
|
|
708
618
|
if (quote.permits) {
|
|
@@ -713,7 +623,7 @@ async function tradeCoin({
|
|
|
713
623
|
functionName: "allowance",
|
|
714
624
|
args: [
|
|
715
625
|
permit.permit.details.token,
|
|
716
|
-
account.address,
|
|
626
|
+
typeof account === "string" ? account : account.address,
|
|
717
627
|
permit.permit.spender
|
|
718
628
|
]
|
|
719
629
|
});
|
|
@@ -722,7 +632,10 @@ async function tradeCoin({
|
|
|
722
632
|
abi: _viem.erc20Abi,
|
|
723
633
|
address: permitToken,
|
|
724
634
|
functionName: "allowance",
|
|
725
|
-
args: [
|
|
635
|
+
args: [
|
|
636
|
+
typeof account === "string" ? account : account.address,
|
|
637
|
+
_protocoldeployments.permit2Address[_chains.base.id]
|
|
638
|
+
]
|
|
726
639
|
});
|
|
727
640
|
if (allowance < BigInt(permit.permit.details.amount)) {
|
|
728
641
|
const approvalTx = await walletClient.writeContract({
|
|
@@ -756,7 +669,7 @@ async function tradeCoin({
|
|
|
756
669
|
primaryType: "PermitSingle",
|
|
757
670
|
types: PERMIT_SINGLE_TYPES,
|
|
758
671
|
message,
|
|
759
|
-
account
|
|
672
|
+
account: typeof account === "string" ? account : account.address
|
|
760
673
|
});
|
|
761
674
|
signatures.push({
|
|
762
675
|
signature,
|
|
@@ -893,6 +806,8 @@ var getCoinsMostValuable = (query = {}, options) => createExploreQuery(query, "M
|
|
|
893
806
|
var getCoinsNew = (query = {}, options) => createExploreQuery(query, "NEW", options);
|
|
894
807
|
var getCoinsLastTraded = (query = {}, options) => createExploreQuery(query, "LAST_TRADED", options);
|
|
895
808
|
var getCoinsLastTradedUnique = (query = {}, options) => createExploreQuery(query, "LAST_TRADED_UNIQUE", options);
|
|
809
|
+
var getCreatorCoins = (query = {}, options) => createExploreQuery(query, "NEW_CREATORS", options);
|
|
810
|
+
var getMostValuableCreatorCoins = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE_CREATORS", options);
|
|
896
811
|
|
|
897
812
|
// src/uploader/metadata.ts
|
|
898
813
|
function validateImageMimeType(mimeType) {
|
|
@@ -1009,9 +924,9 @@ var CoinMetadataBuilder = class {
|
|
|
1009
924
|
symbol: this.symbol,
|
|
1010
925
|
description: this.description,
|
|
1011
926
|
image: this.imageURL.toString(),
|
|
1012
|
-
animation_url: _optionalChain([this, 'access',
|
|
927
|
+
animation_url: _optionalChain([this, 'access', _13 => _13.mediaURL, 'optionalAccess', _14 => _14.toString, 'call', _15 => _15()]),
|
|
1013
928
|
content: this.mediaURL ? {
|
|
1014
|
-
uri: _optionalChain([this, 'access',
|
|
929
|
+
uri: _optionalChain([this, 'access', _16 => _16.mediaURL, 'optionalAccess', _17 => _17.toString, 'call', _18 => _18()]),
|
|
1015
930
|
mime: this.mediaMimeType
|
|
1016
931
|
} : void 0,
|
|
1017
932
|
properties: this.properties
|
|
@@ -1073,7 +988,7 @@ var ZoraUploader = class {
|
|
|
1073
988
|
const response = await setCreateUploadJwt2({
|
|
1074
989
|
creatorAddress: this.creatorAddress
|
|
1075
990
|
});
|
|
1076
|
-
this.jwtApiKey = _optionalChain([response, 'access',
|
|
991
|
+
this.jwtApiKey = _optionalChain([response, 'access', _19 => _19.data, 'optionalAccess', _20 => _20.createUploadJwtFromApiKey]);
|
|
1077
992
|
if (!this.jwtApiKey) {
|
|
1078
993
|
throw new Error("Failed to create upload JWT");
|
|
1079
994
|
}
|
|
@@ -1144,5 +1059,7 @@ function createZoraUploaderForCreator(creatorAddress) {
|
|
|
1144
1059
|
|
|
1145
1060
|
|
|
1146
1061
|
|
|
1147
|
-
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
exports.CoinMetadataBuilder = CoinMetadataBuilder; exports.DeployCurrency = DeployCurrency; exports.InitialPurchaseCurrency = InitialPurchaseCurrency; exports.ZoraUploader = ZoraUploader; exports.cleanAndValidateMetadataURI = cleanAndValidateMetadataURI; exports.createCoin = createCoin; exports.createCoinCall = createCoinCall; exports.createMetadataBuilder = createMetadataBuilder; exports.createTradeCall = createTradeCall; exports.createZoraUploaderForCreator = createZoraUploaderForCreator; exports.getCoin = getCoin2; exports.getCoinComments = getCoinComments2; exports.getCoinCreateFromLogs = getCoinCreateFromLogs; exports.getCoins = getCoins2; exports.getCoinsLastTraded = getCoinsLastTraded; exports.getCoinsLastTradedUnique = getCoinsLastTradedUnique; exports.getCoinsMostValuable = getCoinsMostValuable; exports.getCoinsNew = getCoinsNew; exports.getCoinsTopGainers = getCoinsTopGainers; exports.getCoinsTopVolume24h = getCoinsTopVolume24h; exports.getCreatorCoins = getCreatorCoins; exports.getMostValuableCreatorCoins = getMostValuableCreatorCoins; exports.getOnchainCoinDetails = getOnchainCoinDetails; exports.getProfile = getProfile2; exports.getProfileBalances = getProfileBalances2; exports.getProfileCoins = getProfileCoins2; exports.getURLFromUploadResult = getURLFromUploadResult; exports.setApiKey = setApiKey; exports.tradeCoin = tradeCoin; exports.updateCoinURI = updateCoinURI; exports.updateCoinURICall = updateCoinURICall; exports.updatePayoutRecipient = updatePayoutRecipient; exports.updatePayoutRecipientCall = updatePayoutRecipientCall; exports.validateImageMimeType = validateImageMimeType; exports.validateMetadataJSON = validateMetadataJSON; exports.validateMetadataURIContent = validateMetadataURIContent;
|
|
1148
1065
|
//# sourceMappingURL=index.cjs.map
|