@venly/wallet-mcp
Version:
Production-ready MCP server enabling AI agents to perform Web3 wallet operations through Venly's blockchain infrastructure. Supports 14+ networks including Ethereum, Polygon, Arbitrum, and stablecoin operations.
652 lines • 23.3 kB
JavaScript
/**
* Pre-built Workflow Templates
*
* Common financial workflow templates for cross-MCP integration
*/
import { WorkflowStepType, WorkflowTriggerType, WebhookEventType } from '../../types/venly.js';
/**
* Invoice to Crypto Payment Workflow
*
* Flow: Stripe invoice → Fiat onramp → Crypto payment → Accounting record
*/
export const INVOICE_TO_CRYPTO_WORKFLOW = {
id: 'invoice-to-crypto-v1',
name: 'Invoice to Crypto Payment',
description: 'Complete workflow from invoice creation to crypto payment with accounting integration',
steps: [
{
id: 'create-stripe-invoice',
name: 'Create Stripe Invoice',
type: WorkflowStepType.EXTERNAL_MCP_CALL,
mcpServer: 'stripe',
action: 'create_invoice',
parameters: {
amount: '{{inputs.amount}}',
currency: '{{inputs.currency}}',
customer_email: '{{inputs.customerEmail}}',
description: '{{inputs.description}}'
},
retryPolicy: {
maxRetries: 3,
baseDelay: 1000,
maxDelay: 5000,
backoffMultiplier: 2
}
},
{
id: 'create-fiat-onramp',
name: 'Create Fiat Onramp',
type: WorkflowStepType.FIAT_CONVERSION,
action: 'create_fiat_onramp',
parameters: {
walletId: '{{inputs.walletId}}',
fiatAmount: '{{inputs.amount}}',
fiatCurrency: '{{inputs.currency}}',
cryptoCurrency: '{{inputs.cryptoCurrency}}',
provider: '{{inputs.fiatProvider}}',
email: '{{inputs.customerEmail}}'
},
dependsOn: ['create-stripe-invoice'],
retryPolicy: {
maxRetries: 2,
baseDelay: 2000,
maxDelay: 10000,
backoffMultiplier: 2
}
},
{
id: 'execute-crypto-payment',
name: 'Execute Crypto Payment',
type: WorkflowStepType.VENLY_TRANSACTION,
action: 'send_token',
parameters: {
walletId: '{{inputs.walletId}}',
to: '{{inputs.recipientAddress}}',
tokenAddress: '{{inputs.tokenAddress}}',
amount: '{{inputs.cryptoAmount}}',
secretType: '{{inputs.network}}'
},
dependsOn: ['create-fiat-onramp'],
conditions: [
{
field: 'stepResults.create-fiat-onramp.status',
operator: 'equals',
value: 'COMPLETED'
}
],
retryPolicy: {
maxRetries: 3,
baseDelay: 5000,
maxDelay: 30000,
backoffMultiplier: 2
}
},
{
id: 'record-accounting-entry',
name: 'Record Accounting Entry',
type: WorkflowStepType.EXTERNAL_MCP_CALL,
mcpServer: 'modern_treasury',
action: 'create_ledger_entry',
parameters: {
amount: '{{inputs.amount}}',
currency: '{{inputs.currency}}',
description: 'Crypto payment for invoice {{stepResults.create-stripe-invoice.id}}',
reference: '{{stepResults.execute-crypto-payment.transactionHash}}'
},
dependsOn: ['execute-crypto-payment'],
parallel: true
},
{
id: 'setup-transaction-monitoring',
name: 'Setup Transaction Monitoring',
type: WorkflowStepType.WEBHOOK_TRIGGER,
action: 'setup_transaction_webhooks',
parameters: {
walletId: '{{inputs.walletId}}',
eventTypes: ['TRANSACTION_CONFIRMED', 'TRANSACTION_FAILED'],
callbackUrl: '{{inputs.webhookUrl}}'
},
dependsOn: ['execute-crypto-payment'],
parallel: true
}
],
triggers: [
{
id: 'manual-trigger',
type: WorkflowTriggerType.MANUAL,
isActive: true
},
{
id: 'webhook-trigger',
type: WorkflowTriggerType.WEBHOOK_EVENT,
webhookEventTypes: [WebhookEventType.TOKEN_RECEIVED],
isActive: true
}
],
metadata: {
version: '1.0.0',
author: 'Venly',
description: 'Automated invoice-to-crypto payment workflow with cross-MCP integration',
tags: ['invoice', 'crypto', 'payment', 'stripe', 'accounting'],
category: 'Payment Processing',
estimatedDuration: 300, // 5 minutes
complexity: 'HIGH',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
inputSchema: {
type: 'object',
required: ['amount', 'currency', 'walletId', 'recipientAddress', 'customerEmail'],
properties: {
amount: { type: 'number', minimum: 0.01 },
currency: { type: 'string', enum: ['USD', 'EUR', 'GBP'] },
walletId: { type: 'string' },
recipientAddress: { type: 'string' },
customerEmail: { type: 'string', format: 'email' },
cryptoCurrency: { type: 'string', default: 'USDC' },
network: { type: 'string', default: 'ETHEREUM' },
fiatProvider: { type: 'string', enum: ['TRANSAK', 'MOONPAY', 'RAMP_NETWORK'], default: 'TRANSAK' },
webhookUrl: { type: 'string', format: 'uri' }
}
},
outputSchema: {
type: 'object',
properties: {
invoiceId: { type: 'string' },
transactionHash: { type: 'string' },
onrampUrl: { type: 'string' },
accountingEntryId: { type: 'string' },
webhookId: { type: 'string' }
}
},
isActive: true
};
/**
* Crypto to Fiat Withdrawal Workflow
*
* Flow: Balance check → Fiat offramp → Bank transfer → Tax reporting
*/
export const CRYPTO_TO_FIAT_WORKFLOW = {
id: 'crypto-to-fiat-v1',
name: 'Crypto to Fiat Withdrawal',
description: 'Complete crypto-to-fiat withdrawal with compliance and tax reporting',
steps: [
{
id: 'verify-balance',
name: 'Verify Wallet Balance',
type: WorkflowStepType.CONDITION_CHECK,
action: 'verify_balance',
parameters: {
conditions: [
{
field: 'inputs.amount',
operator: 'less_than',
value: '{{walletBalance}}'
}
]
}
},
{
id: 'create-fiat-offramp',
name: 'Create Fiat Offramp',
type: WorkflowStepType.FIAT_CONVERSION,
action: 'create_fiat_offramp',
parameters: {
walletId: '{{inputs.walletId}}',
cryptoAmount: '{{inputs.amount}}',
cryptoCurrency: '{{inputs.cryptoCurrency}}',
fiatCurrency: '{{inputs.fiatCurrency}}',
provider: '{{inputs.fiatProvider}}',
email: '{{inputs.email}}',
refundWalletAddress: '{{inputs.walletAddress}}'
},
dependsOn: ['verify-balance'],
retryPolicy: {
maxRetries: 2,
baseDelay: 2000,
maxDelay: 10000,
backoffMultiplier: 2
}
},
{
id: 'setup-transaction-webhooks',
name: 'Setup Transaction Monitoring',
type: WorkflowStepType.WEBHOOK_TRIGGER,
action: 'setup_transaction_webhooks',
parameters: {
walletId: '{{inputs.walletId}}',
eventTypes: ['TRANSACTION_CONFIRMED', 'TOKEN_SENT'],
callbackUrl: '{{inputs.webhookUrl}}',
filters: {
minimumAmount: '{{inputs.amount}}'
}
},
dependsOn: ['create-fiat-offramp'],
parallel: true
},
{
id: 'export-tax-data',
name: 'Export Tax Report',
type: WorkflowStepType.DATA_EXPORT,
action: 'export_financial_data',
parameters: {
walletIds: ['{{inputs.walletId}}'],
format: 'CSV',
dateRange: {
start: '{{inputs.taxYearStart}}',
end: '{{inputs.taxYearEnd}}'
},
includeMetadata: true
},
dependsOn: ['create-fiat-offramp'],
parallel: true
},
{
id: 'record-withdrawal',
name: 'Record Withdrawal Entry',
type: WorkflowStepType.EXTERNAL_MCP_CALL,
mcpServer: 'modern_treasury',
action: 'record_payment',
parameters: {
amount: '{{inputs.fiatAmount}}',
currency: '{{inputs.fiatCurrency}}',
type: 'withdrawal',
description: 'Crypto to fiat withdrawal',
reference: '{{stepResults.create-fiat-offramp.transactionId}}'
},
dependsOn: ['create-fiat-offramp']
}
],
triggers: [
{
id: 'manual-trigger',
type: WorkflowTriggerType.MANUAL,
isActive: true
},
{
id: 'balance-threshold-trigger',
type: WorkflowTriggerType.BALANCE_THRESHOLD,
conditions: [
{
field: 'balance',
operator: 'greater_than',
value: 1000
}
],
isActive: false
}
],
metadata: {
version: '1.0.0',
author: 'Venly',
description: 'Automated crypto-to-fiat withdrawal with compliance reporting',
tags: ['withdrawal', 'fiat', 'crypto', 'tax', 'compliance'],
category: 'Withdrawal Processing',
estimatedDuration: 600, // 10 minutes
complexity: 'MEDIUM',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
inputSchema: {
type: 'object',
required: ['walletId', 'amount', 'cryptoCurrency', 'fiatCurrency', 'email'],
properties: {
walletId: { type: 'string' },
amount: { type: 'number', minimum: 0.01 },
cryptoCurrency: { type: 'string' },
fiatCurrency: { type: 'string', enum: ['USD', 'EUR', 'GBP'] },
email: { type: 'string', format: 'email' },
fiatProvider: { type: 'string', enum: ['TRANSAK', 'MOONPAY', 'RAMP_NETWORK'], default: 'TRANSAK' },
webhookUrl: { type: 'string', format: 'uri' },
taxYearStart: { type: 'string', format: 'date' },
taxYearEnd: { type: 'string', format: 'date' }
}
},
outputSchema: {
type: 'object',
properties: {
offrampUrl: { type: 'string' },
transactionId: { type: 'string' },
webhookId: { type: 'string' },
taxReportId: { type: 'string' },
accountingEntryId: { type: 'string' }
}
},
isActive: true
};
/**
* Portfolio Rebalancing Workflow
*
* Flow: Portfolio analysis → Multi-chain optimization → Transaction execution
*/
export const PORTFOLIO_REBALANCING_WORKFLOW = {
id: 'portfolio-rebalancing-v1',
name: 'Portfolio Rebalancing',
description: 'Automated portfolio rebalancing across multiple chains with optimization',
steps: [
{
id: 'analyze-portfolio',
name: 'Analyze Current Portfolio',
type: WorkflowStepType.VENLY_TRANSACTION,
action: 'get_token_balances',
parameters: {
walletId: '{{inputs.walletId}}'
}
},
{
id: 'calculate-rebalancing',
name: 'Calculate Rebalancing Strategy',
type: WorkflowStepType.CONDITION_CHECK,
action: 'calculate_rebalancing',
parameters: {
conditions: [
{
field: 'portfolioDeviation',
operator: 'greater_than',
value: '{{inputs.rebalanceThreshold}}'
}
]
},
dependsOn: ['analyze-portfolio']
},
{
id: 'optimize-transaction-routing',
name: 'Optimize Transaction Routing',
type: WorkflowStepType.VENLY_TRANSACTION,
action: 'optimize_transaction_routing',
parameters: {
fromToken: '{{rebalancing.fromToken}}',
toToken: '{{rebalancing.toToken}}',
amount: '{{rebalancing.amount}}',
criteria: {
priority: 'COST',
maxSlippage: 2.0,
preferredNetworks: ['ETHEREUM', 'MATIC']
}
},
dependsOn: ['calculate-rebalancing']
},
{
id: 'execute-rebalancing-transactions',
name: 'Execute Rebalancing Transactions',
type: WorkflowStepType.VENLY_TRANSACTION,
action: 'send_token',
parameters: {
walletId: '{{inputs.walletId}}',
transactions: '{{stepResults.optimize-transaction-routing.recommendedRoute}}'
},
dependsOn: ['optimize-transaction-routing'],
retryPolicy: {
maxRetries: 3,
baseDelay: 10000,
maxDelay: 60000,
backoffMultiplier: 2
}
},
{
id: 'setup-portfolio-monitoring',
name: 'Setup Portfolio Monitoring',
type: WorkflowStepType.WEBHOOK_TRIGGER,
action: 'setup_portfolio_webhooks',
parameters: {
walletId: '{{inputs.walletId}}',
eventTypes: ['PORTFOLIO_VALUE_CHANGED'],
callbackUrl: '{{inputs.webhookUrl}}',
filters: {
thresholdPercentage: '{{inputs.rebalanceThreshold}}'
}
},
dependsOn: ['execute-rebalancing-transactions'],
parallel: true
}
],
triggers: [
{
id: 'manual-trigger',
type: WorkflowTriggerType.MANUAL,
isActive: true
},
{
id: 'portfolio-drift-trigger',
type: WorkflowTriggerType.WEBHOOK_EVENT,
webhookEventTypes: [WebhookEventType.PORTFOLIO_VALUE_CHANGED],
conditions: [
{
field: 'portfolioDeviation',
operator: 'greater_than',
value: 5.0
}
],
isActive: true
},
{
id: 'scheduled-rebalancing',
type: WorkflowTriggerType.SCHEDULED,
schedule: '0 0 * * 1', // Weekly on Monday
isActive: false
}
],
metadata: {
version: '1.0.0',
author: 'Venly',
description: 'Automated portfolio rebalancing with multi-chain optimization',
tags: ['portfolio', 'rebalancing', 'optimization', 'multi-chain'],
category: 'Portfolio Management',
estimatedDuration: 900, // 15 minutes
complexity: 'HIGH',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
inputSchema: {
type: 'object',
required: ['walletId', 'targetAllocation', 'rebalanceThreshold'],
properties: {
walletId: { type: 'string' },
targetAllocation: {
type: 'object',
additionalProperties: { type: 'number', minimum: 0, maximum: 100 }
},
rebalanceThreshold: { type: 'number', minimum: 1, maximum: 50, default: 5 },
webhookUrl: { type: 'string', format: 'uri' },
maxSlippage: { type: 'number', minimum: 0.1, maximum: 10, default: 2 },
preferredNetworks: {
type: 'array',
items: { type: 'string' },
default: ['ETHEREUM', 'MATIC']
}
}
},
outputSchema: {
type: 'object',
properties: {
rebalancingTransactions: { type: 'array' },
portfolioAnalysis: { type: 'object' },
optimizationResults: { type: 'object' },
webhookId: { type: 'string' }
}
},
isActive: true
};
/**
* Automated Compliance Workflow
*
* Flow: Transaction monitoring → Report generation → Regulatory filing
*/
export const AUTOMATED_COMPLIANCE_WORKFLOW = {
id: 'automated-compliance-v1',
name: 'Automated Compliance Reporting',
description: 'Automated compliance monitoring and regulatory reporting',
steps: [
{
id: 'setup-compliance-monitoring',
name: 'Setup Compliance Monitoring',
type: WorkflowStepType.WEBHOOK_TRIGGER,
action: 'setup_transaction_webhooks',
parameters: {
walletId: '{{inputs.walletId}}',
eventTypes: ['TRANSACTION_CONFIRMED', 'TOKEN_RECEIVED', 'TOKEN_SENT'],
callbackUrl: '{{inputs.complianceWebhookUrl}}',
filters: {
minimumAmount: '{{inputs.reportingThreshold}}'
}
}
},
{
id: 'generate-transaction-report',
name: 'Generate Transaction Report',
type: WorkflowStepType.DATA_EXPORT,
action: 'export_financial_data',
parameters: {
walletIds: ['{{inputs.walletId}}'],
format: 'CSV',
dateRange: {
start: '{{inputs.reportingPeriodStart}}',
end: '{{inputs.reportingPeriodEnd}}'
},
includeMetadata: true,
filters: {
minAmount: '{{inputs.reportingThreshold}}'
}
},
dependsOn: ['setup-compliance-monitoring']
},
{
id: 'generate-tax-report',
name: 'Generate Tax Report',
type: WorkflowStepType.DATA_EXPORT,
action: 'export_financial_data',
parameters: {
walletIds: ['{{inputs.walletId}}'],
format: 'PDF',
dateRange: {
start: '{{inputs.taxYearStart}}',
end: '{{inputs.taxYearEnd}}'
},
reportType: 'TAX_REPORT',
jurisdiction: '{{inputs.jurisdiction}}'
},
dependsOn: ['generate-transaction-report'],
parallel: true
},
{
id: 'submit-regulatory-filing',
name: 'Submit Regulatory Filing',
type: WorkflowStepType.EXTERNAL_MCP_CALL,
mcpServer: 'compliance_system',
action: 'submit_filing',
parameters: {
reportId: '{{stepResults.generate-tax-report.id}}',
jurisdiction: '{{inputs.jurisdiction}}',
filingType: '{{inputs.filingType}}',
dueDate: '{{inputs.filingDueDate}}'
},
dependsOn: ['generate-tax-report'],
conditions: [
{
field: 'inputs.autoSubmit',
operator: 'equals',
value: true
}
]
}
],
triggers: [
{
id: 'manual-trigger',
type: WorkflowTriggerType.MANUAL,
isActive: true
},
{
id: 'scheduled-monthly-report',
type: WorkflowTriggerType.SCHEDULED,
schedule: '0 0 1 * *', // Monthly on 1st
isActive: true
},
{
id: 'large-transaction-trigger',
type: WorkflowTriggerType.WEBHOOK_EVENT,
webhookEventTypes: [WebhookEventType.TRANSACTION_CONFIRMED],
conditions: [
{
field: 'transactionAmount',
operator: 'greater_than',
value: 10000
}
],
isActive: true
}
],
metadata: {
version: '1.0.0',
author: 'Venly',
description: 'Automated compliance monitoring and regulatory reporting workflow',
tags: ['compliance', 'reporting', 'tax', 'regulatory', 'monitoring'],
category: 'Compliance',
estimatedDuration: 1800, // 30 minutes
complexity: 'MEDIUM',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
inputSchema: {
type: 'object',
required: ['walletId', 'jurisdiction', 'reportingThreshold'],
properties: {
walletId: { type: 'string' },
jurisdiction: { type: 'string', enum: ['US', 'EU', 'UK', 'CA'] },
reportingThreshold: { type: 'number', minimum: 0, default: 10000 },
reportingPeriodStart: { type: 'string', format: 'date' },
reportingPeriodEnd: { type: 'string', format: 'date' },
taxYearStart: { type: 'string', format: 'date' },
taxYearEnd: { type: 'string', format: 'date' },
filingType: { type: 'string', enum: ['ANNUAL', 'QUARTERLY', 'MONTHLY'] },
filingDueDate: { type: 'string', format: 'date' },
autoSubmit: { type: 'boolean', default: false },
complianceWebhookUrl: { type: 'string', format: 'uri' }
}
},
outputSchema: {
type: 'object',
properties: {
webhookId: { type: 'string' },
transactionReportId: { type: 'string' },
taxReportId: { type: 'string' },
filingId: { type: 'string' },
complianceStatus: { type: 'string' }
}
},
isActive: true
};
/**
* All available workflow templates
*/
export const WORKFLOW_TEMPLATES = {
INVOICE_TO_CRYPTO_WORKFLOW,
CRYPTO_TO_FIAT_WORKFLOW,
PORTFOLIO_REBALANCING_WORKFLOW,
AUTOMATED_COMPLIANCE_WORKFLOW
};
/**
* Get workflow template by ID
*/
export function getWorkflowTemplate(templateId) {
return Object.values(WORKFLOW_TEMPLATES).find(template => template.id === templateId);
}
/**
* List all available workflow templates
*/
export function listWorkflowTemplates() {
return Object.values(WORKFLOW_TEMPLATES);
}
/**
* Get workflow templates by category
*/
export function getWorkflowTemplatesByCategory(category) {
return Object.values(WORKFLOW_TEMPLATES).filter(template => template.metadata.category === category);
}
/**
* Get workflow templates by complexity
*/
export function getWorkflowTemplatesByComplexity(complexity) {
return Object.values(WORKFLOW_TEMPLATES).filter(template => template.metadata.complexity === complexity);
}
//# sourceMappingURL=index.js.map