Skip to content

Commit

Permalink
refactor: rename Chains enum to Chain (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
crnkovic authored Oct 31, 2023
1 parent 807204a commit 6b20a3b
Show file tree
Hide file tree
Showing 76 changed files with 260 additions and 260 deletions.
18 changes: 9 additions & 9 deletions app/Console/Commands/LiveDumpNfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Collection as NftCollection;
use App\Models\Network;
use App\Models\Token;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function handle(): int
return Command::INVALID;
}

$chain = Chains::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));
$chain = Chain::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));

$topCollections = $this->getTopCollections($chain, self::COLLECTION_LIMIT);

Expand Down Expand Up @@ -133,7 +133,7 @@ public function handle(): int
return Command::SUCCESS;
}

private function prepareCollectionModel(Chains $chain, stdClass $collection): NftCollection
private function prepareCollectionModel(Chain $chain, stdClass $collection): NftCollection
{
$network = Network::firstWhere('chain_id', $chain->value);

Expand Down Expand Up @@ -161,7 +161,7 @@ private function prepareCollectionModel(Chains $chain, stdClass $collection): Nf
/**
* @return IlluminateCollection<int, array<string, mixed>> $collections
*/
private function getTopCollections(Chains $chain, int $limit = 25): IlluminateCollection
private function getTopCollections(Chain $chain, int $limit = 25): IlluminateCollection
{
$chainName = strtolower($chain->name);
$fileName = self::nftsSubDir."/top-{$chainName}-collections.json";
Expand Down Expand Up @@ -215,7 +215,7 @@ private function filterNftAttributes(array $nft): array

private function getCollectionNftsAndPersist(
NftCollection $collection,
Chains $chain,
Chain $chain,
int $itemsTotal,
int $chunk,
string $cursor = null,
Expand Down Expand Up @@ -250,7 +250,7 @@ private function getCollectionNftsAndPersist(
$progressBar->finish();
}

private function mergeNftChunks(Chains $chain, string $contractAddress): void
private function mergeNftChunks(Chain $chain, string $contractAddress): void
{
$fs = Storage::disk(self::diskName);

Expand All @@ -272,12 +272,12 @@ private function mergeNftChunks(Chains $chain, string $contractAddress): void
$this->info('Total NFTs count: '.count($nfts));
}

private function prepareCollectionPath(Chains $chain, string $contractAddress): string
private function prepareCollectionPath(Chain $chain, string $contractAddress): string
{
return self::nftsSubDir.'/'.Str::lower($chain->name).'_'.$contractAddress;
}

private function getTokenCursorForChunk(int $chunk, Chains $chain, string $contractAddress): ?string
private function getTokenCursorForChunk(int $chunk, Chain $chain, string $contractAddress): ?string
{
$path = $this->prepareCollectionPath($chain, $contractAddress);

Expand All @@ -294,7 +294,7 @@ private function getTokenCursorForChunk(int $chunk, Chains $chain, string $contr
return Arr::get($nftChunk, 'nextToken');
}

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

Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/LiveDumpWallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Contracts\Web3DataProvider;
use App\Data\Web3\Web3NftData;
use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Network;
use App\Models\User;
use App\Models\Wallet;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function handle(): int

$providers = [new AlchemyWeb3DataProvider(), new MoralisWeb3DataProvider()];

$chains = [Chains::ETH, Chains::Polygon];
$chains = [Chain::ETH, Chain::Polygon];

/** @var string[] */
$addresses = config('dashbrd.live_dump_wallets');
Expand Down Expand Up @@ -114,7 +114,7 @@ public function handle(): int
// Download traits for each collection
$allTraits = $nftCollections->mapWithKeys(function ($collectionAddresses, $chainId) {
$traits = $collectionAddresses->unique()
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getNftCollectionTraits(Chains::from($chainId), $collectionAddress)]);
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getNftCollectionTraits(Chain::from($chainId), $collectionAddress)]);

return [$chainId => $traits];
});
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SyncActivityPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Enums\TokenGuid;
use App\Models\Network;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function handle(): int
DB::beginTransaction();
$this->info('Updating NFT activity table...');

$network = Network::firstWhere('chain_id', Chains::Polygon);
$network = Network::firstWhere('chain_id', Chain::Polygon);
$ethereumGuid = TokenGuid::Ethereum->value;
$polygonGuid = TokenGuid::Polygon->value;

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SyncSpamContracts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Network;
use App\Models\SpamContract;
use App\Support\Facades\Alchemy;
Expand Down Expand Up @@ -33,7 +33,7 @@ class SyncSpamContracts extends Command
*/
public function handle(): int
{
$chain = Chains::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));
$chain = Chain::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));

/** @var Network $network */
$network = Network::query()->where('chain_id', $chain)->first();
Expand Down
4 changes: 2 additions & 2 deletions app/Contracts/Web3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Data\Web3\Web3Erc20TokenData;
use App\Data\Web3\Web3NftCollectionFloorPrice;
use App\Data\Web3\Web3NftsChunk;
use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Collection as CollectionModel;
use App\Models\Network;
use App\Models\Wallet;
Expand Down Expand Up @@ -38,5 +38,5 @@ public function getBlockTimestamp(Network $network, int $blockNumber): Carbon;
*/
public function getMiddleware(): array;

public function getNftCollectionFloorPrice(Chains $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
}
2 changes: 1 addition & 1 deletion app/Data/Collections/CollectionBasicDetailsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CollectionBasicDetailsData extends Data
{
public function __construct(
public string $slug,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Collections/CollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
public string $name,
public string $slug,
public string $address,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?string $floorPrice,
public ?float $floorPriceFiat,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Collections/CollectionDetailData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
public string $slug,
public ?string $description,
public string $address,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?string $floorPrice,
public ?string $floorPriceCurrency,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Gallery/GalleryCollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public string $name,
public string $slug,
public string $address,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?string $floorPrice,
public ?float $floorPriceFiat,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Network/NetworkWithCollectionsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
public int $id,
public string $name,
public bool $isMainnet,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public string $publicRpcProvider,
public string $explorerUrl,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Nfts/NftCollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
public string $slug,
public ?string $description,
public string $address,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?string $floorPrice,
public string $website,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Token/TokenData.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
public string $address,
public bool $isNativeToken,
public bool $isDefaultToken,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chainId,
public ?int $guid,
public string $name,
Expand Down
2 changes: 1 addition & 1 deletion app/Data/TokenListItemData.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
public bool $is_native_token,
public string $balance,
public int $decimals,
#[LiteralTypeScriptType('App.Enums.Chains')]
#[LiteralTypeScriptType('App.Enums.Chain')]
public int $chain_id,
public int $network_id,
public ?string $minted_supply,
Expand Down
8 changes: 4 additions & 4 deletions app/Enums/AlchemyChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ enum AlchemyChain: string
public static function fromChainId(int $chainId): self
{
$chain = match ($chainId) {
Chains::ETH->value => self::EthereumMainnet,
Chains::Goerli->value => self::EthereumTestnet,
Chains::Polygon->value => self::PolygonMainnet,
Chains::Mumbai->value => self::PolygonTestnet,
Chain::ETH->value => self::EthereumMainnet,
Chain::Goerli->value => self::EthereumTestnet,
Chain::Polygon->value => self::PolygonMainnet,
Chain::Mumbai->value => self::PolygonTestnet,
default => throw new \InvalidArgumentException(sprintf('Chain ID %d is not supported', $chainId)),
};

Expand Down
6 changes: 3 additions & 3 deletions app/Enums/Chains.php → app/Enums/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript]
enum Chains: int
enum Chain: int
{
case ETH = 1;
case Goerli = 5;
Expand All @@ -17,8 +17,8 @@ enum Chains: int
public function nativeCurrency(): string
{
return match ($this) {
Chains::ETH, Chains::Goerli => 'ETH',
Chains::Polygon, Chains::Mumbai => 'MATIC',
self::ETH, self::Goerli => 'ETH',
self::Polygon, self::Mumbai => 'MATIC',
};
}
}
10 changes: 5 additions & 5 deletions app/Enums/CoingeckoPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ enum CoingeckoPlatform: string
case Ethereum = 'ethereum';
case Polygon = 'polygon-pos';

public function toChain(): Chains
public function toChain(): Chain
{
return match ($this) {
CoingeckoPlatform::Ethereum => Chains::ETH,
CoingeckoPlatform::Polygon => Chains::Polygon,
CoingeckoPlatform::Ethereum => Chain::ETH,
CoingeckoPlatform::Polygon => Chain::Polygon,
};
}

public static function tryFromChainId(int $chainId): ?CoingeckoPlatform
{
return match ($chainId) {
Chains::ETH->value => CoingeckoPlatform::Ethereum,
Chains::Polygon->value => CoingeckoPlatform::Polygon,
Chain::ETH->value => CoingeckoPlatform::Ethereum,
Chain::Polygon->value => CoingeckoPlatform::Polygon,
default => null,
};
}
Expand Down
6 changes: 3 additions & 3 deletions app/Enums/MnemonicChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ enum MnemonicChain: string
case Ethereum = 'ethereum';
case Polygon = 'polygon';

public static function fromChain(Chains $chain): self
public static function fromChain(Chain $chain): self
{
return match ($chain) {
Chains::ETH => self::Ethereum,
Chains::Polygon => self::Polygon,
Chain::ETH => self::Ethereum,
Chain::Polygon => self::Polygon,
default => throw new \InvalidArgumentException(sprintf('Chain ID %d is not supported', $chain->name)),
};
}
Expand Down
8 changes: 4 additions & 4 deletions app/Enums/MoralisChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ enum MoralisChain: string
public static function fromChainId(int $chainId): self
{
return match ($chainId) {
Chains::ETH->value => self::ETH,
Chains::Goerli->value => self::Goerli,
Chains::Polygon->value => self::Polygon,
Chains::Mumbai->value => self::Mumbai,
Chain::ETH->value => self::ETH,
Chain::Goerli->value => self::Goerli,
Chain::Polygon->value => self::Polygon,
Chain::Mumbai->value => self::Mumbai,
default => throw new \InvalidArgumentException(sprintf('Chain ID %d is not supported', $chainId)),
};
}
Expand Down
8 changes: 4 additions & 4 deletions app/Enums/OpenseaChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ enum OpenseaChain: string
public static function fromChainId(int $chainId): self
{
return match ($chainId) {
Chains::ETH->value => self::ETH,
Chains::Goerli->value => self::Goerli,
Chains::Polygon->value => self::Polygon,
Chains::Mumbai->value => self::Mumbai,
Chain::ETH->value => self::ETH,
Chain::Goerli->value => self::Goerli,
Chain::Polygon->value => self::Polygon,
Chain::Mumbai->value => self::Mumbai,
default => throw new \InvalidArgumentException(sprintf('Chain ID %d is not supported', $chainId)),
};
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Client/Alchemy/AlchemyPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Data\Web3\Web3NftData;
use App\Data\Web3\Web3NftsChunk;
use App\Enums\AlchemyChain;
use App\Enums\Chains;
use App\Enums\Chain;
use App\Enums\CryptoCurrencyDecimals;
use App\Enums\ImageSize;
use App\Enums\NftInfo;
Expand Down Expand Up @@ -485,7 +485,7 @@ private function tokenMetadata(string $tokenAddress): ?array
}

// https://docs.alchemy.com/reference/getfloorprice
public function getNftCollectionFloorPrice(Chains $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
// Only ETH is supported at the moment since this API is still considered in beta:

Expand All @@ -494,7 +494,7 @@ public function getNftCollectionFloorPrice(Chains $chain, string $contractAddres
// Polygon X X
// Optimism X X
// Arbitrum X X
if ($chain !== Chains::ETH) {
if ($chain !== Chain::ETH) {
return null;
}

Expand Down
Loading

0 comments on commit 6b20a3b

Please sign in to comment.