Skip to content

Commit

Permalink
feat: add attribute to detect the deployment origin (#634)
Browse files Browse the repository at this point in the history
* docs+tests: add docs + tests

* fix: metadata documentation

* Update packages/deploy/src/models/deployment.ts

Co-authored-by: Eric Lau <[email protected]>

---------

Co-authored-by: Eric Lau <[email protected]>
  • Loading branch information
MCarlomagno and ericglau authored Dec 30, 2024
1 parent c56c8d7 commit 406f8d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
20 changes: 20 additions & 0 deletions packages/deploy/src/api/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ describe('Deploy Client', () => {
expect(deployClient.api.post).toBeCalledWith('/deployments', deployCreatePayload);
expect(createAuthenticatedApi).toBeCalled();
});
it('adds origin to the payload if not provided', async () => {
await deployClient.deployContract(deployCreatePayload);
expect(deployClient.api.post).toHaveBeenCalledWith(
'/deployments',
expect.objectContaining({
origin: 'SDK',
}),
);
expect(createAuthenticatedApi).toHaveBeenCalled();
});
it('allows custom origin', async () => {
await deployClient.deployContract({ ...deployCreatePayload, origin: 'Foundry' });
expect(deployClient.api.post).toHaveBeenCalledWith(
'/deployments',
expect.objectContaining({
origin: 'Foundry',
}),
);
expect(createAuthenticatedApi).toHaveBeenCalled();
});
});
describe('get', () => {
it('calls API correctly', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/deploy/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class DeployClient extends BaseApiClient {
params.artifactPayload = JSON.stringify(extractArtifact(params));
}

// If the origin is not provided,
// we assume the deployment was made using the SDK
if (!params.origin) params.origin = 'SDK';

return this.apiCall(async (api) => {
return api.post(`${DEPLOYMENTS_PATH}`, params);
});
Expand Down
15 changes: 12 additions & 3 deletions packages/deploy/src/models/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ export interface DeployContractRequest {
approvalProcessId?: string;
createFactoryAddress?: string;
/**
* Only applies to Relayers approval processes, for other default approval processes it has no effect
* @description Only applies to Relayers approval processes, for other default approval processes it has no effect
* @default undefined
*/
txOverrides?: TxOverrides;
/*
* A note to be included in the deployment.
/**
* @description Key-value pairs to be included in the deployment.
*/
metadata?: DeployMetadata;
/**
* @description The client that made the deployment. For internal use only.
* @warning this variable does not represent the `tx.origin` of the deployment.
* @default 'SDK'
*/
origin?: DeploymentOrigin;
}
export interface DeployRequestLibraries {
[k: `${string}:${string}`]: string;
Expand All @@ -70,6 +76,8 @@ export interface DeploymentUpdateRequest {
address?: Address;
}

export type DeploymentOrigin = 'SDK' | 'Foundry' | 'Hardhat' | 'Remix' | 'Wizard';

export interface DeploymentResponse {
deploymentId: string;
createdAt: string;
Expand Down Expand Up @@ -98,6 +106,7 @@ export interface DeploymentResponse {
[k: string]: string;
};
constructorInputs?: (string | boolean | number)[];
origin?: DeploymentOrigin;
}
export interface BlockExplorerVerification {
status: string;
Expand Down

0 comments on commit 406f8d4

Please sign in to comment.