Skip to content

Commit

Permalink
Merge pull request elizaOS#929 from btspoony/tbh/flow-update-generate…
Browse files Browse the repository at this point in the history
…Object

feat: flow update generate object
  • Loading branch information
odilitime authored Dec 11, 2024
2 parents 2864f1c + 7165821 commit 197a119
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
11 changes: 8 additions & 3 deletions packages/plugin-flow/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
composeContext,
Content,
elizaLogger,
generateObjectDEPRECATED,
generateObjectArray,
ModelClass,
type Action,
type ActionExample,
Expand Down Expand Up @@ -87,12 +87,17 @@ 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
const content = recommendations[recommendations.length - 1];

// Validate transfer content
if (!isTransferContent(runtime, content)) {
elizaLogger.error("Invalid content for SEND_COIN action.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<auth(EVM.Call) &EVM.CadenceOwnedAccount>(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<auth(EVM.Withdraw) &EVM.CadenceOwnedAccount>(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<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: storagePath)
?? panic("Could not borrow COA from provided gateway address")
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-flow/src/providers/connector.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-flow/src/providers/wallet.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-flow/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down

0 comments on commit 197a119

Please sign in to comment.