Skip to content

Commit

Permalink
chore: merge rc into main (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo authored Mar 18, 2024
2 parents f9cf9fb + 9537152 commit 30e8dad
Show file tree
Hide file tree
Showing 187 changed files with 4,280 additions and 4,297 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ module.exports = {
"unicorn/prefer-string-slice": "error",
"unicorn/prefer-ternary": "off", // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md
"unicorn/prefer-top-level-await": "error",
"unicorn/prevent-abbreviations": [
"error",
{
ignore: ["i18n"],
},
],
},
overrides: [
{
Expand Down
68 changes: 68 additions & 0 deletions app/Console/Commands/CalculateCollectionTraitRarities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Jobs\CalculateTraitRaritiesForCollection;
use App\Models\Collection;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus;

class CalculateCollectionTraitRarities extends Command
{
use InteractsWithCollections;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'collections:calculate-trait-rarities {--start=} {--limit=} {--collection-id=}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Calculate the trait rarities for collections';

/**
* Execute the console command.
*/
public function handle(): int
{
$start = $this->option('start');
$limit = $this->option('limit');

if ($start !== null) {
$collections = Collection::query()
->withAcceptableSupply()
->select('collections.*')
->withoutSpamContracts()
->where('id', '>=', (int) $start)
->when($limit !== null, fn ($q) => $q->limit((int) $limit))
->orderBy('id', 'asc')
->get();

$first = $collections->first();
$last = $collections->last();

Bus::batch($collections->mapInto(CalculateTraitRaritiesForCollection::class))
->name('Calculating rarities for collection IDs '.$first->id.' to '.$last->id)
->dispatch();

$this->info('Starting from ID: '.$first->id.' to ID '.$last->id.' collections (inclusive). Total: '.$collections->count());

return Command::SUCCESS;
}

$queryCallback = fn ($query) => $query->withAcceptableSupply();

$this->forEachCollection(function ($collection) {
CalculateTraitRaritiesForCollection::dispatch($collection);
}, $queryCallback);

return Command::SUCCESS;
}
}
5 changes: 2 additions & 3 deletions app/Console/Commands/FetchCollectionOpenseaSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FetchCollectionOpenseaSlug extends Command
*
* @var string
*/
protected $description = 'Fetch the opensea slug for collections';
protected $description = 'Fetch the OpenSea slug for collections';

/**
* Execute the console command.
Expand All @@ -33,6 +33,7 @@ public function handle(): int
// Job runs every 5 minutes
$limit = $this->getLimitPerMinutes(5);

// We only care about collections that don't have a slug yet, so in most cases it will not run any request...
$this->forEachCollection(
callback: function ($collection, $index) {
$this->dispatchDelayed(
Expand All @@ -43,9 +44,7 @@ public function handle(): int
},
queryCallback: fn ($query) => $query
->orderByOpenseaSlugLastFetchedAt()
// Does not have an opensea slug
->whereNull('extra_attributes->opensea_slug')
// Has not been fetched
->whereNull('extra_attributes->opensea_slug_last_fetched_at'),
limit: $limit
);
Expand Down
39 changes: 0 additions & 39 deletions app/Console/Commands/FetchCollectionTraits.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Console/Commands/InteractsWithCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function forEachCollection(Closure $callback, ?Closure $queryCallback = n
->select('collections.*')
->where('collections.id', '=', $this->option('collection-id'))
->withoutSpamContracts()
->erc721()
->first();

$collection && $callback($collection, 0);
Expand All @@ -35,7 +34,6 @@ public function forEachCollection(Closure $callback, ?Closure $queryCallback = n
->when($queryCallback !== null, $queryCallback)
->select('collections.*')
->withoutSpamContracts()
->erc721()
->when($limit !== null, fn ($query) => $query
->limit($limit)
->get()
Expand Down
20 changes: 0 additions & 20 deletions app/Console/Commands/LiveDumpNfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Models\Network;
use App\Models\Token;
use App\Support\Facades\Alchemy;
use App\Support\Facades\Mnemonic;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -127,8 +126,6 @@ public function handle(): int

$this->mergeNftChunks($chain, $contractAddress);

$this->getCollectionTraitsAndPersist($chain, $contractAddress);

return Command::SUCCESS;
}

Expand Down Expand Up @@ -287,23 +284,6 @@ private function getTokenCursorForChunk(int $chunk, Chain $chain, string $contra
return Arr::get($nftChunk, 'pageKey');
}

private function getCollectionTraitsAndPersist(Chain $chain, string $address): void
{
$this->info('Fetching collection traits...');

$fs = Storage::disk(self::diskName);

$traits = Mnemonic::getCollectionTraits($chain, $address);

$path = $this->prepareCollectionPath($chain, $address);

$fileName = $path.'/traits.json';

$fs->put($fileName, (string) json_encode($traits, JSON_PRETTY_PRINT));

$this->info('Fetched collection traits, file: '.$fileName);
}

/**
* @param array<mixed> $data
* @param array<mixed> $attributes
Expand Down
11 changes: 0 additions & 11 deletions app/Console/Commands/LiveDumpWallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ public function handle(): int
}
}

// Download traits for each collection
$allTraits = $nftCollections->mapWithKeys(function ($collectionAddresses, $chainId) {
$traits = $collectionAddresses->unique()
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getCollectionTraits(Chain::from($chainId), $collectionAddress)]);

return [$chainId => $traits];
});

$fs->put('mnemonic_nft_collection_traits.json', (string) json_encode($allTraits, JSON_PRETTY_PRINT));
$progressBar->advance();

$progressBar->finish();

return Command::SUCCESS;
Expand Down
7 changes: 0 additions & 7 deletions app/Console/Commands/UpdateCollectionsFiatValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Console\Commands;

use App\Models\Collection;
use App\Models\User;
use App\Support\Queues;
use Illuminate\Console\Command;
use Illuminate\Support\Collection as EloquentCollection;
Expand All @@ -31,12 +30,6 @@ class UpdateCollectionsFiatValue extends Command
*/
public function handle(): int
{
User::query()->select('id')->chunkById(50, function (EloquentCollection $users) {
dispatch(function () use ($users) {
User::updateCollectionsValue($users->pluck('id')->toArray());
})->onQueue(Queues::SCHEDULED_DEFAULT);
});

Collection::query()->select('id')->chunkById(50, function (EloquentCollection $collections) {
dispatch(function () use ($collections) {
Collection::updateFiatValue($collections->pluck('id')->toArray());
Expand Down
8 changes: 0 additions & 8 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ protected function schedule(Schedule $schedule): void

private function scheduleJobsForCollectionsOrGalleries(Schedule $schedule): void
{
$schedule
// Command only fetches collections that don't have a slug yet
// so in most cases it will not run any request
->command(FetchCollectionOpenseaSlug::class)
->withoutOverlapping()
->hourly();

$schedule
->command(FetchCollectionTotalVolume::class)
->withoutOverlapping()
Expand Down Expand Up @@ -151,7 +144,6 @@ private function scheduleJobsForCollectionsOrGalleries(Schedule $schedule): void
->command(FetchCollectionOpenseaSlug::class)
->withoutOverlapping()
->everyFiveMinutes();

}

private function scheduleJobsForGalleries(Schedule $schedule): void
Expand Down
12 changes: 3 additions & 9 deletions app/Data/Collections/CollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace App\Data\Collections;

use App\Data\FloorPriceData;
use App\Data\VolumeData;
use App\Enums\CurrencyCode;
use App\Enums\Period;
use App\Models\Collection;
use App\Transformers\IpfsGatewayUrlTransformer;
use Illuminate\Support\Str;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\WithTransformer;
use Spatie\LaravelData\Data;
Expand All @@ -30,10 +30,7 @@ public function __construct(
public string $address,
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?string $floorPrice,
public ?float $floorPriceFiat,
public ?string $floorPriceCurrency,
public ?int $floorPriceDecimals,
public FloorPriceData $floorPrice,
public ?int $supply,
#[WithTransformer(IpfsGatewayUrlTransformer::class)]
public ?string $image,
Expand Down Expand Up @@ -62,10 +59,7 @@ public static function fromModel(Collection $collection, CurrencyCode $currency,
slug: $collection->slug,
address: $collection->address,
chainId: $collection->network->chain_id,
floorPrice: $collection->floor_price,
floorPriceFiat: (float) $collection->fiatValue($currency),
floorPriceCurrency: $collection->floorPriceToken ? Str::lower($collection->floorPriceToken->symbol) : null,
floorPriceDecimals: $collection->floorPriceToken?->decimals,
floorPrice: $collection->createFloorPriceData($currency),
supply: $collection->supply,
image: $collection->extra_attributes->get('image'),
banner: $collection->extra_attributes->get('banner'),
Expand Down
5 changes: 3 additions & 2 deletions app/Data/Collections/CollectionFeaturedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Data\Collections;

use App\Data\Gallery\GalleryNftData;
use App\Data\VolumeData;
use App\Enums\CurrencyCode;
use App\Models\Collection;
use App\Transformers\IpfsGatewayUrlTransformer;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function __construct(
public DataCollection $nfts,
public bool $isFeatured,
public ?string $description,
public ?string $volume,
public VolumeData $volume,
) {
}

Expand Down Expand Up @@ -72,7 +73,7 @@ public static function fromModel(Collection $collection, CurrencyCode $currency)
supply: $collection->supply,
isFeatured: $collection->is_featured,
description: $description,
volume: $collection->volume,
volume: $collection->createVolumeData(period: null, currency: $currency),
);
}
}
3 changes: 0 additions & 3 deletions app/Data/Collections/CollectionTraitData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'/** Use the displayType to infer the actual type. */ value' => 'string | number',
'/** Only present for numeric displayTypes. */ valueMin' => '?number',
'/** Only present for numeric displayTypes. */ valueMax' => '?number',
'nftsCount' => 'number',
'nftsPercentage' => 'number',
])]
class CollectionTraitData extends Data
Expand All @@ -27,7 +26,6 @@ public function __construct(
public string|float $value,
public ?float $valueMin,
public ?float $valueMax,
public float $nftsCount,
public float $nftsPercentage,
) {
}
Expand All @@ -40,7 +38,6 @@ public static function fromModel(CollectionTrait $trait): self
value: self::extractValue($trait),
valueMin: $trait['value_min'] ?? null,
valueMax: $trait['value_max'] ?? null,
nftsCount: $trait['nfts_count'],
nftsPercentage: $trait['nfts_percentage'],
);
}
Expand Down
Loading

0 comments on commit 30e8dad

Please sign in to comment.