From 4af13464bc0fcee4be965813cc77e55eb25843bf Mon Sep 17 00:00:00 2001 From: Tang Bo Hao Date: Sat, 7 Dec 2024 16:41:16 +0800 Subject: [PATCH 1/4] feat: update provider output --- packages/plugin-flow/src/providers/connector.provider.ts | 2 +- packages/plugin-flow/src/providers/wallet.provider.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/plugin-flow/src/providers/connector.provider.ts b/packages/plugin-flow/src/providers/connector.provider.ts index f0a7e3913d..7d81fe3c87 100644 --- a/packages/plugin-flow/src/providers/connector.provider.ts +++ b/packages/plugin-flow/src/providers/connector.provider.ts @@ -72,7 +72,7 @@ export class FlowConnectorProvider { constructor(private readonly instance: FlowConnector) {} getConnectorStatus(runtime: IAgentRuntime): string { - let output = `${runtime.character.name}[${runtime.character.id ?? 0}] Connected to\n`; + let output = `Now user<${runtime.character.name}> connected to\n`; output += `Flow network: ${this.instance.network}\n`; output += `Flow Endpoint: ${this.instance.rpcEndpoint}\n`; return output; diff --git a/packages/plugin-flow/src/providers/wallet.provider.ts b/packages/plugin-flow/src/providers/wallet.provider.ts index 7e6ba65bf0..1d300bafa7 100644 --- a/packages/plugin-flow/src/providers/wallet.provider.ts +++ b/packages/plugin-flow/src/providers/wallet.provider.ts @@ -232,7 +232,12 @@ const flowWalletProvider: Provider = { elizaLogger.error("Invalid account info"); return null; } - return `Flow Wallet Address: ${walletProvider.address}\nBalance: ${info.balance} FLOW\nFlow COA(EVM) Address: ${info.coaAddress || "unknown"}\nFLOW COA(EVM) Balance: ${info.coaBalance ?? 0} FLOW`; + let output = `Here is user<${runtime.character.name}>'s wallet status:\n`; + output += `Flow wallet address: ${walletProvider.address}\n`; + output += `FLOW balance: ${info.balance} FLOW\n`; + output += `Flow wallet's COA(EVM) address: ${info.coaAddress || "unknown"}\n`; + output += `FLOW balance in COA(EVM) address: ${info.coaBalance ?? 0} FLOW`; + return output; } catch (error) { elizaLogger.error("Error in Flow wallet provider:", error.message); return null; From 68c260003a7fa7ea8453b398c9744ef936a2c2ec Mon Sep 17 00:00:00 2001 From: Tang Bo Hao Date: Sat, 7 Dec 2024 21:31:13 +0800 Subject: [PATCH 2/4] feat: improve prompt --- packages/plugin-flow/src/actions/transfer.ts | 5 +++++ packages/plugin-flow/src/templates/index.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/plugin-flow/src/actions/transfer.ts b/packages/plugin-flow/src/actions/transfer.ts index 88366028b5..c3f3dcdcb8 100644 --- a/packages/plugin-flow/src/actions/transfer.ts +++ b/packages/plugin-flow/src/actions/transfer.ts @@ -93,6 +93,11 @@ export class TransferAction { modelClass: ModelClass.SMALL, }); + // Convert array to object + if (Array.isArray(content)) { + content = content[content.length - 1]; + } + // Validate transfer content if (!isTransferContent(runtime, content)) { elizaLogger.error("Invalid content for SEND_COIN action."); diff --git a/packages/plugin-flow/src/templates/index.ts b/packages/plugin-flow/src/templates/index.ts index 1f6a3878e0..66b27b1854 100644 --- a/packages/plugin-flow/src/templates/index.ts +++ b/packages/plugin-flow/src/templates/index.ts @@ -8,7 +8,9 @@ Extract the following information about the requested transfer: - Field "token": Cadence Resource Identifier or ERC20 contract address (if not native token). this field should be null if the token is native token: $FLOW or FLOW. Examples for this field: 1. For Cadence resource identifier, the field should be "A.1654653399040a61.ContractName" 2. For ERC20 contract address, the field should be "0xe6ffc15a5bde7dd33c127670ba2b9fcb82db971a" -- Field "amount": Amount to transfer +- Field "amount": Amount to transfer, it should be a number or a string. Examples for this field: + 1. "1000" + 2. 1000 - Field "to": Recipient wallet address, can be EVM address or Cadence address. Examples for this field: 1. Cadence address: "0x1654653399040a61" 2. EVM address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" @@ -21,7 +23,7 @@ Respond with a JSON markdown block containing only the extracted values. Use nul \`\`\`json { "token": string | null - "amount": string | null, + "amount": number | string | null, "to": string | null, "matched": boolean } From 600cc10f47895b99941c485dbe8f56c547ce6da3 Mon Sep 17 00:00:00 2001 From: Tang Bo Hao Date: Sat, 7 Dec 2024 23:27:26 +0800 Subject: [PATCH 3/4] feat: update evm transaction call cdc file --- .../src/assets/cadence/transactions/evm/call.cdc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/plugin-flow/src/assets/cadence/transactions/evm/call.cdc b/packages/plugin-flow/src/assets/cadence/transactions/evm/call.cdc index 1f7c60143b..44fffbcf7f 100644 --- a/packages/plugin-flow/src/assets/cadence/transactions/evm/call.cdc +++ b/packages/plugin-flow/src/assets/cadence/transactions/evm/call.cdc @@ -10,7 +10,20 @@ transaction(evmContractAddressHex: String, calldata: String, gasLimit: UInt64, v prepare(signer: auth(BorrowValue) &Account) { self.evmAddress = EVM.addressFromString(evmContractAddressHex) - self.coa = signer.storage.borrow(from: /storage/evm) + let storagePath = StoragePath(identifier: "evm")! + let publicPath = PublicPath(identifier: "evm")! + + // Reference signer's COA if one exists + let coa = signer.storage.borrow(from: storagePath) + if coa == nil { + let coa <- EVM.createCadenceOwnedAccount() + signer.storage.save<@EVM.CadenceOwnedAccount>(<-coa, to: storagePath) + let addressableCap = signer.capabilities.storage.issue<&EVM.CadenceOwnedAccount>(storagePath) + signer.capabilities.unpublish(publicPath) + signer.capabilities.publish(addressableCap, at: publicPath) + } + + self.coa = signer.storage.borrow(from: storagePath) ?? panic("Could not borrow COA from provided gateway address") } From e508f8d72a6187302886be0ba2097307434f227b Mon Sep 17 00:00:00 2001 From: Tang Bo Hao Date: Mon, 9 Dec 2024 14:09:34 +0800 Subject: [PATCH 4/4] feat: use generateObjectArray instead of generateObjectDEPRECATED --- packages/plugin-flow/src/actions/transfer.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/plugin-flow/src/actions/transfer.ts b/packages/plugin-flow/src/actions/transfer.ts index c3f3dcdcb8..bc04dcfec3 100644 --- a/packages/plugin-flow/src/actions/transfer.ts +++ b/packages/plugin-flow/src/actions/transfer.ts @@ -2,7 +2,7 @@ import { composeContext, Content, elizaLogger, - generateObjectDEPRECATED, + generateObjectArray, ModelClass, type Action, type ActionExample, @@ -87,16 +87,16 @@ export class TransferAction { }); // Generate transfer content - const content = await generateObjectDEPRECATED({ + const recommendations = await generateObjectArray({ runtime, context: transferContext, - modelClass: ModelClass.SMALL, + modelClass: ModelClass.MEDIUM, }); + elizaLogger.debug("Recommendations", recommendations); + // Convert array to object - if (Array.isArray(content)) { - content = content[content.length - 1]; - } + const content = recommendations[recommendations.length - 1]; // Validate transfer content if (!isTransferContent(runtime, content)) {