forked from ussyalfaks/Grainlify-Stellar-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounty-lock-release.ts
More file actions
81 lines (71 loc) · 2.34 KB
/
Copy pathbounty-lock-release.ts
File metadata and controls
81 lines (71 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Keypair } from '@stellar/stellar-sdk';
import { BountyEscrowClient } from '../src/bounty-escrow-client';
async function main() {
// Configuration
const config = {
contractId: 'CBTG2...', // Replace with actual contract ID
rpcUrl: 'https://soroban-testnet.stellar.org',
networkPassphrase: 'Test SDF Network ; September 2015',
};
const client = new BountyEscrowClient(config);
// Generate some keypairs for demonstration
const adminKeypair = Keypair.random();
const depositorKeypair = Keypair.random();
const contributorKeypair = Keypair.random();
const tokenAddress = 'CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC'; // XLM on testnet
console.log('1. Initializing Bounty Escrow Contract');
try {
await client.init(adminKeypair.publicKey(), tokenAddress, adminKeypair);
console.log('Successfully initialized contract');
} catch (error) {
console.log('Initialization mock catch:', error.message);
}
console.log('\n2. Locking Funds for a Bounty');
const bountyId = 1n;
const amount = 10000000n; // 100 XLM
const deadline = Math.floor(Date.now() / 1000) + 86400 * 7; // 7 days from now
try {
await client.lockFunds(
depositorKeypair.publicKey(),
bountyId,
amount,
deadline,
depositorKeypair
);
console.log('Funds locked successfully');
} catch (error) {
console.log('Lock funds mock catch:', error.message);
}
console.log('\n3. Partial Release of Funds');
const partialAmount = 2500000n; // 25 XLM
try {
await client.partialRelease(
bountyId,
contributorKeypair.publicKey(),
partialAmount,
adminKeypair // admin or authorized caller
);
console.log('Partial release successful');
} catch (error) {
console.log('Partial release mock catch:', error.message);
}
console.log('\n4. Full Release of Remaining Funds');
try {
await client.releaseFunds(
bountyId,
contributorKeypair.publicKey(),
adminKeypair
);
console.log('Full release successful');
} catch (error) {
console.log('Full release mock catch:', error.message);
}
console.log('\n5. Query Escrow Info');
try {
const info = await client.getEscrowInfo(bountyId);
console.log('Escrow Info:', info);
} catch (error) {
console.log('Query mock catch:', error.message);
}
}
main().catch(console.error);