Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem committed Jan 16, 2025
1 parent 23d3d22 commit 59edf79
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package/bin/dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --no-warnings --import tsx
#!/usr/bin/env -S node --no-warnings --no-deprecation --import tsx

/**
* Fluence CLI
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package/bin/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --no-warnings
#!/usr/bin/env -S node --no-warnings --no-deprecation

/**
* Fluence CLI
Expand Down
61 changes: 34 additions & 27 deletions packages/cli/package/src/lib/chain/offer/offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
type ResourcePrices,
resourceTypeToOnChainResourceType,
OnChainResourceType,
isOnChainResourceType,
onChainResourceTypeToResourceType,
getDataCentersFromChain,
resourcePriceToBigInt,
Expand Down Expand Up @@ -60,7 +59,7 @@ import {
import { getOffers } from "../../gql/gql.js";
import { setTryTimeout } from "../../helpers/setTryTimeout.js";
import { stringifyUnknown } from "../../helpers/stringifyUnknown.js";
import { bigintToStr, numToStr } from "../../helpers/typesafeStringify.js";
import { numToStr } from "../../helpers/typesafeStringify.js";
import {
commaSepStrToArr,
splitErrorsAndResults,
Expand Down Expand Up @@ -635,13 +634,26 @@ async function formatOfferInfo(
"Data Center": offerIndexerInfo.dataCenter,
"Created At": offerIndexerInfo.createdAt,
"Last Updated At": offerIndexerInfo.updatedAt,
"Resource Prices": offerIndexerInfo.resources?.map(
({ resourceId, resourcePrice }) => {
return {
"Resource ID": resourceId,
Price: bigintToStr(resourcePrice),
};
},
"Resource Prices": await Promise.all(
(offerIndexerInfo.resources ?? []).map(
async ({
resourceId,
resourcePrice,
resource: { type, metadata },
}) => {
const resourceType = onChainResourceTypeToResourceType(type);
return {
"Resource Type": resourceType,
"Resource ID": resourceId,
Metadata: metadata,
Price: await ptFormatWithSymbol(
resourceType === "cpu"
? resourcePrice * BigInt(VCPU_PER_CU)
: resourcePrice,
),
};
},
),
),
"Total compute units": offerIndexerInfo.totalComputeUnits,
"Free compute units": offerIndexerInfo.freeComputeUnits,
Expand All @@ -654,57 +666,60 @@ async function formatOfferInfo(
Resources: {
CPU: {
"Resource ID": resourcesByType.cpu.resourceId,
Metadata: resourcesByType.cpu.metadata,
Details: resourcesByType.cpu.details,
Supply: (
await resourceSupplyFromChainToConfig(
"cpu",
resourcesByType.cpu.supply,
)
).supplyString,
Details: resourcesByType.cpu.details,
},
RAM: {
"Resource ID": resourcesByType.ram.resourceId,
Metadata: resourcesByType.ram.metadata,
Details: resourcesByType.ram.details,
Supply: (
await resourceSupplyFromChainToConfig(
"ram",
resourcesByType.ram.supply,
)
).supplyString,
Details: resourcesByType.ram.details,
},
Storage: await Promise.all(
resourcesByType.storage.map(async (storage) => {
return {
"Resource ID": storage.resourceId,
Metadata: storage.metadata,
Details: storage.details,
Supply: (
await resourceSupplyFromChainToConfig(
"storage",
storage.supply,
)
).supplyString,
Details: storage.details,
};
}),
),
IP: {
"Resource ID": resourcesByType.ip.resourceId,
Metadata: resourcesByType.ip.metadata,
Supply: (
await resourceSupplyFromChainToConfig(
"ip",
resourcesByType.ip.supply,
)
).supplyString,
Details: resourcesByType.ip.details,
},
Bandwidth: {
"Resource ID": resourcesByType.bandwidth.resourceId,
Metadata: resourcesByType.bandwidth.metadata,
Supply: (
await resourceSupplyFromChainToConfig(
"bandwidth",
resourcesByType.bandwidth.supply,
)
).supplyString,
Details: resourcesByType.bandwidth.details,
},
},
};
Expand Down Expand Up @@ -775,14 +790,7 @@ export async function resolveOffersFromProviderConfig(
offerIndexerInfo.resources ?? []
).reduce<ResourcePricesWithIds>(
(acc, { resourceId, resourcePrice, resource: { type } }) => {
if (
!isOnChainResourceType(type) ||
type === OnChainResourceType.GPU
) {
return acc;
}

const resourceType = onChainResourceTypeToResourceType[type];
const resourceType = onChainResourceTypeToResourceType(type);

acc[resourceType].push({
ty: type,
Expand Down Expand Up @@ -952,6 +960,7 @@ export type OnChainResource = {
resourceId: string;
supply: number;
details: string;
metadata: string;
};

type ResourcePricesWithIds = Record<
Expand Down Expand Up @@ -1318,15 +1327,13 @@ function indexerResourcesToOnchainResources(
>,
offerId: string,
): [OnChainResource, ...OnChainResource[]] {
const onChainResourceType = resourceTypeToOnChainResourceType[resourceType];

const [firstResource, ...restResources] = resources
.filter(({ resource: { type } }) => {
return isOnChainResourceType(type) && type === onChainResourceType;
return onChainResourceTypeToResourceType(type) === resourceType;
})
.map(({ details, resource: { id: resourceId }, maxSupply }) => {
.map(({ details, resource: { id: resourceId, metadata }, maxSupply }) => {
assertIsHex(resourceId, `Invalid Resource ID for offer ${offerId}`);
return { resourceId, supply: Number(maxSupply), details };
return { resourceId, supply: Number(maxSupply), details, metadata };
});

if (firstResource === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package/src/lib/chain/offer/updateOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ async function populateChangeResourcePriceTx({
}

return {
description: `Change ${resourceType} resource price for ${resourceName} from ${await ptFormatWithSymbol(resourcePrice * BigInt(VCPU_PER_CU))} to ${await ptFormatWithSymbol(price)}`,
description: `Change ${resourceType} resource price for ${resourceName} from ${await ptFormatWithSymbol(resourceType === "cpu" ? resourcePrice * BigInt(VCPU_PER_CU) : resourcePrice)} to ${await ptFormatWithSymbol(price)}`,
tx: populateTx(
contracts.diamond.changeResourcePriceV2,
offerId,
Expand Down
39 changes: 18 additions & 21 deletions packages/cli/package/src/lib/configs/project/provider/provider4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export function bandwidthResourceToHumanReadableString({
}

export function ipResourceToHumanReadableString({ version }: IPMetadata) {
return version;
return `v${version}`;
}

export async function resourceNameToId(
Expand Down Expand Up @@ -1224,13 +1224,22 @@ export enum OnChainResourceType {
STORAGE,
PUBLIC_IP,
NETWORK_BANDWIDTH,
GPU,
}

export function isOnChainResourceType(
value: unknown,
): value is OnChainResourceType {
return typeof value === "number" && value in OnChainResourceType;
export function onChainResourceTypeToResourceType(value: number | bigint) {
const numberValue = Number(value);
assertOnChainResourceType(numberValue);
return onChainResourceTypeToResourceTypeMap[numberValue];
}

function assertOnChainResourceType(
value: number,
): asserts value is OnChainResourceType {
if (!(value in OnChainResourceType)) {
commandObj.error(
`Unknown resource type: ${color.yellow(value)}. You may need to update ${CLI_NAME_FULL}`,
);
}
}

export const resourceTypeToOnChainResourceType: Record<
Expand All @@ -1244,8 +1253,8 @@ export const resourceTypeToOnChainResourceType: Record<
ip: OnChainResourceType.PUBLIC_IP,
};

export const onChainResourceTypeToResourceType: Record<
Exclude<OnChainResourceType, OnChainResourceType.GPU>,
const onChainResourceTypeToResourceTypeMap: Record<
OnChainResourceType,
ResourceType
> = {
[OnChainResourceType.VCPU]: "cpu",
Expand Down Expand Up @@ -1777,19 +1786,7 @@ async function getResourcesFromChainImpl(): Promise<ChainResources> {
};

for (const { metadata, id, ty } of resources) {
const onChainResourceType = Number(ty);

if (!isOnChainResourceType(onChainResourceType)) {
commandObj.error(
`Unknown resource type: ${color.yellow(onChainResourceType)}. You may need to update ${CLI_NAME_FULL}`,
);
}

if (onChainResourceType === OnChainResourceType.GPU) {
continue;
}

const resourceType = onChainResourceTypeToResourceType[onChainResourceType];
const resourceType = onChainResourceTypeToResourceType(ty);

try {
const parsedMetadata = JSON.parse(metadata);
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package/src/lib/gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ query OfferDetails($where: Offer_filter) {
resource {
id
type
metadata
}
}
peers(where: { deleted: false }) {
Expand All @@ -33,6 +34,7 @@ query OfferDetails($where: Offer_filter) {
resource {
id
type
metadata
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package/src/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"protocolVersion": 1,
"chain-rpc": "docker.fluence.dev/chain-rpc:add-dc-to-subgraph-afdd94a-7473-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:add-dc-to-subgraph-afdd94a-7473-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:add-dc-to-subgraph-afdd94a-7473-1"
"chain-rpc": "docker.fluence.dev/chain-rpc:feat-marketplace-v2-resources-40f9723-7509-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:feat-marketplace-v2-resources-40f9723-7509-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:feat-marketplace-v2-resources-40f9723-7509-1"
}

0 comments on commit 59edf79

Please sign in to comment.