-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
275 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
import { Tool } from './index'; | ||
|
||
test('exists definition', async () => { | ||
// const tool = new Tool({}); | ||
// const definition = tool.getDefinition(); | ||
// expect(definition).toBeInstanceOf(Object); | ||
const tool = new Tool({ name: 'test', privateKey: 'test' }); | ||
const definition = tool.getDefinition(); | ||
expect(definition).toBeInstanceOf(Object); | ||
}); | ||
|
||
test('run definition', async () => { | ||
// const tool = new Tool({}); | ||
// const run_result = await tool.run({ walletId: '0d948159-3b3e-40f8-9001-741e64498fa9' }); | ||
// console.log(run_result); | ||
}, 25000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: '@shinkai_protocol/shinkai-tool-coinbase-get-transactions', | ||
preset: '../../jest.preset.js', | ||
coverageDirectory: '../../coverage/apps/shinkai-tool-coinbase-get-transactions', | ||
passWithNoTests: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@shinkai_protocol/shinkai-tool-coinbase-get-transactions", | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@shinkai_protocol/shinkai-tool-coinbase-get-transactions", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/shinkai-tool-coinbase-get-transactions/src", | ||
"projectType": "library", | ||
"tags": ["tool"], | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-commands", | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"command": "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-coinbase-get-transactions/src/index.ts --outputFolder ./dist/apps/shinkai-tool-coinbase-get-transactions" | ||
}, | ||
"configurations": { | ||
"development": {}, | ||
"production": {} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"apps/shinkai-tool-coinbase-get-transactions/**/*.ts", | ||
"apps/shinkai-tool-coinbase-get-transactions/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/shinkai-tool-coinbase-get-transactions/src/chrome-paths.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module 'chrome-paths' { | ||
const chrome: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare global { | ||
interface Window { | ||
viemClient: any; | ||
viemAccount: any; | ||
ethereum: any; | ||
} | ||
} | ||
|
||
export {}; |
7 changes: 7 additions & 0 deletions
7
apps/shinkai-tool-coinbase-get-transactions/src/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Tool } from './index'; | ||
|
||
test('exists definition', async () => { | ||
// const tool = new Tool({ name: 'test', privateKey: 'test' }); | ||
// const definition = tool.getDefinition(); | ||
// expect(definition).toBeInstanceOf(Object); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder'; | ||
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition'; | ||
import { Coinbase, CoinbaseOptions } from '@coinbase/coinbase-sdk'; | ||
|
||
type Config = { | ||
name: string; | ||
privateKey: string; | ||
walletId: string; | ||
}; | ||
type Params = {}; | ||
type Result = { tableCsv: string; rowsCount: number; columnsCount: number }; | ||
|
||
export class Tool extends BaseTool<Config, Params, Result> { | ||
definition: ToolDefinition<Config, Params, Result> = { | ||
id: 'shinkai-tool-coinbase-get-transactions', | ||
name: 'Shinkai: Coinbase Transactions Getter', | ||
description: | ||
'Tool for getting the transactions of a Coinbase wallet after restoring it', | ||
author: 'Shinkai', | ||
keywords: ['coinbase', 'balance', 'shinkai'], | ||
configurations: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
privateKey: { type: 'string' }, | ||
walletId: { type: 'string' }, | ||
}, | ||
required: ['name', 'privateKey', 'walletId'], | ||
}, | ||
parameters: { | ||
type: 'object', | ||
properties: { | ||
walletId: { type: 'string', nullable: true }, | ||
}, | ||
required: [], | ||
}, | ||
result: { | ||
type: 'object', | ||
properties: { | ||
tableCsv: { type: 'string' }, | ||
rowsCount: { type: 'number' }, | ||
columnsCount: { type: 'number' }, | ||
}, | ||
required: ['tableCsv', 'rowsCount', 'columnsCount'], | ||
}, | ||
}; | ||
|
||
async run(params: Params): Promise<RunResult<Result>> { | ||
const coinbaseOptions: CoinbaseOptions = { | ||
apiKeyName: this.config.name, | ||
privateKey: this.config.privateKey, | ||
}; | ||
const coinbase = new Coinbase(coinbaseOptions); | ||
const user = await coinbase.getDefaultUser(); | ||
|
||
// Prioritize walletId from Params over Config | ||
const walletId = this.config.walletId; | ||
|
||
let wallet = await user.getWallet(walletId); | ||
console.log(`Wallet retrieved: `, wallet.toString()); | ||
|
||
// Retrieve the list of balances for the wallet | ||
let address = await wallet.getDefaultAddress(); | ||
let transactions = (await address?.listTransfers()) ?? []; | ||
|
||
// Convert transactions to CSV format | ||
const headers = [ | ||
'transferId', | ||
'networkId', | ||
'fromAddressId', | ||
'destinationAddressId', | ||
'assetId', | ||
'amount', | ||
'transactionHash', | ||
'transactionLink', | ||
'status', | ||
]; | ||
const rows = transactions.map((tx) => [ | ||
tx.getId(), | ||
tx.getNetworkId(), | ||
tx.getFromAddressId(), | ||
tx.getDestinationAddressId(), | ||
tx.getAssetId(), | ||
tx.getAmount().toString(), | ||
tx.getTransactionHash(), | ||
tx.getTransactionLink(), | ||
tx.getStatus(), | ||
]); | ||
const tableCsv = [headers, ...rows].map((row) => row.join(';')).join('\n'); | ||
|
||
return Promise.resolve({ | ||
data: { | ||
tableCsv, | ||
rowsCount: transactions.length, | ||
columnsCount: headers.length, | ||
}, | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/shinkai-tool-coinbase-get-transactions/tsconfig.app.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["./src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": {}, | ||
"include": ["./src/**/*.ts"] | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/shinkai-tool-coinbase-get-transactions/tsconfig.spec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"], | ||
"lib": ["dom"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.