-
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.
* - feature: replace webpack5 with esbuild for tools bundling * - feature: adapted tools runner to spawn tools backend and use the API * - fix: permissions for shinkai-tools-backend binary * minor fixes * - fix: dom lib in playwright example tsconfig when use jest * stuck with window issue * exp * update * - fix: permissions * - fix: missing chrome * - fix: node version * - feature: bundle tools-backend macos compatible * - fix: missing chrome in CI * - fix: added tests for tool backend project * - fix: missing depends on lint and tests * - fix: single app binary bundler * - fix: ddg search scrapper * - fix: builds concurrency * - fix: lint and test in ci * update aave add coinbase * - fix: stuck tests * - feature: integrated shinkai-viem lib * - fix: adapted to shinkai-viem * - fix: removed unusded file * fix output ethplorer * update * update * buttons * fixes * change conf * - fix: lock merge * - fix: shinkai-viem * - fix: tests * add new tools * - fix: rename aave * fix headless defillama * - fix: tests * - fix: tests * - fix: project names * - fix: project rename * - fix: tests * - fix: add pass with no tests for coinbase projects * - fix: add timeout limit to check * - fix: tests * - fix: removed unused file * - fix: remove headless false * - fix: force exit in jest * temp fix * fix * fix coinbase wallet return * - fix: aave tests * update to support actual mpc * update serversigner type in cb * fix * - fix: tests * - fix: tests * - fix: tests --------- Co-authored-by: Alfredo Gallardo <agallardol@outlook.com>
- Loading branch information
1 parent
3dbbd22
commit d9d0930
Showing
93 changed files
with
47,511 additions
and
316 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
18 changes: 18 additions & 0 deletions
18
apps/shinkai-tool-aave-loan-requester/generate-shinkai-viem-export.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,18 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const shinkaViemPath = path.join( | ||
__dirname, | ||
'../../dist/libs/shinkai-viem/shinkai-viem.js', | ||
); | ||
const shinkaiViemContent = fs.readFileSync(shinkaViemPath, 'utf-8'); | ||
|
||
const outputPath = path.join( | ||
__dirname, | ||
'src/bundled-resources/shinkai-viem.ts', | ||
); | ||
const outputContent = `// autogenerated | ||
export const viemScriptContent = "${Buffer.from(shinkaiViemContent).toString('base64')}"; | ||
`; | ||
|
||
fs.writeFileSync(outputPath, outputContent); |
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,6 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: '@shinkai_protocol/shinkai-tool-aave-loan-requester', | ||
preset: '../../jest.preset.js', | ||
coverageDirectory: '../../coverage/apps/shinkai-tool-aave-loan-requester', | ||
}; |
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-aave-loan-requester", | ||
"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,38 @@ | ||
{ | ||
"name": "@shinkai_protocol/shinkai-tool-aave-loan-requester", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/shinkai-tool-aave-loan-requester/src", | ||
"projectType": "library", | ||
"tags": ["tool"], | ||
"targets": { | ||
"build": { | ||
"dependsOn": [ | ||
{ "projects": "@shinkai_protocol/shinkai-viem", "target": "build" } | ||
], | ||
"executor": "nx:run-commands", | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"commands": [ | ||
"npx ts-node apps/shinkai-tool-aave-loan-requester/generate-shinkai-viem-export.ts", | ||
"npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-aave-loan-requester/src/index.ts --outputFolder ./dist/apps/shinkai-tool-aave-loan-requester" | ||
], | ||
"parallel": false | ||
}, | ||
"configurations": { | ||
"development": {}, | ||
"production": {} | ||
} | ||
}, | ||
"lint": { | ||
"dependsOn": ["build"], | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"apps/shinkai-tool-aave-loan-requester/**/*.ts", | ||
"apps/shinkai-tool-aave-loan-requester/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
apps/shinkai-tool-aave-loan-requester/src/bundled-resources/shinkai-viem.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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 {}; |
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,18 @@ | ||
import { Tool } from '../src/index'; | ||
|
||
test('exists definition', async () => { | ||
const tool = new Tool({}); | ||
const definition = tool.getDefinition(); | ||
expect(definition).toBeInstanceOf(Object); | ||
}); | ||
|
||
test('run definition', async () => { | ||
const tool = new Tool({ | ||
chromePath: process.env?.CHROME_PATH, | ||
}); | ||
const run_result = await tool.run({ | ||
inputValue: '0.005', | ||
assetSymbol: 'ETH', | ||
}); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder'; | ||
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition'; | ||
import * as playwright from 'playwright'; | ||
import * as chromePaths from 'chrome-paths'; | ||
import { createWalletClient, http, parseEther } from 'viem'; | ||
|
||
// Remove later. It's for debugging. | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { viemScriptContent } from './bundled-resources/shinkai-viem'; | ||
|
||
type Config = { | ||
chromePath?: string; | ||
}; | ||
type Params = { | ||
inputValue: string; | ||
assetSymbol: string; | ||
}; | ||
type Result = { | ||
amountProcessed: string; | ||
}; | ||
|
||
// Extend the Window interface to include ethereum | ||
declare global { | ||
interface Window { | ||
ethereum: any; | ||
} | ||
} | ||
|
||
export class Tool extends BaseTool<Config, Params, Result> { | ||
definition: ToolDefinition<Config, Params, Result> = { | ||
id: 'shinkai-tool-aave-loan-requester', | ||
name: 'Shinkai: Aave Loan Requester', | ||
description: | ||
'Tool for requesting a loan on Aave, including selecting assets to supply and borrow with their APYs', | ||
author: 'Shinkai', | ||
keywords: ['aave', 'market', 'extractor', 'shinkai'], | ||
configurations: { | ||
type: 'object', | ||
properties: { | ||
chromePath: { type: 'string', nullable: true }, | ||
}, | ||
required: [], | ||
}, | ||
parameters: { | ||
type: 'object', | ||
properties: { | ||
inputValue: { type: 'string' }, | ||
assetSymbol: { type: 'string' }, | ||
}, | ||
required: ['inputValue', 'assetSymbol'], | ||
}, | ||
result: { | ||
type: 'object', | ||
properties: { | ||
amountProcessed: { type: 'string' }, | ||
}, | ||
required: ['amountProcessed'], | ||
}, | ||
}; | ||
|
||
async run(params: Params): Promise<RunResult<Result>> { | ||
const browser = await playwright['chromium'].launch({ | ||
executablePath: this.config?.chromePath || chromePaths.chrome, | ||
}); | ||
const context = await browser.newContext({ | ||
viewport: { width: 1280, height: 800 }, // Set viewport size | ||
}); | ||
|
||
const page = await context.newPage(); | ||
// await page.goto(params.url); | ||
await page.goto( | ||
'https://staging.aave.com/?marketName=proto_arbitrum_sepolia_v3', | ||
); | ||
|
||
console.log('Viem script loaded'); | ||
|
||
await page.evaluate((scriptContent) => { | ||
const script = document.createElement('script'); | ||
script.textContent = scriptContent; | ||
document.head.appendChild(script); | ||
console.log('Viem script injected'); | ||
}, Buffer.from(viemScriptContent, 'base64').toString('utf-8')); | ||
|
||
// Click the "Opt-out" button | ||
// Wait for the "Opt-out" button to appear and click it | ||
await page.waitForSelector('#rcc-decline-button > p'); | ||
await page.click('#rcc-decline-button > p'); | ||
|
||
// Click the wallet button | ||
await page.waitForSelector('#wallet-button'); | ||
await page.click('#wallet-button'); | ||
|
||
// Click the "Browser wallet" button | ||
const browserWalletButton = page.locator( | ||
'body > div:nth-child(20) > div[class*="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1"] > div[class*="MuiBox-root"] > button:nth-child(2)', | ||
); | ||
|
||
await browserWalletButton.waitFor({ state: 'visible' }); | ||
console.log('Browser wallet button is visible'); | ||
await browserWalletButton.click(); | ||
|
||
const assetSymbolUpper = params.assetSymbol.toUpperCase(); | ||
|
||
// Find the div with data-cy="dashboardSupplyListItem_ETH" and click the first button inside the 5th internal div | ||
const assetSupplyListItem = page.locator( | ||
`div[data-cy="dashboardSupplyListItem_${assetSymbolUpper}"]`, | ||
); | ||
const buttonInFifthDiv = assetSupplyListItem | ||
.locator('div:nth-child(5) button') | ||
.first(); | ||
await buttonInFifthDiv.waitFor({ state: 'visible' }); | ||
await buttonInFifthDiv.click(); | ||
console.log( | ||
`First button inside the 5th internal div for ${assetSymbolUpper} clicked`, | ||
); | ||
|
||
// Input a value of 0.1 into the specified input field | ||
const inputField = page.locator( | ||
'div.MuiModal-root div.MuiPaper-root div.MuiBox-root div.MuiBox-root div.MuiBox-root div.MuiInputBase-root input', | ||
); | ||
await inputField.waitFor({ state: 'visible' }); | ||
await inputField.fill(params.inputValue); | ||
console.log('Input field filled with value 0.1'); | ||
|
||
// Click the button with data-cy="actionButton" | ||
const actionButton = page.locator('button[data-cy="actionButton"]'); | ||
await actionButton.waitFor({ state: 'visible' }); | ||
await actionButton.click(); | ||
console.log('Action button clicked'); | ||
|
||
// Wait for the specified selector with a more flexible approach | ||
await page.waitForSelector( | ||
'body > div.MuiModal-root > div.MuiPaper-root.MuiPaper-elevation.MuiPaper-rounded.MuiPaper-elevation1 > div.MuiBox-root > h2', | ||
); | ||
|
||
// Take a screenshot and save it to ./tmp/ | ||
const screenshotPath = path.join(__dirname, 'tmp', 'screenshot.png'); | ||
await page.screenshot({ path: screenshotPath }); | ||
|
||
await browser.close(); | ||
return Promise.resolve({ | ||
data: { amountProcessed: params.inputValue }, | ||
}); | ||
} | ||
} |
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"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: '@shinkai_protocol/shinkai-tool-aave-state', | ||
preset: '../../jest.preset.js', | ||
coverageDirectory: '../../coverage/apps/shinkai-tool-aave-state', | ||
}; |
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-aave-state", | ||
"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,39 @@ | ||
{ | ||
"name": "@shinkai_protocol/shinkai-tool-aave-state", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/shinkai-tool-aave-state/src", | ||
"projectType": "library", | ||
"tags": ["tool"], | ||
"targets": { | ||
"build": { | ||
"dependsOn": [ | ||
{ "projects": "@shinkai_protocol/shinkai-viem", "target": "build" } | ||
], | ||
"executor": "nx:run-commands", | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"commands": [ | ||
"npx copyfiles --up 3 --verbose dist/libs/shinkai-viem/* apps/shinkai-tool-aave-state/src/bundled-resources/", | ||
"npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-aave-state/src/index.ts --outputFolder ./dist/apps/shinkai-tool-aave-state" | ||
] | ||
}, | ||
"configurations": { | ||
"development": {}, | ||
"production": {} | ||
} | ||
}, | ||
"lint": { | ||
"dependsOn": [ | ||
{ "projects": "@shinkai_protocol/shinkai-viem", "target": "build" } | ||
], | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"apps/shinkai-tool-aave-state/**/*.ts", | ||
"apps/shinkai-tool-aave-state/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.