Skip to content

Commit 197a119

Browse files
authoredDec 11, 2024··
Merge pull request #929 from btspoony/tbh/flow-update-generateObject
feat: flow update generate object
2 parents 2864f1c + 7165821 commit 197a119

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed
 

‎packages/plugin-flow/src/actions/transfer.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
composeContext,
33
Content,
44
elizaLogger,
5-
generateObjectDEPRECATED,
5+
generateObjectArray,
66
ModelClass,
77
type Action,
88
type ActionExample,
@@ -87,12 +87,17 @@ export class TransferAction {
8787
});
8888

8989
// Generate transfer content
90-
const content = await generateObjectDEPRECATED({
90+
const recommendations = await generateObjectArray({
9191
runtime,
9292
context: transferContext,
93-
modelClass: ModelClass.SMALL,
93+
modelClass: ModelClass.MEDIUM,
9494
});
9595

96+
elizaLogger.debug("Recommendations", recommendations);
97+
98+
// Convert array to object
99+
const content = recommendations[recommendations.length - 1];
100+
96101
// Validate transfer content
97102
if (!isTransferContent(runtime, content)) {
98103
elizaLogger.error("Invalid content for SEND_COIN action.");

‎packages/plugin-flow/src/assets/cadence/transactions/evm/call.cdc

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ transaction(evmContractAddressHex: String, calldata: String, gasLimit: UInt64, v
1010
prepare(signer: auth(BorrowValue) &Account) {
1111
self.evmAddress = EVM.addressFromString(evmContractAddressHex)
1212

13-
self.coa = signer.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
13+
let storagePath = StoragePath(identifier: "evm")!
14+
let publicPath = PublicPath(identifier: "evm")!
15+
16+
// Reference signer's COA if one exists
17+
let coa = signer.storage.borrow<auth(EVM.Withdraw) &EVM.CadenceOwnedAccount>(from: storagePath)
18+
if coa == nil {
19+
let coa <- EVM.createCadenceOwnedAccount()
20+
signer.storage.save<@EVM.CadenceOwnedAccount>(<-coa, to: storagePath)
21+
let addressableCap = signer.capabilities.storage.issue<&EVM.CadenceOwnedAccount>(storagePath)
22+
signer.capabilities.unpublish(publicPath)
23+
signer.capabilities.publish(addressableCap, at: publicPath)
24+
}
25+
26+
self.coa = signer.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: storagePath)
1427
?? panic("Could not borrow COA from provided gateway address")
1528
}
1629

‎packages/plugin-flow/src/providers/connector.provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class FlowConnectorProvider {
7272
constructor(private readonly instance: FlowConnector) {}
7373

7474
getConnectorStatus(runtime: IAgentRuntime): string {
75-
let output = `${runtime.character.name}[${runtime.character.id ?? 0}] Connected to\n`;
75+
let output = `Now user<${runtime.character.name}> connected to\n`;
7676
output += `Flow network: ${this.instance.network}\n`;
7777
output += `Flow Endpoint: ${this.instance.rpcEndpoint}\n`;
7878
return output;

‎packages/plugin-flow/src/providers/wallet.provider.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ const flowWalletProvider: Provider = {
232232
elizaLogger.error("Invalid account info");
233233
return null;
234234
}
235-
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`;
235+
let output = `Here is user<${runtime.character.name}>'s wallet status:\n`;
236+
output += `Flow wallet address: ${walletProvider.address}\n`;
237+
output += `FLOW balance: ${info.balance} FLOW\n`;
238+
output += `Flow wallet's COA(EVM) address: ${info.coaAddress || "unknown"}\n`;
239+
output += `FLOW balance in COA(EVM) address: ${info.coaBalance ?? 0} FLOW`;
240+
return output;
236241
} catch (error) {
237242
elizaLogger.error("Error in Flow wallet provider:", error.message);
238243
return null;

‎packages/plugin-flow/src/templates/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Extract the following information about the requested transfer:
88
- 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:
99
1. For Cadence resource identifier, the field should be "A.1654653399040a61.ContractName"
1010
2. For ERC20 contract address, the field should be "0xe6ffc15a5bde7dd33c127670ba2b9fcb82db971a"
11-
- Field "amount": Amount to transfer
11+
- Field "amount": Amount to transfer, it should be a number or a string. Examples for this field:
12+
1. "1000"
13+
2. 1000
1214
- Field "to": Recipient wallet address, can be EVM address or Cadence address. Examples for this field:
1315
1. Cadence address: "0x1654653399040a61"
1416
2. EVM address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
@@ -21,7 +23,7 @@ Respond with a JSON markdown block containing only the extracted values. Use nul
2123
\`\`\`json
2224
{
2325
"token": string | null
24-
"amount": string | null,
26+
"amount": number | string | null,
2527
"to": string | null,
2628
"matched": boolean
2729
}

0 commit comments

Comments
 (0)
Please sign in to comment.