Skip to content

Commit

Permalink
PlatformID is everywhere now (#25)
Browse files Browse the repository at this point in the history
* Added functionality to specify PlatformId as a parameter

* Updated Comments (PlatformID parameter)
  • Loading branch information
pranav-dblocked authored Apr 7, 2024
1 parent a66f574 commit dc92321
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions packages/client/src/disputes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ export class Disputes {

/**
* getArbitrationCost - Retrieves the current cost of arbitration. This function is useful for understanding the financial implications of initiating an arbitration process.
* @param {number} platformId - The platform ID where the arbitration cost is to be retrieved. (Optional)
* @returns {Promise<any>} - Returns a Promise that resolves to the arbitration cost, typically in a numerical or string format representing the cost value.
*/
public async getArbitrationCost(): Promise<any> {
const platformResponse = await this.subgraph.get(getPlatformById(this.platformID.toString()));
public async getArbitrationCost(platformId?: number): Promise<any> {
const platformID = platformId || this.platformID;
const platformResponse = await this.subgraph.get(getPlatformById(platformID.toString()));

if (!platformResponse?.data?.platform) {
throw new Error('Platform not found');
Expand All @@ -73,21 +75,23 @@ export class Disputes {
address: arbitrator,
abi: contract.abi,
functionName: 'arbitrationCost',
args: [toHex(this.platformID, { size: 32 })],
args: [toHex(platformID, { size: 32 })],
});
}

/**
* setPrice - Sets the price of arbitration. This function allows for modifying the arbitration cost for the current platform
* @param {number | string} value - The new price value for arbitration, which can be specified as a number or a string representing the price.
* @param {number} platformId - The platform ID where the price of arbitration is set. (optional)
* @returns {Promise<Hash>} - A promise that resolves to the transaction hash of the set operation.
*/
public async setPrice(value: number | string): Promise<Hash> {
public async setPrice(value: number | string, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const transformedPrice = parseEther(value.toString());
this.logger.debug(`Setting arbitration price to ${transformedPrice}`);

const tx = await this.wallet.writeContract('talentLayerArbitrator', 'setArbitrationPrice', [
this.platformID,
platformID,
transformedPrice,
]);

Expand Down
14 changes: 9 additions & 5 deletions packages/client/src/escrow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export class Escrow {
serviceId: string,
proposalId: string,
metaEvidenceCid: string,
platformId?: number
): Promise<ClientTransactionResponse> {
const platformID = platformId || this.platformID;
const proposalInstance = new Proposal(
this.graphQlClient,
this.ipfsClient,
this.viemClient,
this.platformID,
platformID,
this.logger
);
const proposal = await proposalInstance.getOne(proposalId);
Expand Down Expand Up @@ -154,12 +156,13 @@ export class Escrow {
throw new Error('Error creating Transaction');
}

public async release(serviceId: string, amount: bigint, userId: number): Promise<any> {
public async release(serviceId: string, amount: bigint, userId: number, platformId?: number): Promise<any> {
const platformID = platformId || this.platformID;
const serviceInstance = new Service(
this.graphQlClient,
this.ipfsClient,
this.viemClient,
this.platformID,
platformID,
this.logger
);
const service = await serviceInstance.getOne(serviceId);
Expand All @@ -182,12 +185,13 @@ export class Escrow {
return tx;
}

public async reimburse(serviceId: string, amount: bigint, userId: number): Promise<any> {
public async reimburse(serviceId: string, amount: bigint, userId: number, platformId?: number): Promise<any> {
const platformID = platformId || this.platformID;
const serviceInstance = new Service(
this.graphQlClient,
this.ipfsClient,
this.viemClient,
this.platformID,
platformID,
this.logger
);
const service = await serviceInstance.getOne(serviceId);
Expand Down
57 changes: 35 additions & 22 deletions packages/client/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ export class Platform {
* Updates the platform details on the blockchain using the provided data.
*
* @param {PlatformDetails} data - The new platform details to be updated.
* @param {number} platformId - The platform ID where the platform details are updated. (optional)
* @returns {Promise<ClientTransactionResponse>} A promise that resolves to the transaction response of the update operation.
*/
public async update(data: PlatformDetails): Promise<ClientTransactionResponse> {
public async update(data: PlatformDetails, platformId?: number): Promise<ClientTransactionResponse> {
const platformID = platformId || this.platformID;
this.logger.debug('updating platform details');
const cid = await this.upload(data);
this.logger.debug('platform details uploaded to ipfs', cid);
const tx = await this.wallet.writeContract('talentLayerPlatformId', 'updateProfileData', [
this.platformID,
platformID,
cid,
]);

Expand All @@ -117,9 +119,9 @@ export class Platform {
*/
public async mint(platformName: string): Promise<Hash> {
const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'mint',
[platformName],
'talentLayerPlatformId',
'mint',
[platformName],
);

return tx;
Expand All @@ -129,13 +131,15 @@ export class Platform {
* Sets the fee timeout for the platform.
*
* @param {number} timeout - The timeout value in seconds.
* @param {number} platformId - The platform ID where the fee timeout is set. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async setFeeTimeout(timeout: number): Promise<Hash> {
public async setFeeTimeout(timeout: number, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'updateArbitrationFeeTimeout',
[this.platformID, timeout],
[platformID, timeout],
);

return tx;
Expand Down Expand Up @@ -163,9 +167,11 @@ export class Platform {
* Throws an error if the provided address is not an allowed arbitrator.
*
* @param {Hash} address - The new arbitrator's address.
* @param {number} platformId - The platform ID where the arbitrator address is updated. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async updateArbitrator(address: Hash): Promise<Hash> {
public async updateArbitrator(address: Hash, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const allowedArbitrators: Arbitrator[] = this.getArbitrators(this.wallet.chainId);

const allowedArbitratorAddresses = allowedArbitrators.map((_arbitrator: Arbitrator) =>
Expand All @@ -177,7 +183,7 @@ export class Platform {
}

const tx = await this.wallet.writeContract('talentLayerPlatformId', 'updateArbitrator', [
this.platformID,
platformID,
address,
'',
]);
Expand All @@ -191,16 +197,18 @@ export class Platform {
* Updates the service fee rate for origin services on the platform.
*
* @param {number} value - The new fee rate as a percentage ( if you want to set the fees to 5%, pass in 5).
* @param {number} platformId - The platform ID where the service fee rate is updated. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async updateOriginServiceFeeRate(value: number): Promise<Hash> {
public async updateOriginServiceFeeRate(value: number, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const transformedFeeRate = Math.round((Number(value) * FEE_RATE_DIVIDER) / 100);

this.logger.info(`updating service fee rate for platform id: ${this.platformID} to ${transformedFeeRate}`);
this.logger.info(`updating service fee rate for platform id: ${platformID} to ${transformedFeeRate}`);
const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'updateOriginServiceFeeRate',
[this.platformID, transformedFeeRate],
[platformID, transformedFeeRate],
);

return tx;
Expand All @@ -210,16 +218,18 @@ export class Platform {
* Updates the fee rate for validated proposals
*
* @param {number} value - The new fee rate as a percentage ( if you want to set the fees to 5%, pass in 5).
* @param {number} platformId - The platform ID where fee rate is updated. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async updateOriginValidatedProposalFeeRate(value: number): Promise<Hash> {
public async updateOriginValidatedProposalFeeRate(value: number, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const transformedFeeRate = Math.round((Number(value) * FEE_RATE_DIVIDER) / 100);

this.logger.debug('SDK: transformedFeeRate', transformedFeeRate, this.platformID);
this.logger.debug('SDK: transformedFeeRate', transformedFeeRate, platformID);
const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'updateOriginValidatedProposalFeeRate',
[this.platformID, transformedFeeRate],
[platformID, transformedFeeRate],
);

return tx;
Expand All @@ -229,14 +239,15 @@ export class Platform {
* Updates the posting fee for services on the platform.
*
* @param {number} value - The new fee rate.
* @param {number} platformId - The platform ID where the posting fee is updated. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async updateServicePostingFee(value: number): Promise<Hash> {
public async updateServicePostingFee(value: number, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const transformedFeeRate = parseEther(value.toString());

this.logger.debug(`updating service posting fee rate for platform id: ${this.platformID} to ${transformedFeeRate}`);
this.logger.debug(`updating service posting fee rate for platform id: ${platformID} to ${transformedFeeRate}`);
const tx = await this.wallet.writeContract('talentLayerPlatformId', 'updateServicePostingFee', [
this.platformID,
platformID,
transformedFeeRate,
]);

Expand All @@ -247,16 +258,18 @@ export class Platform {
* Updates the posting fee for proposals on the platform.
*
* @param {number} value - The new fee rate.
* @param {number} platformId - The platform ID where the posting fee is updated. (optional)
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the update operation.
*/
public async updateProposalPostingFee(value: number): Promise<Hash> {
public async updateProposalPostingFee(value: number, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformID;
const transformedFeeRate = parseEther(value.toString());
this.logger.debug(`updating proposal posting fee rate for platform id: ${this.platformID} to ${transformedFeeRate}`);
this.logger.debug(`updating proposal posting fee rate for platform id: ${platformID} to ${transformedFeeRate}`);

const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'updateProposalPostingFee',
[this.platformID, transformedFeeRate],
[platformID, transformedFeeRate],
);

return tx;
Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ export class Profile {
/**
* create - Creates a new user profile by minting it on the TalentLayerId contract. This function is typically called when a new user registers and a profile needs to be created in the system.
* @param {string} handle - The user handle or username for the new profile.
* @param {number} platformId - The platform ID where the profile is created. (optional)
* @returns {Promise<Hash>} - A promise that resolves to the transaction hash once the profile creation transaction is completed.
*/
public async create(handle: string): Promise<Hash> {
public async create(handle: string, platformId?: number): Promise<Hash> {
const platformID = platformId || this.platformId;
const proposolResponse = await this.graphQlClient.get(getProtocolById(1));

const protocol = proposolResponse?.data?.protocol;
Expand All @@ -124,7 +126,7 @@ export class Profile {
return this.viemClient.writeContract(
'talentLayerId',
'mint',
[this.platformId.toString(), handle],
[platformID.toString(), handle],
BigInt(fee),
);
}
Expand Down
9 changes: 6 additions & 3 deletions packages/client/src/proposals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class Proposal {
* @param {string} rateToken - The address of the token used for setting the rate.
* @param {string} rateAmount - The amount/rate for which the proposal is being created
* @param {string} expirationDate - The expiration date of the proposal.
* @param {number} platformId - The platform ID where the proposal is to be created. (optional)
* @returns {Promise<ClientTransactionResponse>} - A promise that resolves to the transaction response for the proposal creation {cid and txHash}.
*/
public async create(
Expand All @@ -121,7 +122,9 @@ export class Proposal {
rateToken: string,
rateAmount: string,
expirationDate: string,
platformId?: number,
): Promise<ClientTransactionResponse> {
const platformID = platformId || this.platformID;
const cid = await this.upload(proposalDetails);
const signature = await this.getSignature({
profileId: Number(userId),
Expand All @@ -132,19 +135,19 @@ export class Proposal {
const platform = new Platform(
this.graphQlClient,
this.viemClient,
this.platformID,
platformID,
this.ipfsClient,
this.logger
);

const platformDetails = await platform.getOne(this.platformID.toString());
const platformDetails = await platform.getOne(platformID.toString());

const proposalPostingFees = BigInt(platformDetails?.proposalPostingFee || '0');

const tx = await this.viemClient.writeContract(
'talentLayerService',
'createProposal',
[userId, serviceId, rateToken, rateAmount, this.platformID, cid, expirationDate, signature],
[userId, serviceId, rateToken, rateAmount, platformID, cid, expirationDate, signature],
proposalPostingFees,
);

Expand Down

0 comments on commit dc92321

Please sign in to comment.