Skip to content

Commit dc5b52a

Browse files
Merge pull request #3 from GabrielCartier/feature/create-vault
Feature/create vault
2 parents 4dc4934 + 45baf81 commit dc5b52a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3392
-243
lines changed

backend/.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ next-env.d.ts
4242
**/*.log
4343
package-lock.json
4444
**/*.bun
45+
46+
node_modules
47+
.env
48+
49+
# Hardhat files
50+
/cache
51+
/artifacts
52+
53+
# TypeChain files
54+
/typechain
55+
/typechain-types
56+
57+
# solidity-coverage files
58+
/coverage
59+
/coverage.json
60+
61+
# Hardhat Ignition default folder for deployments against a local node
62+
ignition/deployments/chain-31337

backend/README.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@ To start the development server run:
66
bun run dev
77
```
88

9-
## Curl
9+
## Curl for creating a vault
1010

1111
curl -X POST http://localhost:3000/message \
1212
-H "Content-Type: application/json" \
1313
-d '{
1414
"agentId": "416659f6-a8ab-4d90-87b5-fd5635ebe37d",
15-
"text": "deposit 0.01 S (0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38)",
15+
"text": "create a vault for me",
1616
"roomId": "default-room",
17-
"userId": "user",
18-
"userName": "User",
19-
"content": {
20-
"amount": "10000000000000000",
21-
"tokenAddress": "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38",
22-
"siloAddress": "0xf55902DE87Bd80c6a35614b48d7f8B612a083C12",
23-
"userAddress": "0x2D9b0C8529f49CB9561ba21f87AA77886e32858E"
24-
}
17+
"userId": "12dea96f-ec20-0935-a6ab-75692c994959",
18+
"walletAddress": "0x1234567890thisisatestabcdef12345678"
2519
}'
26-

backend/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
"zod": "^3.24.2"
1919
},
2020
"devDependencies": {
21+
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
2122
"@types/yargs": "^17.0.33",
22-
"bun-types": "latest"
23+
"bun-types": "latest",
24+
"dotenv": "^16.4.7",
25+
"hardhat": "^2.22.19"
2326
},
2427
"engines": {
2528
"node": ">=22"
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { http, createPublicClient, createWalletClient } from 'viem';
2+
import { privateKeyToAccount } from 'viem/accounts';
3+
import { sonic } from 'viem/chains';
4+
import VaultFactoryArtifact from '../../contracts/artifacts/src/contracts/create-vault/VaultFactory.sol/VaultFactory.json'; // Adjust path
5+
6+
async function main() {
7+
console.log('Deploying VaultFactory to Sonic Blaze testnet...');
8+
9+
// Check for private key
10+
if (!process.env.EVM_PRIVATE_KEY) {
11+
throw new Error('EVM_PRIVATE_KEY environment variable is not set');
12+
}
13+
14+
// Initialize Viem clients
15+
const publicClient = createPublicClient({
16+
chain: sonic,
17+
transport: http(),
18+
});
19+
20+
// Create wallet client with private key
21+
const account = privateKeyToAccount(
22+
process.env.EVM_PRIVATE_KEY as `0x${string}`,
23+
);
24+
console.log('Deploying from account:', account.address);
25+
26+
const walletClient = createWalletClient({
27+
account,
28+
chain: sonic,
29+
transport: http(),
30+
});
31+
32+
console.log('Deploying contract...');
33+
// Deploy the contract using ABI and Bytecode
34+
const hash = await walletClient.deployContract({
35+
abi: VaultFactoryArtifact.abi,
36+
bytecode: VaultFactoryArtifact.bytecode,
37+
});
38+
39+
console.log('Transaction hash:', hash);
40+
console.log('Waiting for deployment...');
41+
42+
// Wait for deployment transaction
43+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
44+
45+
if (!receipt.contractAddress) {
46+
throw new Error('Failed to get contract address from transaction receipt');
47+
}
48+
49+
console.log('VaultFactory deployed to:', receipt.contractAddress);
50+
console.log('Please set this address in your .env file as EVM_PRIVATE_KEY');
51+
}
52+
53+
main()
54+
.then(() => process.exit(0))
55+
.catch((error) => {
56+
console.error(error);
57+
process.exit(1);
58+
});

backend/src/config/env.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import path from 'node:path';
2+
import { config } from 'dotenv';
3+
4+
// Load environment variables from .env file
5+
config({ path: path.resolve(process.cwd(), '.env') });
6+
7+
// Validate required environment variables
8+
const requiredEnvVars = [
9+
'VAULT_FACTORY_ADDRESS',
10+
'EVM_PRIVATE_KEY',
11+
'SONIC_RPC_URL',
12+
] as const;
13+
14+
for (const envVar of requiredEnvVars) {
15+
if (!process.env[envVar]) {
16+
throw new Error(`Missing required environment variable: ${envVar}`);
17+
}
18+
}
19+
20+
export const env = {
21+
VAULT_FACTORY_ADDRESS: process.env.VAULT_FACTORY_ADDRESS as `0x${string}`,
22+
EVM_PRIVATE_KEY: process.env.EVM_PRIVATE_KEY as `0x${string}`,
23+
SONIC_RPC_URL: process.env.SONIC_RPC_URL,
24+
} as const;

backend/src/eliza/api.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ About {{agentName}}:
3434
3535
{{providers}}
3636
37-
{{attachments}}
38-
39-
# Capabilities
40-
Note that {{agentName}} is capable of reading/seeing/hearing various forms of media, including images, videos, audio, plaintext and PDFs. Recent attachments have been included above under the "Attachments" section.
41-
4237
{{messageDirections}}
4338
4439
{{recentMessages}}
@@ -82,11 +77,12 @@ Response format should be formatted in a JSON block like this:
8277

8378
interface MessageRequest {
8479
roomId?: string;
85-
userId?: string;
80+
userId: string;
8681
userName?: string;
8782
name?: string;
8883
text?: string;
8984
agentId?: string;
85+
walletAddress?: string;
9086
}
9187

9288
export class ApiClient {
@@ -211,7 +207,7 @@ export class ApiClient {
211207
elizaLogger.info('[ApiClient] Starting message handling');
212208
const { agentId } = request;
213209
const roomId = stringToUuid(request.roomId ?? `default-room-${agentId}`);
214-
const userId = stringToUuid(request.userId ?? 'user');
210+
const userId = stringToUuid(request.userId);
215211

216212
await agent.ensureConnection(
217213
userId,
@@ -233,6 +229,9 @@ export class ApiClient {
233229
attachments: [],
234230
source: 'direct',
235231
inReplyTo: undefined,
232+
metadata: {
233+
walletAddress: request.walletAddress,
234+
},
236235
};
237236
const userMessage = {
238237
content,

0 commit comments

Comments
 (0)