Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename getNftCollection* methods to getCollection* #604

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Commands/LiveDumpNfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private function getCollectionTraitsAndPersist(Chain $chain, string $address): v

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/LiveDumpWallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function handle(): int

$collectionFloorPrices = $collectionAddresses
->mapWithKeys(fn (string $collectionAddress
) => [$collectionAddress => Mnemonic::getNftCollectionFloorPrice($chain, $collectionAddress)]);
) => [$collectionAddress => Mnemonic::getCollectionFloorPrice($chain, $collectionAddress)]);

// modify `network` and `retrievedAt` to make output stable between reruns as these change independent
// of the API response.
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(Chain::from($chainId), $collectionAddress)]);
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getCollectionTraits(Chain::from($chainId), $collectionAddress)]);

return [$chainId => $traits];
});
Expand Down
2 changes: 1 addition & 1 deletion app/Contracts/Web3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public function getBlockTimestamp(Network $network, int $blockNumber): Carbon;
*/
public function getMiddleware(): array;

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
}
2 changes: 1 addition & 1 deletion app/Http/Client/Alchemy/AlchemyPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private function tokenMetadata(string $tokenAddress): ?array
}

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

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Client/Mnemonic/MnemonicPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function send(string $method, string $path, array $options = []): Respons
}

// https://docs.mnemonichq.com/reference/marketplacesservice_getfloorprice
public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
$this->chain = MnemonicChain::fromChain($chain);

Expand Down Expand Up @@ -180,7 +180,7 @@ public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress
}

// https://docs.mnemonichq.com/reference/collectionsservice_getmetadata
public function getNftCollectionBanner(Chain $chain, string $contractAddress): ?string
public function getCollectionBanner(Chain $chain, string $contractAddress): ?string
{
$this->chain = MnemonicChain::fromChain($chain);

Expand Down Expand Up @@ -215,7 +215,7 @@ public function getNftCollectionBanner(Chain $chain, string $contractAddress): ?
}

// https://docs.mnemonichq.com/reference/collectionsservice_getownerscount
public function getNftCollectionOwners(Chain $chain, string $contractAddress): ?int
public function getCollectionOwners(Chain $chain, string $contractAddress): ?int
{
$this->chain = MnemonicChain::fromChain($chain);

Expand All @@ -232,7 +232,7 @@ public function getNftCollectionOwners(Chain $chain, string $contractAddress): ?
}

// https://docs.mnemonichq.com/reference/collectionsservice_getsalesvolume
public function getNftCollectionVolume(Chain $chain, string $contractAddress): ?string
public function getCollectionVolume(Chain $chain, string $contractAddress): ?string
{
$this->chain = MnemonicChain::fromChain($chain);

Expand All @@ -258,7 +258,7 @@ public function getNftCollectionVolume(Chain $chain, string $contractAddress): ?
/**
* @return Collection<int, Web3NftCollectionTrait>
*/
public function getNftCollectionTraits(Chain $chain, string $contractAddress): Collection
public function getCollectionTraits(Chain $chain, string $contractAddress): Collection
{
// {
// "name": "string",
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Client/Moralis/MoralisPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getNativeBalances(array $walletAddresses, Network $network): Col
* @see https://docs.moralis.io/web3-data-api/evm/reference/get-nft-lowest-price
* Get the lowest executed price for an NFT contract for the last x days (only trades paid in ETH).
*/
public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
try {
$data = self::get(sprintf('nft/%s/lowestprice', $contractAddress), [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Client/Opensea/OpenseaPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function nft(Chain $chain, string $address, string $identifier): ?Opensea
/**
* @see https://docs.opensea.io/v1.0/reference/retrieving-collection-stats
*/
public function getNftCollectionFloorPrice(string $collectionSlug): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(string $collectionSlug): ?Web3NftCollectionFloorPrice
{
try {
$response = $this->makeCollectionStatsRequest($collectionSlug);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchCollectionBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function handle(): void
'collection' => $this->collection->address,
]);

$banner = Mnemonic::getNftCollectionBanner(
$banner = Mnemonic::getCollectionBanner(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchCollectionFloorPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(): void
$collection->save();

$web3DataProvider = $this->getWeb3DataProvider();
$floorPrice = $web3DataProvider->getNftCollectionFloorPrice(
$floorPrice = $web3DataProvider->getCollectionFloorPrice(
Chain::from($this->chainId), $this->address
);

Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchCollectionOwners.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle(): void
'collection' => $this->collection->address,
]);

$owners = Mnemonic::getNftCollectionOwners(
$owners = Mnemonic::getCollectionOwners(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchCollectionTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle(): void
'collection' => $this->collection->address,
]);

$traits = Mnemonic::getNftCollectionTraits(
$traits = Mnemonic::getCollectionTraits(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchCollectionVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle(): void
'collection' => $this->collection->address,
]);

$volume = Mnemonic::getNftCollectionVolume(
$volume = Mnemonic::getCollectionVolume(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
);
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Web3/Alchemy/AlchemyWeb3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public function getMiddleware(): array
return [];
}

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
return $this->fromCache(
static fn () => Alchemy::getNftCollectionFloorPrice($chain, $contractAddress),
static fn () => Alchemy::getCollectionFloorPrice($chain, $contractAddress),
[$chain->name, $contractAddress]
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Web3/Fake/FakeWeb3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getWalletNfts(Wallet $wallet, Network $network, ?string $cursor
name: $nft->name,
description: null,
extraAttributes: $nft['extra_attributes']->toArray(),
floorPrice: $this->getNftCollectionFloorPrice(Chain::ETH, $wallet->address),
floorPrice: $this->getCollectionFloorPrice(Chain::ETH, $wallet->address),
traits: [],
mintedBlock: random_int(1, 10000),
mintedAt: now(),
Expand Down Expand Up @@ -114,7 +114,7 @@ public function getBlockTimestamp(Network $network, int $blockNumber): Carbon
return now();
}

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
return new Web3NftCollectionFloorPrice((string) (random_int(50, 1000) * 1e18), 'eth', Carbon::now());
}
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Web3/Mnemonic/MnemonicWeb3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function getCollectionsNfts(CollectionModel $collection, ?string $startTo
throw new NotImplementedException();
}

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
return $this->fromCache(
static fn () => Mnemonic::getNftCollectionFloorPrice($chain, $contractAddress),
static fn () => Mnemonic::getCollectionFloorPrice($chain, $contractAddress),
[$chain->name, $contractAddress]
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Web3/Moralis/MoralisWeb3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public function getMiddleware(): array
return [new RateLimited(Service::Moralis)];
}

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
return $this->fromCache(
static fn () => Moralis::getNftCollectionFloorPrice($chain, $contractAddress),
static fn () => Moralis::getCollectionFloorPrice($chain, $contractAddress),
[$chain->name, $contractAddress]
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Web3/Opensea/OpenseaWeb3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getCollectionsNfts(CollectionModel $collection, ?string $startTo
throw new NotImplementedException();
}

public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
public function getCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice
{
return $this->fromCache(
function () use ($contractAddress, $chain) {
Expand All @@ -64,7 +64,7 @@ function () use ($contractAddress, $chain) {
return null;
}

return Opensea::getNftCollectionFloorPrice($openseaSlug);
return Opensea::getCollectionFloorPrice($openseaSlug);
},
[$chain->name, $contractAddress]
);
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Facades/Alchemy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @method static Web3NftData parseNft(array $nft, int $networkId)
* @method static string getNativeBalance(Wallet $wallet, Network $network)
* @method static Carbon getBlockTimestamp(Network $network, int $blockNumber)
* @method static Web3NftCollectionFloorPrice | null getNftCollectionFloorPrice(Chain $chain, string $contractAddress)
* @method static Web3NftCollectionFloorPrice | null getCollectionFloorPrice(Chain $chain, string $contractAddress)
*
* @see App\Http\Client\Alchemy\AlchemyPendingRequest
*/
Expand Down
10 changes: 5 additions & 5 deletions app/Support/Facades/Mnemonic.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

/**
* @method static string getNativeBalance(Wallet $wallet, Network $network)
* @method static Web3NftCollectionFloorPrice | null getNftCollectionFloorPrice(Chain $chain, string $contractAddress)
* @method static string | null getNftCollectionBanner(Chain $chain, string $contractAddress)
* @method static int | null getNftCollectionOwners(Chain $chain, string $contractAddress)
* @method static string | null getNftCollectionVolume(Chain $chain, string $contractAddress)
* @method static Collection<int, Web3NftCollectionTrait> getNftCollectionTraits(Chain $chain, string $contractAddress)
* @method static Web3NftCollectionFloorPrice | null getCollectionFloorPrice(Chain $chain, string $contractAddress)
* @method static string | null getCollectionBanner(Chain $chain, string $contractAddress)
* @method static int | null getCollectionOwners(Chain $chain, string $contractAddress)
* @method static string | null getCollectionVolume(Chain $chain, string $contractAddress)
* @method static Collection<int, Web3NftCollectionTrait> getCollectionTraits(Chain $chain, string $contractAddress)
* @method static Collection<int, CollectionActivity> getCollectionActivity(Chain $chain, string $contractAddress, int $limit, ?Carbon $from = null)
* @method static Collection<int, CollectionActivity> getBurnActivity(Chain $chain, string $contractAddress, int $limit, ?Carbon $from = null)
*
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Facades/Moralis.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @method static string getNativeBalance(Wallet $wallet, Network $network)
* @method static Collection<int, WalletBalance> getNativeBalances(array $walletAddresses, Network $network)
* @method static Carbon getBlockTimestamp(Network $network, int $blockNumber)
* @method static Web3NftCollectionFloorPrice | null getNftCollectionFloorPrice(Chain $chain, string $contractAddress)
* @method static Web3NftCollectionFloorPrice | null getCollectionFloorPrice(Chain $chain, string $contractAddress)
*
* @see App\Http\Client\Moralis\MoralisPendingRequest
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Facades/Opensea.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* @method static string getCollectionTotalVolume(Collection $collection)
* @method static Web3NftCollectionFloorPrice | null getNftCollectionFloorPrice(string $collectionSlug)
* @method static Web3NftCollectionFloorPrice | null getCollectionFloorPrice(string $collectionSlug)
* @method static OpenseaNftDetails | null nft(Chain $chain, string $address, string $identifier)
*
* @see App\Http\Client\Opensea\OpenseaPendingRequest
Expand Down
8 changes: 4 additions & 4 deletions config/dashbrd.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@
'cache_ttl' => [
'alchemy' => [
'getBlockTimestamp' => 60 * 60 * 24 * 10, // 10 days... Creation date for blocks will never change, so we can safely cache in a distant future...
'getNftCollectionFloorPrice' => 60, // 1 minute
'getCollectionFloorPrice' => 60, // 1 minute
],
'moralis' => [
'getEnsDomain' => 60, // 1 minute
'getBlockTimestamp' => 60 * 60 * 24 * 10, // 10 days... Creation date for blocks will never change, so we can safely cache in a distant future...
'getNftCollectionFloorPrice' => 60, // 1 minute
'getCollectionFloorPrice' => 60, // 1 minute
],
'mnemonic' => [
'getBlockTimestamp' => 60 * 60 * 24 * 10, // 10 days... Creation date for blocks will never change, so we can safely cache in a distant future...
'getNftCollectionFloorPrice' => 60, // 1 minute
'getCollectionFloorPrice' => 60, // 1 minute
],
'opensea' => [
'getNftCollectionFloorPrice' => 60, // 1 minute
'getCollectionFloorPrice' => 60, // 1 minute
],
'coingecko' => [
'getPriceHistory' => [
Expand Down
22 changes: 11 additions & 11 deletions tests/App/Http/Client/Mnemonic/MnemonicPendingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'network_id' => $network->id,
]);

Mnemonic::getNftCollectionFloorPrice(Chain::Polygon, $collection->address);
Mnemonic::getCollectionFloorPrice(Chain::Polygon, $collection->address);
})->throws(ConnectionException::class);

it('should throw on 401', function () {
Expand All @@ -50,7 +50,7 @@
'network_id' => $network->id,
]);

Mnemonic::getNftCollectionFloorPrice(Chain::Polygon, $collection->address);
Mnemonic::getCollectionFloorPrice(Chain::Polygon, $collection->address);
})->throws(Exception::class);

it('should throw a custom exception on rate limits', function () {
Expand All @@ -66,7 +66,7 @@
'network_id' => $network->id,
]);

Mnemonic::getNftCollectionFloorPrice(Chain::Polygon, $collection->address);
Mnemonic::getCollectionFloorPrice(Chain::Polygon, $collection->address);
})->throws(RateLimitException::class);

it('should not retry request on 400', function () {
Expand Down Expand Up @@ -100,7 +100,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionOwners(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionOwners(Chain::Polygon, $collection->address);

expect($data)->toBe(789);
});
Expand All @@ -121,7 +121,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionVolume(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionVolume(Chain::Polygon, $collection->address);

expect($data)->toBe('12300000000000000000');
});
Expand All @@ -138,7 +138,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionVolume(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionVolume(Chain::Polygon, $collection->address);

expect($data)->toBe(null);
})->with([
Expand Down Expand Up @@ -171,7 +171,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionTraits(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionTraits(Chain::Polygon, $collection->address);

expect($data)->toHaveCount(25);
});
Expand All @@ -198,7 +198,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionTraits(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionTraits(Chain::Polygon, $collection->address);

expect($data)->toHaveCount(500 + 500 + 0 + 0);
});
Expand All @@ -219,7 +219,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionTraits(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionTraits(Chain::Polygon, $collection->address);

expect($data)->toHaveCount(1);
});
Expand All @@ -240,7 +240,7 @@
'network_id' => $network->id,
]);

$data = Mnemonic::getNftCollectionTraits(Chain::Polygon, $collection->address);
$data = Mnemonic::getCollectionTraits(Chain::Polygon, $collection->address);

expect($data)->toHaveCount(1);
});
Expand Down Expand Up @@ -472,5 +472,5 @@
'network_id' => $network->id,
]);

expect(Mnemonic::getNftCollectionFloorPrice(Chain::ETH, $collection->address))->toBeNull();
expect(Mnemonic::getCollectionFloorPrice(Chain::ETH, $collection->address))->toBeNull();
});
Loading
Loading