Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flow update generate object #929

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything in this PR looks good but I don't feel qualified to review this portion

Copy link
Contributor Author

@btspoony btspoony Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it is Flow blockchain dedicated transaction optimization to avoid EVM coa resource is nil.
If we only look at the semantics and not the grammar, i think its intention is clear.


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
Loading