Skip to content

Commit

Permalink
Merge branch 'develop' into fix-plugin-icp
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 authored Jan 31, 2025
2 parents cba727d + 32cb314 commit 8a73db6
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/docs/packages/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,5 +753,5 @@ class CustomDatabaseAdapter extends DatabaseAdapter {

## Related Resources

- [Database Schema Reference](/api)
- [Error Handling](../../packages/core)
- [Database Schema Reference](/api/classes/DatabaseAdapter/)
- [Error Handling](../../packages/core/#error-handling)
2 changes: 1 addition & 1 deletion docs/docs/packages/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,4 @@ async processMessage(message) {

## Related Resources

- [Error Handling](../../packages/core)
- [Error Handling](../../packages/core/#error-handling)
2 changes: 1 addition & 1 deletion docs/docs/packages/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ Agent: "I'll get the inference now..."
Agent: "Inference provided by Allora Network on topic ETH 5min Prediction (ID: 13): 3393.364326646801085508"
```
For detailed information and additional implementation examples, please refer to the [Allora-Eliza integration docs](https://docs.allora.network/marketplace/integrations/eliza-os).
For detailed information and additional implementation examples, please refer to the [Allora-Eliza integration docs](https://docs.allora.network/marketplace/integrations/eliza-os/implementation).
### 13. Form Plugin (`@elizaos/plugin-form`)
Expand Down
41 changes: 41 additions & 0 deletions packages/plugin-avail/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "error"
},
"suspicious": {
"noExplicitAny": "error"
},
"style": {
"useConst": "error",
"useImportType": "off"
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "es5"
}
},
"files": {
"ignore": [
"dist/**/*",
"extra/**/*",
"node_modules/**/*"
]
}
}
9 changes: 7 additions & 2 deletions packages/plugin-avail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
"tsup": "8.3.5",
"@polkadot/types": "^10.11.3",
"vitest": "^2.1.8",
"@vitest/coverage-v8": "^2.1.8"
"@vitest/coverage-v8": "^2.1.8",
"@biomejs/biome": "1.9.4"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"test:watch": "vitest watch",
"test:coverage": "vitest run --coverage"
"test:coverage": "vitest run --coverage",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write ."
}
}
25 changes: 13 additions & 12 deletions packages/plugin-avail/src/actions/submitData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getKeyringFromSeed,
} from "avail-js-sdk";
import type { H256 } from "@polkadot/types/interfaces/runtime";
import { ISubmittableResult } from "@polkadot/types/types";
import type { ISubmittableResult } from "@polkadot/types/types";

export interface DataContent extends Content {
data: string;
Expand Down Expand Up @@ -79,15 +79,16 @@ export default {
elizaLogger.log("Starting SUBMIT_DATA handler...");

// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

// Compose transfer context
const submitDataContext = composeContext({
state,
state: currentState,
template: submitDataTemplate,
});

Expand All @@ -112,7 +113,8 @@ export default {
// }
if (content.data != null) {
try {
const SEED = runtime.getSetting("AVAIL_SEED")!;
const SEED = runtime.getSetting("AVAIL_SEED");
if (!SEED) throw new Error("AVAIL_SEED not set");
//const ACCOUNT = runtime.getSetting("AVAIL_ADDRESS")!;
const ENDPOINT = runtime.getSetting("AVAIL_RPC_URL");
const APP_ID = runtime.getSetting("AVAIL_APP_ID");
Expand All @@ -134,7 +136,7 @@ export default {
`);

//submit data
const txResult:ISubmittableResult = await new Promise(
const txResult:ISubmittableResult = await new Promise<ISubmittableResult>(
(res) => {
api.tx.dataAvailability
.submitData(data)
Expand All @@ -146,7 +148,7 @@ export default {
`Tx status: ${result.status}`
);
if (result.isFinalized || result.isError) {
res(result as any);
res(result);
}
}
);
Expand All @@ -155,12 +157,12 @@ export default {

// Rejected Transaction handling
if (txResult.isError) {
console.log(`Transaction was not executed`);
console.log('Transaction was not executed');
}

// Failed Transaction handling
const error = txResult.dispatchError;
if (error != undefined) {
if (error !== undefined) {
if (error.isModule) {
const decoded = api.registry.findMetaError(
error.asModule
Expand All @@ -173,8 +175,7 @@ export default {
}

elizaLogger.success(
"Data submitted successfully! tx: \n " +
`Tx Hash: ${txResult.txHash as H256}, Block Hash: ${txResult.status.asFinalized as H256}`
`Data submitted successfully! tx: \nTx Hash: ${txResult.txHash as H256}, Block Hash: ${txResult.status.asFinalized as H256}`
);
if (callback) {
callback({
Expand Down
35 changes: 16 additions & 19 deletions packages/plugin-avail/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ export default {
elizaLogger.log("Starting SEND_TOKEN handler...");

// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

// Compose transfer context
const transferContext = composeContext({
state,
state: currentState,
template: transferTemplate,
});

Expand All @@ -126,7 +127,8 @@ export default {

if (content.amount != null && content.recipient != null) {
try {
const SEED = runtime.getSetting("AVAIL_SEED")!;
const SEED = runtime.getSetting("AVAIL_SEED");
if (!SEED) throw new Error("AVAIL_SEED not set");
//const PUBLIC_KEY = runtime.getSetting("AVAIL_ADDRESS")!;
const ENDPOINT = runtime.getSetting("AVAIL_RPC_URL");

Expand All @@ -136,15 +138,13 @@ export default {
const decimals = getDecimals(api);
const amount = formatNumberToBalance(content.amount, decimals);

const oldBalance: any = await api.query.system.account(
content.recipient
);
const oldBalance = await api.query.system.account(content.recipient);
elizaLogger.log(
`Balance before the transfer call: ${oldBalance["data"]["free"].toHuman()}`
`Balance before the transfer call: ${oldBalance.toString()}`
);

// Transaction call
const txResult:ISubmittableResult = await new Promise(
const txResult:ISubmittableResult = await new Promise<ISubmittableResult>(
(res) => {
api.tx.balances
.transferKeepAlive(content.recipient, amount)
Expand All @@ -156,7 +156,7 @@ export default {
`Tx status: ${result.status}`
);
if (result.isFinalized || result.isError) {
res(result as any);
res(result);
}
}
);
Expand All @@ -166,8 +166,8 @@ export default {
// Error handling
const error = txResult.dispatchError;
if (txResult.isError) {
elizaLogger.log(`Transaction was not executed`);
} else if (error != undefined) {
elizaLogger.log("Transaction was not executed");
} else if (error !== undefined) {
if (error.isModule) {
const decoded = api.registry.findMetaError(
error.asModule
Expand All @@ -181,16 +181,13 @@ export default {
}
}

const newBalance: any = await api.query.system.account(
content.recipient
);
const newBalance = await api.query.system.account(content.recipient);
elizaLogger.log(
`Balance after the transfer call: ${newBalance["data"]["free"].toHuman()}`
`Balance after the transfer call: ${newBalance.toString()}`
);

elizaLogger.success(
"Transfer completed successfully! tx: \n " +
`Tx Hash: ${txResult.txHash as H256}, Block Hash: ${txResult.status.asFinalized as H256}`
`Transfer completed successfully! tx: \nTx Hash: ${txResult.txHash as H256}, Block Hash: ${txResult.status.asFinalized as H256}`
);
if (callback) {
callback({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class EmailAutomationService extends Service {
return {
memory,
state,
metadata: state?.metadata || {},
metadata: state?.metadata as Record<string, unknown>,
timestamp: new Date(),
conversationId: memory.id || ''
};
Expand Down Expand Up @@ -390,4 +390,4 @@ export class EmailAutomationService extends Service {
// Default platform
return 'unknown';
}
}
}

0 comments on commit 8a73db6

Please sign in to comment.