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

Add new bot metadata fields to cli #320

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 21 additions & 16 deletions cli/commands/info/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,29 @@ describe("info", () => {
}

const mockIpfsManifest = {
"manifest":{
"from":"0x123456",
"name":"Compound Liquidatable Positions Monitor",
"agentId":"Compound Liquidatable Positions Monitor",
"agentIdHash":"0x3c61101f1d349661298a58ba59a58fbce5a3626c5c7af10b091796969e0d6c59",
"version":"0.0.1",
"timestamp":"Fri, 20 May 2022 15:54:56 GMT",
"imageReference":"bafybeib5kmox5r2wpre3tgkfgfr76tm4qascagmqvod2wcojxrqmgyxfp4@sha256:2fcfede6f821f4f14e745598fd71b2201471517acd345f7b8f0cd424d35b441a",
"documentation":"QmQXZvBdZ4eMtCefNXYMRwQ7UJbgW74EqrMv9wS9hoSXV7",
"repository":"https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"projects":[
"compound_v2"
"manifest": {
"from": "0x123456",
"name": "Compound Liquidatable Positions Monitor",
"displayName": "Compound Liquidatable Positions Monitor",
"description": "Compound Liquidatable Positions Monitor description",
"longDescription": "Compound Liquidatable Positions Monitor long description",
"agentId": "Compound Liquidatable Positions Monitor",
"agentIdHash": "0x3c61101f1d349661298a58ba59a58fbce5a3626c5c7af10b091796969e0d6c59",
"version": "0.0.1",
"timestamp": "Fri, 20 May 2022 15:54:56 GMT",
"imageReference": "bafybeib5kmox5r2wpre3tgkfgfr76tm4qascagmqvod2wcojxrqmgyxfp4@sha256:2fcfede6f821f4f14e745598fd71b2201471517acd345f7b8f0cd424d35b441a",
"documentation": "QmQXZvBdZ4eMtCefNXYMRwQ7UJbgW74EqrMv9wS9hoSXV7",
"repository": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"licenseUrl": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"promoUrl": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"projects": [
"compound_v2"
],
"chainIds":[
1
"chainIds": [
1
],
"publishedFrom":"Forta Explorer 0.0.2"
} as IpfsManifestData
"publishedFrom": "Forta Explorer 0.0.2"
} as IpfsManifestData
} as IpfsData

const mockLogOne: PolyscanLog = {
Expand Down
13 changes: 11 additions & 2 deletions cli/commands/publish/upload.manifest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ describe("uploadManifest", () => {
} as any
const mockAddToIpfs = jest.fn()
const mockAgentName = "agentName"
const mockAgentDisplayName = "agent name"
const mockDescription = "some description"
const mockLongDescription = "some long description"
const mockAgentId = "0xagentId"
const mockVersion = "0.1"
const mockDocumentation = "README.md"
const mockRepository = "github.com/myrepository"
const mockLicenseUrl = "github.com/myrepository"
const mockPromoUrl = "github.com/myrepository"
const mockImageRef = "123abc"
const mockPrivateKey = "0xabcd"
const mockCliVersion = "0.2"
Expand Down Expand Up @@ -56,7 +60,8 @@ describe("uploadManifest", () => {

beforeAll(() => {
uploadManifest = provideUploadManifest(
mockFilesystem, mockAddToIpfs, mockAgentName, mockDescription, mockAgentId, mockVersion, mockDocumentation, mockRepository, mockCliVersion, mockChainIds, mockChainSettings
mockFilesystem, mockAddToIpfs, mockAgentName, mockAgentDisplayName,
mockDescription, mockLongDescription, mockAgentId, mockVersion, mockDocumentation, mockRepository, mockLicenseUrl, mockPromoUrl, mockCliVersion, mockChainIds, mockChainSettings
)
})

Expand Down Expand Up @@ -103,14 +108,18 @@ describe("uploadManifest", () => {
const mockManifest = {
from: new Wallet(mockPrivateKey).address,
name: mockAgentName,
displayName: mockAgentDisplayName,
description: mockDescription,
longDescription: mockLongDescription,
agentId: mockAgentName,
agentIdHash: mockAgentId,
version: mockVersion,
timestamp: systemTime.toUTCString(),
imageReference: mockImageRef,
documentation: mockDocumentationRef,
repository: mockRepository,
licenseUrl: mockLicenseUrl,
promoUrl: mockPromoUrl,
chainIds: mockChainIds,
publishedFrom: `Forta CLI ${mockCliVersion}`,
chainSettings: formattedMockChainSettings
Expand All @@ -129,7 +138,7 @@ describe("uploadManifest", () => {
expect(mockFilesystem.readFileSync).toHaveBeenCalledWith(mockDocumentation, 'utf8')
expect(mockAddToIpfs).toHaveBeenCalledTimes(2)
expect(mockAddToIpfs).toHaveBeenNthCalledWith(1, mockDocumentationFile)
const signingKey = new ethers.utils.SigningKey(mockPrivateKey)
const signingKey = new ethers.utils.SigningKey(mockPrivateKey)
const signature = ethers.utils.joinSignature(signingKey.signDigest(keccak256(JSON.stringify(mockManifest))))
expect(mockAddToIpfs).toHaveBeenNthCalledWith(2, JSON.stringify({ manifest: mockManifest, signature }))
jest.useRealTimers()
Expand Down
34 changes: 23 additions & 11 deletions cli/commands/publish/upload.manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,39 @@ export type ChainSettings = { [id: string]: ChainSetting }
type Manifest = {
from: string,
name: string,
displayName?: string,
description: string,
longDescription?: string,
agentId: string,
agentIdHash: string,
version: string,
timestamp: string,
imageReference: string,
documentation: string,
repository?: string,
licenseUrl?: string,
promoUrl?: string,
chainIds: number[],
publishedFrom: string,
chainSettings?: ChainSettings
}

export default function provideUploadManifest(
filesystem: typeof fs,
addToIpfs: AddToIpfs,
agentName: string,
description: string,
agentId: string,
version: string,
documentation: string,
repository: string,
cliVersion: string,
chainIds: number[],
chainSettings?: ChainSettings
filesystem: typeof fs,
addToIpfs: AddToIpfs,
agentName: string,
agentDisplayName: string,
description: string,
longDescription: string,
agentId: string,
version: string,
documentation: string,
repository: string,
licenseUrl: string,
promoUrl: string,
cliVersion: string,
chainIds: number[],
chainSettings?: ChainSettings
): UploadManifest {
assertExists(filesystem, 'filesystem')
assertExists(addToIpfs, 'addToIpfs')
Expand Down Expand Up @@ -69,14 +77,18 @@ export default function provideUploadManifest(
const manifest: Manifest = {
from: new Wallet(privateKey).address,
name: agentName,
aomerk marked this conversation as resolved.
Show resolved Hide resolved
displayName: agentDisplayName,
aomerk marked this conversation as resolved.
Show resolved Hide resolved
description,
longDescription: longDescription,
agentId: agentName,
agentIdHash: agentId,
version,
timestamp: new Date().toUTCString(),
imageReference,
documentation: documentationReference,
repository,
licenseUrl: licenseUrl,
promoUrl: promoUrl,
chainIds,
publishedFrom: `Forta CLI ${cliVersion}`,
chainSettings: formatChainSettings(chainSettings),
Expand Down
4 changes: 4 additions & 0 deletions cli/di.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export default function configureContainer(args: any = {}) {
}
}).singleton(),
agentName: asFunction((packageJson: any) => packageJson.name).singleton(),
agentDisplayName: asFunction((packageJson: any) => packageJson.displayName).singleton(),
description: asFunction((packageJson: any) => packageJson.description).singleton(),
longDescription: asFunction((packageJson: any) => packageJson.longDescription).singleton(),
agentId: asFunction((args: any, fortaConfig: FortaConfig, agentName: string) => {
return args.agentId || fortaConfig.agentId || keccak256(agentName)
}).singleton(),
Expand Down Expand Up @@ -167,6 +169,8 @@ export default function configureContainer(args: any = {}) {
}
return undefined
}).singleton(),
licenseUrl: asFunction((packageJson: any) => packageJson.licenseUrl).singleton(),
promoUrl: asFunction((packageJson: any) => packageJson.promoUrl).singleton(),
keyfileName: asFunction((fortaConfig: FortaConfig) => {
return fortaConfig.keyfile
}),
Expand Down
41 changes: 23 additions & 18 deletions cli/utils/ipfs/get.from.ipfs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ import { formatDate, formatIpfsData } from "../../commands/info";
import provideGetFromIpfs, { GetFromIpfs, IpfsData, IpfsManifestData } from "./get.from.ipfs";

const mockIpfsData = {
"manifest":{
"from":"0x123456",
"name":"Compound Liquidatable Positions Monitor",
"agentId":"Compound Liquidatable Positions Monitor",
"agentIdHash":"0x3c61101f1d349661298a58ba59a58fbce5a3626c5c7af10b091796969e0d6c59",
"version":"0.0.1",
"timestamp":"Fri, 20 May 2022 15:54:56 GMT",
"imageReference":"bafybeib5kmox5r2wpre3tgkfgfr76tm4qascagmqvod2wcojxrqmgyxfp4@sha256:2fcfede6f821f4f14e745598fd71b2201471517acd345f7b8f0cd424d35b441a",
"documentation":"QmQXZvBdZ4eMtCefNXYMRwQ7UJbgW74EqrMv9wS9hoSXV7",
"repository":"https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"projects":[
"compound_v2"
],
"chainIds":[
1
],
"publishedFrom":"Forta Explorer 0.0.2"
} as IpfsManifestData
"manifest": {
"from": "0x123456",
"name": "Compound Liquidatable Positions Monitor",
"displayName": "Compound Liquidatable Positions Monitor",
"agentId": "Compound Liquidatable Positions Monitor",
"description": "Test description",
"longDescription": "Test long description",
"agentIdHash": "0x3c61101f1d349661298a58ba59a58fbce5a3626c5c7af10b091796969e0d6c59",
"version": "0.0.1",
"timestamp": "Fri, 20 May 2022 15:54:56 GMT",
"imageReference": "bafybeib5kmox5r2wpre3tgkfgfr76tm4qascagmqvod2wcojxrqmgyxfp4@sha256:2fcfede6f821f4f14e745598fd71b2201471517acd345f7b8f0cd424d35b441a",
"documentation": "QmQXZvBdZ4eMtCefNXYMRwQ7UJbgW74EqrMv9wS9hoSXV7",
"repository": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"licenseUrl": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"promoUrl": "https://github.com/arbitraryexecution/compound-monitoring/tree/main/liquidation-monitor",
"projects": [
"compound_v2"
],
"chainIds": [
1
],
"publishedFrom": "Forta Explorer 0.0.2"
} as IpfsManifestData
}


Expand Down
5 changes: 5 additions & 0 deletions cli/utils/ipfs/get.from.ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ export interface IpfsData {

export interface IpfsManifestData {
name: string,
displayName: string,
aomerk marked this conversation as resolved.
Show resolved Hide resolved
from: string,
description: string,
longDescription: string
agentId: string,
version: string,
imageReference: string,
agentIdHash: string,
timestamp: string,
repository: string,
licenseUrl: string,
promoUrl: string,
chainIds: number[],
publishedFrom: string,
documentation: string
Expand Down