Skip to content

Commit 9ce5217

Browse files
authored
Merge pull request #21 from elizaos-plugins/tcm/fix-build-error
fix: building error
2 parents df6b3a9 + 0601bc4 commit 9ce5217

4 files changed

Lines changed: 123 additions & 17 deletions

File tree

src/actions/bridge.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { HandlerCallback, IAgentRuntime, Memory, State } from '@elizaos/core';
1+
import type { ActionResult, HandlerCallback, IAgentRuntime, Memory, State } from '@elizaos/core';
22
import {
33
composePromptFromState,
44
ModelType,
@@ -634,7 +634,7 @@ export const bridgeAction = {
634634
state?: State,
635635
_options?: Record<string, unknown>,
636636
callback?: HandlerCallback
637-
) => {
637+
): Promise<ActionResult> => {
638638
const walletProvider = await initWalletProvider(runtime);
639639
const action = new BridgeAction(walletProvider);
640640

@@ -655,6 +655,7 @@ export const bridgeAction = {
655655
});
656656

657657
const text = `Successfully bridged ${bridgeOptions.amount} tokens from ${bridgeOptions.fromChain} to ${bridgeOptions.toChain}\n\nTransaction Hash: ${bridgeResp.hash}\nGas optimized and monitored throughout the process`;
658+
const successText = `✅ Successfully bridged ${bridgeOptions.amount} tokens from ${bridgeOptions.fromChain} to ${bridgeOptions.toChain}\n\nTransaction Hash: ${bridgeResp.hash}\nGas optimized and monitored throughout the process`;
658659

659660
await runtime.createMemory(
660661
{
@@ -683,12 +684,29 @@ export const bridgeAction = {
683684
},
684685
});
685686
}
686-
return true;
687+
return {
688+
success: true,
689+
text: successText,
690+
values: {
691+
bridgeSucceeded: true,
692+
gasOptimized: true,
693+
},
694+
data: {
695+
actionName: 'EVM_BRIDGE_TOKENS',
696+
transactionHash: bridgeResp.hash,
697+
fromChain: bridgeOptions.fromChain,
698+
toChain: bridgeOptions.toChain,
699+
token: bridgeOptions.fromToken,
700+
amount: bridgeOptions.amount,
701+
recipient: bridgeResp.to,
702+
},
703+
};
687704
} catch (error) {
688-
logger.error(
689-
'Error in bridge handler:',
690-
error instanceof Error ? error.message : 'Unknown error'
691-
);
705+
const message = error instanceof Error ? error.message : 'Unknown error';
706+
logger.error('Error in bridge handler:', message);
707+
708+
const failureText = `❌ Bridge failed: ${message}\n\nPlease check your balance, network connectivity, and try again.`;
709+
692710
if (callback) {
693711
callback({
694712
text: `Bridge failed: ${error instanceof Error ? error.message : 'Unknown error'}\n\nPlease check your balance, network connectivity, and try again.`,
@@ -698,7 +716,20 @@ export const bridgeAction = {
698716
},
699717
});
700718
}
701-
return false;
719+
return {
720+
success: false,
721+
text: failureText,
722+
values: {
723+
bridgeSucceeded: false,
724+
error: true,
725+
errorMessage: message,
726+
},
727+
data: {
728+
actionName: 'EVM_BRIDGE_TOKENS',
729+
error: message,
730+
},
731+
error: error instanceof Error ? error : new Error(String(error)),
732+
};
702733
}
703734
},
704735
template: bridgeTemplate,

src/actions/swap.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { HandlerCallback, IAgentRuntime, Memory, State } from '@elizaos/core';
1+
import type { ActionResult, HandlerCallback, IAgentRuntime, Memory, State } from '@elizaos/core';
22
import { ModelType, composePromptFromState, elizaLogger, parseKeyValueXml } from '@elizaos/core';
33
import {
44
type ExtendedChain,
@@ -718,7 +718,7 @@ export const swapAction = {
718718
state?: State,
719719
_options?: any,
720720
callback?: HandlerCallback
721-
) => {
721+
): Promise<ActionResult> => {
722722
const walletProvider = await initWalletProvider(runtime);
723723
const action = new SwapAction(walletProvider);
724724

@@ -732,6 +732,8 @@ export const swapAction = {
732732

733733
const swapResp = await action.swap(swapOptions);
734734

735+
const successText = `✅ Successfully swapped ${swapOptions.amount} ${swapOptions.fromToken} for ${swapOptions.toToken} on ${swapOptions.chain}\nTransaction Hash: ${swapResp.hash}`;
736+
735737
// Only create success memory and callback after successful swap
736738
if (callback) {
737739
callback({
@@ -747,7 +749,23 @@ export const swapAction = {
747749
});
748750
}
749751

750-
return true;
752+
return {
753+
success: true,
754+
text: successText,
755+
values: {
756+
swapSucceeded: true,
757+
inputToken: swapOptions.fromToken,
758+
outputToken: swapOptions.toToken,
759+
},
760+
data: {
761+
actionName: 'EVM_SWAP_TOKENS',
762+
transactionHash: swapResp.hash,
763+
chain: swapOptions.chain,
764+
fromToken: swapOptions.fromToken,
765+
toToken: swapOptions.toToken,
766+
amount: swapOptions.amount,
767+
},
768+
};
751769
} catch (error: unknown) {
752770
const errorMessage = error instanceof Error ? error.message : String(error);
753771
console.error('Error in swap handler:', errorMessage);
@@ -791,7 +809,20 @@ export const swapAction = {
791809
},
792810
});
793811
}
794-
return false;
812+
return {
813+
success: false,
814+
text: `❌ ${userFriendlyMessage}`,
815+
values: {
816+
swapSucceeded: false,
817+
error: true,
818+
errorMessage,
819+
},
820+
data: {
821+
actionName: 'EVM_SWAP_TOKENS',
822+
error: errorMessage,
823+
},
824+
error: error instanceof Error ? error : new Error(String(error)),
825+
};
795826
}
796827
},
797828
template: swapTemplate,

src/actions/transfer.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
parseKeyValueXml,
99
composePromptFromState,
1010
elizaLogger,
11+
ActionResult,
1112
} from '@elizaos/core';
1213
import {
1314
type Hex,
@@ -218,7 +219,7 @@ export const transferAction: Action = {
218219
state: State | undefined,
219220
_options: any,
220221
callback?: HandlerCallback
221-
) => {
222+
): Promise<ActionResult> => {
222223
if (!state) {
223224
state = (await runtime.composeState(message)) as State;
224225
}
@@ -241,6 +242,10 @@ export const transferAction: Action = {
241242
? paramOptions.token.toUpperCase()
242243
: chainConfig.nativeCurrency.symbol;
243244

245+
const successText =
246+
`✅ Successfully transferred ${paramOptions.amount} ${tokenSymbol} to ${paramOptions.toAddress}\n` +
247+
`Transaction Hash: ${transferResp.hash}`;
248+
244249
if (callback) {
245250
callback({
246251
text: `Successfully transferred ${paramOptions.amount} ${tokenSymbol} to ${paramOptions.toAddress}\nTransaction Hash: ${transferResp.hash}`,
@@ -254,17 +259,48 @@ export const transferAction: Action = {
254259
},
255260
});
256261
}
257-
return true;
262+
return {
263+
success: true,
264+
text: successText,
265+
values: {
266+
transferSucceeded: true,
267+
tokenTransferred: tokenSymbol,
268+
recipientAddress: transferResp.to,
269+
},
270+
data: {
271+
actionName: 'EVM_TRANSFER_TOKENS',
272+
transactionHash: transferResp.hash,
273+
fromAddress: transferResp.from,
274+
toAddress: transferResp.to,
275+
token: tokenSymbol,
276+
amount: paramOptions.amount,
277+
chain: paramOptions.fromChain,
278+
},
279+
};
258280
} catch (error: unknown) {
259281
const errorMessage = error instanceof Error ? error.message : String(error);
282+
const failureText = `❌ Error transferring tokens: ${errorMessage}`;
260283
console.error('Error during token transfer:', errorMessage);
261284
if (callback) {
262285
callback({
263286
text: `Error transferring tokens: ${errorMessage}`,
264287
content: { error: errorMessage },
265288
});
266289
}
267-
return false;
290+
return {
291+
success: false,
292+
text: failureText,
293+
values: {
294+
transferSucceeded: false,
295+
error: true,
296+
errorMessage,
297+
},
298+
data: {
299+
actionName: 'EVM_TRANSFER_TOKENS',
300+
error: errorMessage,
301+
},
302+
error: error instanceof Error ? error : new Error(String(error)),
303+
};
268304
}
269305
},
270306
validate: async (runtime: IAgentRuntime) => {

src/providers/wallet.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,16 @@ export class WalletProvider {
202202

203203
const genChainsFromRuntime = (runtime: IAgentRuntime): Record<string, Chain> => {
204204
// Get chains from settings - ONLY use configured chains
205-
const configuredChains = (runtime?.character?.settings?.chains?.evm as SupportedChain[]) || [];
206-
205+
const settings = runtime.character?.settings;
206+
const configuredChains =
207+
typeof settings === 'object' &&
208+
settings !== null &&
209+
'chains' in settings &&
210+
typeof settings.chains === 'object' &&
211+
settings.chains !== null &&
212+
'evm' in settings.chains
213+
? (settings.chains.evm as SupportedChain[])
214+
: [];
207215
// If no chains are configured, default to mainnet and base
208216
const chainsToUse = configuredChains.length > 0 ? configuredChains : ['mainnet', 'base'];
209217

0 commit comments

Comments
 (0)