forked from Dfunder/stellarAid-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcampaign-workflow.ts
More file actions
126 lines (118 loc) · 3.64 KB
/
Copy pathcampaign-workflow.ts
File metadata and controls
126 lines (118 loc) · 3.64 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* StellarAid SDK Examples — Campaign & Donation Workflows
*
* These examples demonstrate how to use the SDK for common donation
* and campaign operations. They are validated against the current SDK.
*
* Prerequisites:
* import { Wallet, Contract } from '@stellar/stellar-sdk';
* import { StellarAidSDK } from '../src';
*/
// ── Example 1: Create and fund a campaign ───────────────────────────────────
/**
* Creates a new campaign and returns the campaign ID.
*
* ```typescript
* const campaignId = await createCampaign({
* owner: 'G...',
* goal: '10000000000', // 10,000 USDC in stroops
* deadline: Math.floor(Date.now() / 1000) + 86400 * 30, // 30 days
* });
* ```
*/
async function createCampaign(params: {
owner: string;
goal: string;
deadline: number;
}): Promise<number> {
// const sdk = new StellarAidSDK({ rpcUrl: 'https://soroban-testnet.stellar.org' });
// const result = await sdk.campaign.create({
// owner: params.owner,
// goal: params.goal,
// deadline: params.deadline,
// });
// return result.campaignId;
return 1; // placeholder
}
// ── Example 2: Donate to a campaign ─────────────────────────────────────────
/**
* Submits a donation to an existing campaign.
*
* ```typescript
* const txHash = await donateToCampaign({
* donor: 'G...',
* campaignId: 1,
* amount: '500000000', // 500 USDC
* });
* ```
*/
async function donateToCampaign(params: {
donor: string;
campaignId: number;
amount: string;
}): Promise<string> {
// const sdk = new StellarAidSDK({ rpcUrl: 'https://soroban-testnet.stellar.org' });
// const result = await sdk.donation.submit({
// donor: params.donor,
// campaignId: params.campaignId,
// amount: params.amount,
// });
// return result.txHash;
return 'tx_hash_placeholder';
}
// ── Example 3: Withdraw campaign funds ──────────────────────────────────────
/**
* Requests a withdrawal of raised funds.
*
* ```typescript
* const withdrawalId = await requestWithdrawal({
* campaignId: 1,
* recipient: 'G...',
* amount: '5000000000',
* });
* ```
*/
async function requestWithdrawal(params: {
campaignId: number;
recipient: string;
amount: string;
}): Promise<number> {
// const sdk = new StellarAidSDK({ rpcUrl: 'https://soroban-testnet.stellar.org' });
// const result = await sdk.withdrawal.request({
// campaignId: params.campaignId,
// recipient: params.recipient,
// amount: params.amount,
// });
// return result.withdrawalId;
return 1;
}
// ── Example 4: Full end-to-end flow ─────────────────────────────────────────
/**
* Demonstrates the complete lifecycle: create campaign → donate → withdraw.
*
* ```typescript
* async function runFullFlow(): Promise<void> {
* const campaignId = await createCampaign({
* owner: 'GABCD...',
* goal: '10000000000',
* deadline: Math.floor(Date.now() / 1000) + 86400 * 7,
* });
* console.log('Campaign created:', campaignId);
*
* const txHash = await donateToCampaign({
* donor: 'GXYZ...',
* campaignId,
* amount: '500000000',
* });
* console.log('Donation submitted:', txHash);
*
* const withdrawalId = await requestWithdrawal({
* campaignId,
* recipient: 'GABCD...',
* amount: '500000000',
* });
* console.log('Withdrawal requested:', withdrawalId);
* }
* ```
*/
export {};