Skip to content

Commit 0fdfd9f

Browse files
authored
Merge pull request #164 from Virtual-Protocol/feat/yang-add-required-funds-to-job-offering
feat: add required funds to job offering
2 parents c9d3198 + eb9416f commit 0fdfd9f

5 files changed

Lines changed: 85 additions & 13 deletions

File tree

examples/acp-base/skip-evaluation/buyer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AcpClient, {
1111
import {
1212
BUYER_AGENT_WALLET_ADDRESS,
1313
WHITELISTED_WALLET_PRIVATE_KEY,
14-
BUYER_ENTITY_ID, SELLER_AGENT_WALLET_ADDRESS
14+
BUYER_ENTITY_ID,
1515
} from "./env";
1616

1717
async function buyer() {

src/acpClient.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import BaseAcpContractClient, {
88
} from "./contractClients/baseAcpContractClient";
99
import AcpJob from "./acpJob";
1010
import AcpMemo from "./acpMemo";
11-
import AcpJobOffering from "./acpJobOffering";
11+
import AcpJobOffering, { PriceType } from "./acpJobOffering";
1212
import {
1313
IAcpAgent,
1414
AcpAgentSort,
@@ -418,15 +418,30 @@ class AcpClient {
418418
id: agent.id,
419419
name: agent.name,
420420
description: agent.description,
421-
jobOfferings: agent.jobs.map((jobs) => {
421+
jobOfferings: agent.jobs
422+
.filter((offering) =>
423+
offering.priceV2?.value != null ||
424+
offering.price != null
425+
)
426+
.map((offering) => {
427+
const price =
428+
offering.priceV2?.value ??
429+
offering.price!;
430+
431+
const priceType =
432+
offering.priceV2?.type ??
433+
PriceType.FIXED;
434+
422435
return new AcpJobOffering(
423436
this,
424437
acpContractClient,
425438
agent.walletAddress,
426-
jobs.name,
427-
jobs.priceV2.value,
428-
jobs.priceV2.type,
429-
jobs.requirement,
439+
offering.name,
440+
price,
441+
priceType,
442+
offering.requiredFunds,
443+
offering.requirement,
444+
offering.deliverable
430445
);
431446
}),
432447
contractAddress: agent.contractAddress,

src/acpJobOffering.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class AcpJobOffering {
2929
public providerAddress: Address,
3030
public name: string,
3131
public price: number,
32-
public priceType: PriceType = PriceType.FIXED,
33-
public requirement?: Object | string
32+
public priceType: PriceType,
33+
public requiredFunds: boolean,
34+
public requirement?: Object | string,
35+
public deliverable?: Object | string
3436
) {
3537
this.ajv = new Ajv({ allErrors: true });
3638
}

src/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ export interface IAcpAgent {
126126
twitterHandle: string;
127127
jobs: {
128128
name: string;
129+
price: number;
129130
priceV2: {
130131
type: PriceType;
131132
value: number;
132133
};
134+
requiredFunds: boolean;
133135
requirement?: Object | string;
134136
deliverable?: Object | string;
135137
}[];

test/unit/acpJobOffering.test.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,33 @@ describe("AcpJobOffering Unit Testing", () => {
6565
"MockJob",
6666
100,
6767
PriceType.FIXED,
68+
true,
6869
);
6970

7071
expect(offering).toBeInstanceOf(AcpJobOffering);
7172
expect(offering.providerAddress).toBe("0xProvider");
7273
expect(offering.name).toBe("MockJob");
7374
expect(offering.price).toBe(100);
7475
expect(offering.priceType).toBe(PriceType.FIXED);
76+
expect(offering.requiredFunds).toBe(true);
7577
expect(offering.requirement).toBe(undefined);
78+
expect(offering.deliverable).toBe(undefined);
7679
});
7780

78-
it("should use default priceType of FIXED", () => {
81+
it("should use priceType FIXED and requiredFunds", () => {
7982
const offering = new AcpJobOffering(
8083
mockAcpClient,
8184
mockContractClient,
8285
"0xProvider" as Address,
8386
"MockJob",
8487
100,
88+
PriceType.FIXED,
89+
false,
8590
);
8691

8792
expect(offering).toBeInstanceOf(AcpJobOffering);
8893
expect(offering.priceType).toBe(PriceType.FIXED);
94+
expect(offering.requiredFunds).toBe(false);
8995
});
9096

9197
it("should accept custom priceType", () => {
@@ -96,6 +102,7 @@ describe("AcpJobOffering Unit Testing", () => {
96102
"MockJob",
97103
100,
98104
PriceType.PERCENTAGE,
105+
true,
99106
);
100107

101108
expect(offering.priceType).toBe(PriceType.PERCENTAGE);
@@ -108,7 +115,8 @@ describe("AcpJobOffering Unit Testing", () => {
108115
"0xProvider" as Address,
109116
"MockJob",
110117
100,
111-
undefined,
118+
PriceType.FIXED,
119+
true,
112120
"custom requirement",
113121
);
114122

@@ -128,13 +136,50 @@ describe("AcpJobOffering Unit Testing", () => {
128136
"0xProvider" as Address,
129137
"MockJob",
130138
100,
131-
undefined,
139+
PriceType.FIXED,
140+
true,
132141
requirementObject,
133142
);
134143

135144
expect(offering).toBeInstanceOf(AcpJobOffering);
136145
expect(offering.requirement).toBe(requirementObject);
137146
});
147+
148+
it("should accept deliverable as string", () => {
149+
const offering = new AcpJobOffering(
150+
mockAcpClient,
151+
mockContractClient,
152+
"0xProvider" as Address,
153+
"MockJob",
154+
100,
155+
PriceType.FIXED,
156+
true,
157+
undefined,
158+
"custom deliverable",
159+
);
160+
161+
expect(offering).toBeInstanceOf(AcpJobOffering);
162+
expect(offering.deliverable).toBe("custom deliverable");
163+
});
164+
165+
it("should accept deliverable as object", () => {
166+
const deliverableObject = { type: "image", format: "png" };
167+
168+
const offering = new AcpJobOffering(
169+
mockAcpClient,
170+
mockContractClient,
171+
"0xProvider" as Address,
172+
"MockJob",
173+
100,
174+
PriceType.FIXED,
175+
false,
176+
undefined,
177+
deliverableObject,
178+
);
179+
180+
expect(offering).toBeInstanceOf(AcpJobOffering);
181+
expect(offering.deliverable).toEqual(deliverableObject);
182+
});
138183
});
139184

140185
describe("initiateJob", () => {
@@ -161,7 +206,8 @@ describe("AcpJobOffering Unit Testing", () => {
161206
"0xProvider" as Address,
162207
"Generate Image",
163208
100,
164-
undefined,
209+
PriceType.FIXED,
210+
true,
165211
);
166212

167213
const result = await offering.initiateJob(
@@ -218,6 +264,7 @@ describe("AcpJobOffering Unit Testing", () => {
218264
"Generate Image",
219265
100,
220266
PriceType.FIXED,
267+
true,
221268
requirementSchema,
222269
);
223270

@@ -249,6 +296,7 @@ describe("AcpJobOffering Unit Testing", () => {
249296
"Generate Image",
250297
100,
251298
PriceType.FIXED,
299+
true,
252300
requirementSchema,
253301
);
254302

@@ -286,6 +334,7 @@ describe("AcpJobOffering Unit Testing", () => {
286334
"Generate Image",
287335
100,
288336
PriceType.PERCENTAGE,
337+
true,
289338
);
290339

291340
const result = await offering.initiateJob(
@@ -324,6 +373,8 @@ describe("AcpJobOffering Unit Testing", () => {
324373
"0xProvider" as Address,
325374
"Generate Image",
326375
100,
376+
PriceType.FIXED,
377+
true,
327378
);
328379

329380
const result = await offering.initiateJob(
@@ -374,6 +425,8 @@ describe("AcpJobOffering Unit Testing", () => {
374425
"0xProvider" as Address,
375426
"Generate Image",
376427
100,
428+
PriceType.FIXED,
429+
true,
377430
);
378431

379432
const result = await offering.initiateJob(

0 commit comments

Comments
 (0)