@flashbacktech/flashbackclient 0.1.34 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stellarv2/client/bucket.d.ts +111 -0
- package/dist/stellarv2/client/bucket.js +272 -0
- package/dist/stellarv2/client/consumer.d.ts +60 -0
- package/dist/stellarv2/client/consumer.js +149 -0
- package/dist/stellarv2/client/deal.d.ts +160 -0
- package/dist/stellarv2/client/deal.js +356 -0
- package/dist/stellarv2/client/funding.d.ts +46 -0
- package/dist/stellarv2/client/funding.js +78 -0
- package/dist/stellarv2/client/index.d.ts +134 -0
- package/dist/stellarv2/client/index.js +240 -0
- package/dist/stellarv2/client/provider.d.ts +72 -0
- package/dist/stellarv2/client/provider.js +178 -0
- package/dist/stellarv2/index.d.ts +6 -6
- package/dist/stellarv2/index.js +5 -5
- package/dist/stellarv2/utils/decorator.d.ts +2 -0
- package/dist/stellarv2/utils/decorator.js +30 -0
- package/dist/stellarv2/utils/lib.d.ts +13 -0
- package/dist/stellarv2/utils/lib.js +26 -0
- package/dist/stellarv2/utils/timing.d.ts +1 -0
- package/dist/stellarv2/utils/timing.js +19 -0
- package/dist/stellarv2/wallet/balance.d.ts +2 -0
- package/dist/stellarv2/wallet/balance.js +9 -0
- package/dist/stellarv2/wallet/batch.d.ts +44 -0
- package/dist/stellarv2/wallet/batch.js +77 -0
- package/dist/stellarv2/wallet/index.d.ts +4 -0
- package/dist/stellarv2/wallet/index.js +20 -0
- package/dist/stellarv2/wallet/token.d.ts +3 -0
- package/dist/stellarv2/wallet/token.js +23 -0
- package/dist/stellarv2/wallet/transaction.d.ts +38 -0
- package/dist/stellarv2/wallet/transaction.js +224 -0
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ClientContext } from '.';
|
|
2
|
+
import { Deal, DealCreateParams, DealConsumptionUpdateParams, DealSLAUpdateParams } from '../models';
|
|
3
|
+
/**
|
|
4
|
+
* Deal operations client for FlashOnStellar V2
|
|
5
|
+
* Implements all deal-related contract methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class DealOps {
|
|
8
|
+
private context;
|
|
9
|
+
constructor(context: ClientContext);
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new deal between a consumer and provider
|
|
12
|
+
* @param consumer_id - Address of the consumer creating the deal
|
|
13
|
+
* @param provider_id - Address of the provider
|
|
14
|
+
* @param bucket_id - ID of the bucket for the deal
|
|
15
|
+
* @param params - Deal creation parameters
|
|
16
|
+
* @returns Promise resolving to the created deal ID
|
|
17
|
+
*/
|
|
18
|
+
createDeal: (consumer_id: string, provider_id: string, bucket_id: number, params: DealCreateParams) => Promise<number>;
|
|
19
|
+
/**
|
|
20
|
+
* Sets a deal as accepted by the provider
|
|
21
|
+
* @param consumer_id - Address of the consumer
|
|
22
|
+
* @param provider_id - Address of the provider accepting the deal
|
|
23
|
+
* @param deal_id - ID of the deal to accept
|
|
24
|
+
* @returns Promise resolving to the acceptance result
|
|
25
|
+
*/
|
|
26
|
+
setDealAccepted: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Sets a deal as funded by the consumer
|
|
29
|
+
* @param consumer_id - Address of the consumer funding the deal
|
|
30
|
+
* @param provider_id - Address of the provider
|
|
31
|
+
* @param deal_id - ID of the deal to fund
|
|
32
|
+
* @param amount_usd - Amount to fund in USD (scaled by 10^7)
|
|
33
|
+
* @returns Promise resolving to the funding result
|
|
34
|
+
*/
|
|
35
|
+
setDealFunded: (consumer_id: string, provider_id: string, deal_id: number, amount_usd: bigint) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Sets a deal as completed
|
|
38
|
+
* @param consumer_id - Address of the consumer
|
|
39
|
+
* @param provider_id - Address of the provider
|
|
40
|
+
* @param deal_id - ID of the deal to complete
|
|
41
|
+
* @returns Promise resolving to the completion result
|
|
42
|
+
*/
|
|
43
|
+
setDealCompleted: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Sets a deal as cancelled
|
|
46
|
+
* @param consumer_id - Address of the consumer
|
|
47
|
+
* @param provider_id - Address of the provider
|
|
48
|
+
* @param deal_id - ID of the deal to cancel
|
|
49
|
+
* @returns Promise resolving to the cancellation result
|
|
50
|
+
*/
|
|
51
|
+
setDealCancelled: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Marks a deal as breached by the consumer
|
|
54
|
+
* @param consumer_id - Address of the consumer
|
|
55
|
+
* @param provider_id - Address of the provider
|
|
56
|
+
* @param deal_id - ID of the deal
|
|
57
|
+
* @returns Promise resolving to the breach marking result
|
|
58
|
+
*/
|
|
59
|
+
setDealBreachedConsumer: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Marks a deal as breached by the provider
|
|
62
|
+
* @param consumer_id - Address of the consumer
|
|
63
|
+
* @param provider_id - Address of the provider
|
|
64
|
+
* @param deal_id - ID of the deal
|
|
65
|
+
* @returns Promise resolving to the breach marking result
|
|
66
|
+
*/
|
|
67
|
+
setDealBreachedProvider: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Deletes a deal from the system (owner only)
|
|
70
|
+
* @param consumer_id - Address of the consumer
|
|
71
|
+
* @param provider_id - Address of the provider
|
|
72
|
+
* @param deal_id - ID of the deal to delete
|
|
73
|
+
* @returns Promise resolving to the deletion result
|
|
74
|
+
*/
|
|
75
|
+
deleteDeal: (consumer_id: string, provider_id: string, deal_id: number) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves deal information
|
|
78
|
+
* @param consumer_id - Address of the consumer
|
|
79
|
+
* @param provider_id - Address of the provider
|
|
80
|
+
* @param deal_id - ID of the deal to retrieve
|
|
81
|
+
* @returns Promise resolving to Deal object or null if not found
|
|
82
|
+
*/
|
|
83
|
+
getDeal(consumer_id: string, provider_id: string, deal_id: number): Promise<Deal | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the total count of deals in the system
|
|
86
|
+
* @returns Promise resolving to the total number of deals
|
|
87
|
+
*/
|
|
88
|
+
getDealCount(): Promise<number>;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves a paginated list of all deals
|
|
91
|
+
* @param skip - Number of items to skip for pagination
|
|
92
|
+
* @param take - Number of items to take per page
|
|
93
|
+
* @returns Promise resolving to an array of Deal objects
|
|
94
|
+
*/
|
|
95
|
+
getDeals(skip?: number, take?: number): Promise<Deal[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Retrieves all deals for a specific consumer
|
|
98
|
+
* @param consumer_id - Address of the consumer
|
|
99
|
+
* @returns Promise resolving to an array of Deal objects
|
|
100
|
+
*/
|
|
101
|
+
getDealsByConsumer(consumer_id: string): Promise<Deal[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves all deals for a specific provider
|
|
104
|
+
* @param provider_id - Address of the provider
|
|
105
|
+
* @returns Promise resolving to an array of Deal objects
|
|
106
|
+
*/
|
|
107
|
+
getDealsByProvider(provider_id: string): Promise<Deal[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves all active deals
|
|
110
|
+
* @param skip - Number of items to skip for pagination
|
|
111
|
+
* @param take - Number of items to take per page
|
|
112
|
+
* @returns Promise resolving to an array of active Deal objects
|
|
113
|
+
*/
|
|
114
|
+
getActiveDeals(skip?: number, take?: number): Promise<Deal[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Pays for pending consumption in a deal (owner only)
|
|
117
|
+
* @param provider_id - Address of the provider
|
|
118
|
+
* @param consumer_id - Address of the consumer
|
|
119
|
+
* @param deal_id - ID of the deal
|
|
120
|
+
* @returns Promise resolving to the payment result
|
|
121
|
+
*/
|
|
122
|
+
payPendingConsumption: (provider_id: string, consumer_id: string, deal_id: number) => Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Updates deal consumption metrics (owner only)
|
|
125
|
+
* @param provider_id - Address of the provider
|
|
126
|
+
* @param consumer_id - Address of the consumer
|
|
127
|
+
* @param deal_id - ID of the deal
|
|
128
|
+
* @param params - Consumption update parameters
|
|
129
|
+
* @returns Promise resolving to the update result
|
|
130
|
+
*/
|
|
131
|
+
updateDealConsumption: (provider_id: string, consumer_id: string, deal_id: number, params: DealConsumptionUpdateParams) => Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Updates deal SLA metrics (owner only)
|
|
134
|
+
* @param provider_id - Address of the provider
|
|
135
|
+
* @param consumer_id - Address of the consumer
|
|
136
|
+
* @param deal_id - ID of the deal
|
|
137
|
+
* @param params - SLA update parameters
|
|
138
|
+
* @returns Promise resolving to the update result
|
|
139
|
+
*/
|
|
140
|
+
updateDealSLA: (provider_id: string, consumer_id: string, deal_id: number, params: DealSLAUpdateParams) => Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Gets deal status information
|
|
143
|
+
* @param consumer_id - Address of the consumer
|
|
144
|
+
* @param provider_id - Address of the provider
|
|
145
|
+
* @param deal_id - ID of the deal
|
|
146
|
+
* @returns Promise resolving to deal status or null if deal not found
|
|
147
|
+
*/
|
|
148
|
+
getDealStatus(consumer_id: string, provider_id: string, deal_id: number): Promise<string | null>;
|
|
149
|
+
/**
|
|
150
|
+
* Gets deal balance information
|
|
151
|
+
* @param consumer_id - Address of the consumer
|
|
152
|
+
* @param provider_id - Address of the provider
|
|
153
|
+
* @param deal_id - ID of the deal
|
|
154
|
+
* @returns Promise resolving to deal balances or null if deal not found
|
|
155
|
+
*/
|
|
156
|
+
getDealBalances(consumer_id: string, provider_id: string, deal_id: number): Promise<{
|
|
157
|
+
balance_consumer: bigint;
|
|
158
|
+
balance_provider: bigint;
|
|
159
|
+
} | null>;
|
|
160
|
+
}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DealOps = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
5
|
+
const decorator_1 = require("../utils/decorator");
|
|
6
|
+
/**
|
|
7
|
+
* Deal operations client for FlashOnStellar V2
|
|
8
|
+
* Implements all deal-related contract methods
|
|
9
|
+
*/
|
|
10
|
+
class DealOps {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new deal between a consumer and provider
|
|
14
|
+
* @param consumer_id - Address of the consumer creating the deal
|
|
15
|
+
* @param provider_id - Address of the provider
|
|
16
|
+
* @param bucket_id - ID of the bucket for the deal
|
|
17
|
+
* @param params - Deal creation parameters
|
|
18
|
+
* @returns Promise resolving to the created deal ID
|
|
19
|
+
*/
|
|
20
|
+
this.createDeal = (0, decorator_1.withSignature)(async (consumer_id, provider_id, bucket_id, params) => {
|
|
21
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, consumer_id, {
|
|
22
|
+
method: 'create_deal',
|
|
23
|
+
args: [
|
|
24
|
+
{ value: consumer_id, type: 'address' },
|
|
25
|
+
{ value: provider_id, type: 'address' },
|
|
26
|
+
{ value: bucket_id, type: 'u32' },
|
|
27
|
+
{ value: params.duration_secs, type: 'u64' },
|
|
28
|
+
{ value: params.agreed_storage_gb, type: 'u32' },
|
|
29
|
+
{ value: params.agreed_egress_gb, type: 'u32' },
|
|
30
|
+
{ value: params.fb_repo_id, type: 'string' },
|
|
31
|
+
{ value: params.api_compatibility, type: 'string' }
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
if (!response.isSuccess) {
|
|
35
|
+
throw new Error('Failed to create deal');
|
|
36
|
+
}
|
|
37
|
+
const result = response.result;
|
|
38
|
+
if (typeof result === 'number') {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Failed to create deal');
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Sets a deal as accepted by the provider
|
|
45
|
+
* @param consumer_id - Address of the consumer
|
|
46
|
+
* @param provider_id - Address of the provider accepting the deal
|
|
47
|
+
* @param deal_id - ID of the deal to accept
|
|
48
|
+
* @returns Promise resolving to the acceptance result
|
|
49
|
+
*/
|
|
50
|
+
this.setDealAccepted = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
51
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "set_deal_accepted", [
|
|
52
|
+
{ value: consumer_id, type: 'address' },
|
|
53
|
+
{ value: provider_id, type: 'address' },
|
|
54
|
+
{ value: deal_id, type: 'u32' }
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Sets a deal as funded by the consumer
|
|
59
|
+
* @param consumer_id - Address of the consumer funding the deal
|
|
60
|
+
* @param provider_id - Address of the provider
|
|
61
|
+
* @param deal_id - ID of the deal to fund
|
|
62
|
+
* @param amount_usd - Amount to fund in USD (scaled by 10^7)
|
|
63
|
+
* @returns Promise resolving to the funding result
|
|
64
|
+
*/
|
|
65
|
+
this.setDealFunded = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id, amount_usd) => {
|
|
66
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "set_deal_funded", [
|
|
67
|
+
{ value: provider_id, type: 'address' },
|
|
68
|
+
{ value: consumer_id, type: 'address' },
|
|
69
|
+
{ value: deal_id, type: 'u32' },
|
|
70
|
+
{ value: amount_usd, type: 'u128' }
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Sets a deal as completed
|
|
75
|
+
* @param consumer_id - Address of the consumer
|
|
76
|
+
* @param provider_id - Address of the provider
|
|
77
|
+
* @param deal_id - ID of the deal to complete
|
|
78
|
+
* @returns Promise resolving to the completion result
|
|
79
|
+
*/
|
|
80
|
+
this.setDealCompleted = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
81
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "set_deal_completed", [
|
|
82
|
+
{ value: provider_id, type: 'address' },
|
|
83
|
+
{ value: consumer_id, type: 'address' },
|
|
84
|
+
{ value: deal_id, type: 'u32' }
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Sets a deal as cancelled
|
|
89
|
+
* @param consumer_id - Address of the consumer
|
|
90
|
+
* @param provider_id - Address of the provider
|
|
91
|
+
* @param deal_id - ID of the deal to cancel
|
|
92
|
+
* @returns Promise resolving to the cancellation result
|
|
93
|
+
*/
|
|
94
|
+
this.setDealCancelled = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
95
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "set_deal_cancelled", [
|
|
96
|
+
{ value: consumer_id, type: 'address' },
|
|
97
|
+
{ value: provider_id, type: 'address' },
|
|
98
|
+
{ value: deal_id, type: 'u32' }
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Marks a deal as breached by the consumer
|
|
103
|
+
* @param consumer_id - Address of the consumer
|
|
104
|
+
* @param provider_id - Address of the provider
|
|
105
|
+
* @param deal_id - ID of the deal
|
|
106
|
+
* @returns Promise resolving to the breach marking result
|
|
107
|
+
*/
|
|
108
|
+
this.setDealBreachedConsumer = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
109
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "set_deal_breached_consumer", [
|
|
110
|
+
{ value: consumer_id, type: 'address' },
|
|
111
|
+
{ value: provider_id, type: 'address' },
|
|
112
|
+
{ value: deal_id, type: 'u32' }
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* Marks a deal as breached by the provider
|
|
117
|
+
* @param consumer_id - Address of the consumer
|
|
118
|
+
* @param provider_id - Address of the provider
|
|
119
|
+
* @param deal_id - ID of the deal
|
|
120
|
+
* @returns Promise resolving to the breach marking result
|
|
121
|
+
*/
|
|
122
|
+
this.setDealBreachedProvider = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
123
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "set_deal_breached_provider", [
|
|
124
|
+
{ value: provider_id, type: 'address' },
|
|
125
|
+
{ value: consumer_id, type: 'address' },
|
|
126
|
+
{ value: deal_id, type: 'u32' }
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Deletes a deal from the system (owner only)
|
|
131
|
+
* @param consumer_id - Address of the consumer
|
|
132
|
+
* @param provider_id - Address of the provider
|
|
133
|
+
* @param deal_id - ID of the deal to delete
|
|
134
|
+
* @returns Promise resolving to the deletion result
|
|
135
|
+
*/
|
|
136
|
+
this.deleteDeal = (0, decorator_1.withSignature)(async (consumer_id, provider_id, deal_id) => {
|
|
137
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "delete_deal", [
|
|
138
|
+
{ value: consumer_id, type: 'address' },
|
|
139
|
+
{ value: provider_id, type: 'address' },
|
|
140
|
+
{ value: deal_id, type: 'u32' }
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Pays for pending consumption in a deal (owner only)
|
|
145
|
+
* @param provider_id - Address of the provider
|
|
146
|
+
* @param consumer_id - Address of the consumer
|
|
147
|
+
* @param deal_id - ID of the deal
|
|
148
|
+
* @returns Promise resolving to the payment result
|
|
149
|
+
*/
|
|
150
|
+
this.payPendingConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id) => {
|
|
151
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "pay_pending_consumption", [
|
|
152
|
+
{ value: provider_id, type: 'address' },
|
|
153
|
+
{ value: consumer_id, type: 'address' },
|
|
154
|
+
{ value: deal_id, type: 'u32' }
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
/**
|
|
158
|
+
* Updates deal consumption metrics (owner only)
|
|
159
|
+
* @param provider_id - Address of the provider
|
|
160
|
+
* @param consumer_id - Address of the consumer
|
|
161
|
+
* @param deal_id - ID of the deal
|
|
162
|
+
* @param params - Consumption update parameters
|
|
163
|
+
* @returns Promise resolving to the update result
|
|
164
|
+
*/
|
|
165
|
+
this.updateDealConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
|
|
166
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_consumption", [
|
|
167
|
+
{ value: provider_id, type: 'address' },
|
|
168
|
+
{ value: consumer_id, type: 'address' },
|
|
169
|
+
{ value: deal_id, type: 'u32' },
|
|
170
|
+
{ value: params.storage_gb, type: 'u32' },
|
|
171
|
+
{ value: params.egress_gb, type: 'u32' }
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
/**
|
|
175
|
+
* Updates deal SLA metrics (owner only)
|
|
176
|
+
* @param provider_id - Address of the provider
|
|
177
|
+
* @param consumer_id - Address of the consumer
|
|
178
|
+
* @param deal_id - ID of the deal
|
|
179
|
+
* @param params - SLA update parameters
|
|
180
|
+
* @returns Promise resolving to the update result
|
|
181
|
+
*/
|
|
182
|
+
this.updateDealSLA = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
|
|
183
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_sla", [
|
|
184
|
+
{ value: provider_id, type: 'address' },
|
|
185
|
+
{ value: consumer_id, type: 'address' },
|
|
186
|
+
{ value: deal_id, type: 'u32' },
|
|
187
|
+
{ value: params.sla_avg_latency_ms, type: 'u32' },
|
|
188
|
+
{ value: params.sla_avg_uptime_pct, type: 'u32' }
|
|
189
|
+
]);
|
|
190
|
+
});
|
|
191
|
+
this.context = context;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves deal information
|
|
195
|
+
* @param consumer_id - Address of the consumer
|
|
196
|
+
* @param provider_id - Address of the provider
|
|
197
|
+
* @param deal_id - ID of the deal to retrieve
|
|
198
|
+
* @returns Promise resolving to Deal object or null if not found
|
|
199
|
+
*/
|
|
200
|
+
async getDeal(consumer_id, provider_id, deal_id) {
|
|
201
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, consumer_id, {
|
|
202
|
+
method: 'get_deal',
|
|
203
|
+
args: [
|
|
204
|
+
{ value: consumer_id, type: 'address' },
|
|
205
|
+
{ value: provider_id, type: 'address' },
|
|
206
|
+
{ value: deal_id, type: 'u32' }
|
|
207
|
+
]
|
|
208
|
+
});
|
|
209
|
+
if (!response.isSuccess) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
const result = response.result;
|
|
213
|
+
if (result && typeof result === 'object') {
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Gets the total count of deals in the system
|
|
220
|
+
* @returns Promise resolving to the total number of deals
|
|
221
|
+
*/
|
|
222
|
+
async getDealCount() {
|
|
223
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
224
|
+
method: 'get_deal_count',
|
|
225
|
+
args: []
|
|
226
|
+
});
|
|
227
|
+
if (!response.isSuccess) {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
const result = response.result;
|
|
231
|
+
if (typeof result === 'number') {
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves a paginated list of all deals
|
|
238
|
+
* @param skip - Number of items to skip for pagination
|
|
239
|
+
* @param take - Number of items to take per page
|
|
240
|
+
* @returns Promise resolving to an array of Deal objects
|
|
241
|
+
*/
|
|
242
|
+
async getDeals(skip = 0, take = 10) {
|
|
243
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
244
|
+
method: 'get_deals',
|
|
245
|
+
args: [
|
|
246
|
+
{ value: skip, type: 'u32' },
|
|
247
|
+
{ value: take, type: 'u32' }
|
|
248
|
+
]
|
|
249
|
+
});
|
|
250
|
+
if (!response.isSuccess) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
const result = response.result;
|
|
254
|
+
if (Array.isArray(result)) {
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Retrieves all deals for a specific consumer
|
|
261
|
+
* @param consumer_id - Address of the consumer
|
|
262
|
+
* @returns Promise resolving to an array of Deal objects
|
|
263
|
+
*/
|
|
264
|
+
async getDealsByConsumer(consumer_id) {
|
|
265
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, consumer_id, {
|
|
266
|
+
method: 'get_deals_by_consumer',
|
|
267
|
+
args: [
|
|
268
|
+
{ value: consumer_id, type: 'address' }
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
if (!response.isSuccess) {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
const result = response.result;
|
|
275
|
+
if (Array.isArray(result)) {
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Retrieves all deals for a specific provider
|
|
282
|
+
* @param provider_id - Address of the provider
|
|
283
|
+
* @returns Promise resolving to an array of Deal objects
|
|
284
|
+
*/
|
|
285
|
+
async getDealsByProvider(provider_id) {
|
|
286
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, provider_id, {
|
|
287
|
+
method: 'get_deals_by_provider',
|
|
288
|
+
args: [
|
|
289
|
+
{ value: provider_id, type: 'address' }
|
|
290
|
+
]
|
|
291
|
+
});
|
|
292
|
+
if (!response.isSuccess) {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
const result = response.result;
|
|
296
|
+
if (Array.isArray(result)) {
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Retrieves all active deals
|
|
303
|
+
* @param skip - Number of items to skip for pagination
|
|
304
|
+
* @param take - Number of items to take per page
|
|
305
|
+
* @returns Promise resolving to an array of active Deal objects
|
|
306
|
+
*/
|
|
307
|
+
async getActiveDeals(skip = 0, take = 10) {
|
|
308
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
309
|
+
method: 'get_active_deals',
|
|
310
|
+
args: [
|
|
311
|
+
{ value: skip, type: 'u32' },
|
|
312
|
+
{ value: take, type: 'u32' }
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
if (!response.isSuccess) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
const result = response.result;
|
|
319
|
+
if (Array.isArray(result)) {
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
return [];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Gets deal status information
|
|
326
|
+
* @param consumer_id - Address of the consumer
|
|
327
|
+
* @param provider_id - Address of the provider
|
|
328
|
+
* @param deal_id - ID of the deal
|
|
329
|
+
* @returns Promise resolving to deal status or null if deal not found
|
|
330
|
+
*/
|
|
331
|
+
async getDealStatus(consumer_id, provider_id, deal_id) {
|
|
332
|
+
const deal = await this.getDeal(consumer_id, provider_id, deal_id);
|
|
333
|
+
if (!deal) {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
return deal.status;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Gets deal balance information
|
|
340
|
+
* @param consumer_id - Address of the consumer
|
|
341
|
+
* @param provider_id - Address of the provider
|
|
342
|
+
* @param deal_id - ID of the deal
|
|
343
|
+
* @returns Promise resolving to deal balances or null if deal not found
|
|
344
|
+
*/
|
|
345
|
+
async getDealBalances(consumer_id, provider_id, deal_id) {
|
|
346
|
+
const deal = await this.getDeal(consumer_id, provider_id, deal_id);
|
|
347
|
+
if (!deal) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
balance_consumer: deal.balance_consumer,
|
|
352
|
+
balance_provider: deal.balance_provider
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
exports.DealOps = DealOps;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ClientContext } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Funding operations client for FlashOnStellar V2
|
|
4
|
+
* Implements all funding-related contract methods (owner only)
|
|
5
|
+
*/
|
|
6
|
+
export declare class FundingOps {
|
|
7
|
+
private context;
|
|
8
|
+
constructor(context: ClientContext);
|
|
9
|
+
/**
|
|
10
|
+
* Sends funds from the contract to a receiver (owner only)
|
|
11
|
+
* @param receiver - Address of the receiver
|
|
12
|
+
* @param amount - Amount to send in the stable asset's smallest unit
|
|
13
|
+
* @returns Promise resolving to the transfer result
|
|
14
|
+
*/
|
|
15
|
+
sendFundsOwner: (receiver: string, amount: bigint) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Test faucet function for minting tokens to a receiver (owner only)
|
|
18
|
+
* @param receiver - Address of the receiver
|
|
19
|
+
* @param amount - Amount to mint in the stable asset's smallest unit
|
|
20
|
+
* @returns Promise resolving to the minting result
|
|
21
|
+
*/
|
|
22
|
+
testFaucetOwner: (receiver: string, amount: bigint) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Changes the admin of the stable asset contract (owner only)
|
|
25
|
+
* @param new_admin - Address of the new admin
|
|
26
|
+
* @returns Promise resolving to the admin change result
|
|
27
|
+
*/
|
|
28
|
+
changeAssetAdmin: (new_admin: string) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the stable asset address from the contract
|
|
31
|
+
* @returns Promise resolving to the stable asset contract address
|
|
32
|
+
*/
|
|
33
|
+
getStableAssetAddress(): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if an address is authorized for the stable asset
|
|
36
|
+
* @param address - Address to check
|
|
37
|
+
* @returns Promise resolving to true if authorized, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
isAuthorizedForAsset(address: string): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the balance of an address for the stable asset
|
|
42
|
+
* @param address - Address to check balance for
|
|
43
|
+
* @returns Promise resolving to the balance amount
|
|
44
|
+
*/
|
|
45
|
+
getAssetBalance(address: string): Promise<bigint>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FundingOps = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
5
|
+
const decorator_1 = require("../utils/decorator");
|
|
6
|
+
/**
|
|
7
|
+
* Funding operations client for FlashOnStellar V2
|
|
8
|
+
* Implements all funding-related contract methods (owner only)
|
|
9
|
+
*/
|
|
10
|
+
class FundingOps {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
/**
|
|
13
|
+
* Sends funds from the contract to a receiver (owner only)
|
|
14
|
+
* @param receiver - Address of the receiver
|
|
15
|
+
* @param amount - Amount to send in the stable asset's smallest unit
|
|
16
|
+
* @returns Promise resolving to the transfer result
|
|
17
|
+
*/
|
|
18
|
+
this.sendFundsOwner = (0, decorator_1.withSignature)(async (receiver, amount) => {
|
|
19
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "send_funds_owner", [
|
|
20
|
+
{ value: receiver, type: 'address' },
|
|
21
|
+
{ value: amount, type: 'i128' }
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Test faucet function for minting tokens to a receiver (owner only)
|
|
26
|
+
* @param receiver - Address of the receiver
|
|
27
|
+
* @param amount - Amount to mint in the stable asset's smallest unit
|
|
28
|
+
* @returns Promise resolving to the minting result
|
|
29
|
+
*/
|
|
30
|
+
this.testFaucetOwner = (0, decorator_1.withSignature)(async (receiver, amount) => {
|
|
31
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "test_faucet_owner", [
|
|
32
|
+
{ value: receiver, type: 'address' },
|
|
33
|
+
{ value: amount, type: 'i128' }
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Changes the admin of the stable asset contract (owner only)
|
|
38
|
+
* @param new_admin - Address of the new admin
|
|
39
|
+
* @returns Promise resolving to the admin change result
|
|
40
|
+
*/
|
|
41
|
+
this.changeAssetAdmin = (0, decorator_1.withSignature)(async (new_admin) => {
|
|
42
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "change_asset_admin", [
|
|
43
|
+
{ value: new_admin, type: 'address' }
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
this.context = context;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the stable asset address from the contract
|
|
50
|
+
* @returns Promise resolving to the stable asset contract address
|
|
51
|
+
*/
|
|
52
|
+
async getStableAssetAddress() {
|
|
53
|
+
// This would typically be a getter method, but since it's not in the FundingOps trait,
|
|
54
|
+
// we'll need to implement it separately or access it through the main contract
|
|
55
|
+
throw new Error('getStableAssetAddress not implemented in FundingOps - use main contract methods');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks if an address is authorized for the stable asset
|
|
59
|
+
* @param address - Address to check
|
|
60
|
+
* @returns Promise resolving to true if authorized, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
async isAuthorizedForAsset(address) {
|
|
63
|
+
// This would typically be a getter method on the stable asset contract
|
|
64
|
+
// Implementation depends on the specific stable asset contract interface
|
|
65
|
+
throw new Error('isAuthorizedForAsset not implemented - requires stable asset contract interaction');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the balance of an address for the stable asset
|
|
69
|
+
* @param address - Address to check balance for
|
|
70
|
+
* @returns Promise resolving to the balance amount
|
|
71
|
+
*/
|
|
72
|
+
async getAssetBalance(address) {
|
|
73
|
+
// This would typically be a getter method on the stable asset contract
|
|
74
|
+
// Implementation depends on the specific stable asset contract interaction
|
|
75
|
+
throw new Error('getAssetBalance not implemented - requires stable asset contract interaction');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.FundingOps = FundingOps;
|