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

feat: update deal interface #1107

Merged
merged 5 commits into from
Feb 12, 2025
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 packages/cli/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"whatwg-url": "^14.0.0"
},
"dependencies": {
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0",
"@fluencelabs/deal-ts-clients": "0.23.2-update-deal-interface-c153307-7773-1.0",
"@kubernetes/client-node": "github:fluencelabs/kubernetes-client-javascript#e72ee00a52fec4eb4a8327632895d888ee504f4d",
"@libp2p/crypto": "4.0.1",
"@libp2p/peer-id-factory": "4.0.5",
Expand Down
59 changes: 20 additions & 39 deletions packages/cli/package/src/commands/provider/deal-exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
} from "../../lib/const.js";
import {
getContracts,
getSignerAddress,
multicallRead,
populateTx,
signBatch,
Expand Down Expand Up @@ -54,7 +53,6 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(DealExit));
const { contracts } = await getContracts();
const signerAddress = await getSignerAddress();

const dealIds =
// flags.all
Expand All @@ -78,62 +76,45 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
}

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const workersFromRPC = (await multicallRead(
const workerIdsFromRPC = (await multicallRead(
dealIds.map((id): MulticallReadItem => {
const deal = contracts.getDeal(id);
const deal = contracts.getDealV2(id);
return {
target: id,
callData: deal.interface.encodeFunctionData("getWorkers"),
callData: deal.interface.encodeFunctionData("getWorkerIds"),
decode(returnData) {
return deal.interface.decodeFunctionResult(
"getWorkers",
"getWorkerIds",
returnData,
);
},
};
}),
)) as Awaited<ReturnType<ReturnType<Contracts["getDeal"]>["getWorkers"]>>[];
)) as Awaited<
ReturnType<ReturnType<Contracts["getDealV2"]>["getWorkerIds"]>
>[];

const dealWorkers = dealIds.map((id, i) => {
const deal = contracts.getDeal(id);
const workers = workersFromRPC[i];

return {
dealId: id,
workers: (workers ?? [])
.filter((worker) => {
return worker.provider.toLowerCase() === signerAddress;
})
.map((worker) => {
return { worker, deal };
}),
};
const dealWorkerIds = dealIds.map((dealId, i) => {
return { dealId, workerIds: workerIdsFromRPC[i] ?? [] };
});

for (const { dealId, workers } of dealWorkers) {
const [firstWorker, ...restWorkers] = workers;

if (firstWorker === undefined) {
commandObj.warn(
`No workers found for address ${signerAddress} and deal id: ${dealId}`,
);
for (const { dealId, workerIds } of dealWorkerIds) {
const deal = contracts.getDealV2(dealId);
const [firstWorkerId, ...restWorkerIds] = workerIds;

if (firstWorkerId === undefined) {
commandObj.warn(`No workers found for deal id: ${dealId}`);
continue;
}

await signBatch({
title: `Remove the following workers from deal ${dealId}:\n\n${workers
.map(({ worker: { onchainId } }) => {
return onchainId;
})
.join("\n")}`,
title: `Remove the following workers from deal ${dealId}:\n\n${workerIds.join(
"\n",
)}`,
populatedTxs: [
populateTx(
firstWorker.deal.removeWorker,
firstWorker.worker.onchainId,
),
...restWorkers.map(({ deal, worker: { onchainId } }) => {
return populateTx(deal.removeWorker, onchainId);
populateTx(deal.removeWorker, firstWorkerId),
...restWorkerIds.map((workerId) => {
return populateTx(deal.removeWorker, workerId);
}),
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class DealRewardsInfo extends BaseCommand<
(await input({ message: "Enter on-chain worker id" }));

const { readonlyContracts } = await getReadonlyContracts();
const deal = readonlyContracts.getDeal(dealAddress);
const deal = readonlyContracts.getDealV2(dealAddress);
const rewardAmount = await deal.getRewardAmount(onChainWorkerId);

commandObj.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import { BaseCommand } from "../../baseCommand.js";
import { peerIdHexStringToBase58String } from "../../lib/chain/conversions.js";
import { ptFormatWithSymbol } from "../../lib/chain/currencies.js";
import { commandObj } from "../../lib/commandObj.js";
import {
Expand Down Expand Up @@ -69,30 +68,30 @@ export default class DealRewardsWithdraw extends BaseCommand<
const { contracts } = await getContracts();

for (const dealId of dealIds) {
const deal = contracts.getDeal(dealId);
const workers = await deal.getWorkers();
const deal = contracts.getDealV2(dealId);
const workersIds = await deal.getWorkerIds();

let providerRewards = 0n;
let stakerRewards = 0n;

for (const { onchainId, peerId } of workers) {
const rewardAmount = await deal.getRewardAmount(onchainId);
for (const workerId of workersIds) {
const rewardAmount = await deal.getRewardAmount(workerId);

if (
rewardAmount.providerReward === 0n &&
rewardAmount.stakerReward === 0n
) {
commandObj.logToStderr(
`No rewards to withdraw for worker ${onchainId} (${await peerIdHexStringToBase58String(peerId)})`,
`No rewards to withdraw for worker ${workerId}`,
);

continue;
}

const txReceipt = await sign({
title: `Withdraw rewards for worker ${onchainId}`,
title: `Withdraw rewards for worker ${workerId}`,
method: deal.withdrawRewards,
args: [onchainId],
args: [workerId],
});

const providerReward = getEventValue({
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": 2,
"chain-rpc": "docker.fluence.dev/chain-rpc:feat-marketplace-v2-resources-d1eaf27-7661-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:feat-marketplace-v2-resources-d1eaf27-7661-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:feat-marketplace-v2-resources-d1eaf27-7661-1"
"chain-rpc": "docker.fluence.dev/chain-rpc:update-deal-interface-c153307-7773-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:update-deal-interface-c153307-7773-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:update-deal-interface-c153307-7773-1"
}
10 changes: 5 additions & 5 deletions packages/cli/package/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ __metadata:
dependencies:
"@actions/core": "npm:1.11.1"
"@aws-sdk/lib-storage": "npm:^3.501.0"
"@fluencelabs/deal-ts-clients": "npm:0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0"
"@fluencelabs/deal-ts-clients": "npm:0.23.2-update-deal-interface-c153307-7773-1.0"
"@graphql-codegen/cli": "npm:^5.0.3"
"@graphql-codegen/typescript": "npm:^4.1.1"
"@graphql-codegen/typescript-graphql-request": "npm:^6.2.0"
Expand Down Expand Up @@ -2038,9 +2038,9 @@ __metadata:
languageName: unknown
linkType: soft

"@fluencelabs/deal-ts-clients@npm:0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0":
version: 0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0
resolution: "@fluencelabs/deal-ts-clients@npm:0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0"
"@fluencelabs/deal-ts-clients@npm:0.23.2-update-deal-interface-c153307-7773-1.0":
version: 0.23.2-update-deal-interface-c153307-7773-1.0
resolution: "@fluencelabs/deal-ts-clients@npm:0.23.2-update-deal-interface-c153307-7773-1.0"
dependencies:
"@graphql-typed-document-node/core": "npm:^3.2.0"
debug: "npm:^4.3.4"
Expand All @@ -2052,7 +2052,7 @@ __metadata:
graphql-tag: "npm:^2.12.6"
ipfs-http-client: "npm:^60.0.1"
multiformats: "npm:^13.0.1"
checksum: 10c0/de15f6704ce019eb5ed0f2f4a8a6714c1b3770eea0acba6c2cd5426c0ebdd5055a48f0c0262f4532bd1adfbde9f7490e483a0014616e14b0612a57b042a2a9c4
checksum: 10c0/b35fabbd4db97676a50b221805e048912553c84b65c9bd0b09274d5ced72a56f209ef20ddfd0a087fce36e8a82047a2ccfdbb906a94fe996f1d75c011f5f57cf
languageName: node
linkType: hard

Expand Down
Loading