@aboutcircles/sdk 0.1.0

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.
@@ -0,0 +1,412 @@
1
+ import type { Address, AvatarRow, ContractRunner, TokenBalanceRow, GroupMembershipRow, GroupRow } from '@aboutcircles/sdk-types';
2
+ import type { TransactionReceipt } from 'viem';
3
+ import type { Core } from '@aboutcircles/sdk-core';
4
+ import { CommonAvatar, type PathfindingOptions } from './CommonAvatar';
5
+ /**
6
+ * HumanAvatar class implementation
7
+ * Provides a simplified, user-friendly wrapper around Circles protocol for human avatars
8
+ *
9
+ * This class represents a human avatar in the Circles ecosystem and provides
10
+ * methods for managing trust relationships, personal token minting, transfers, and more.
11
+ */
12
+ export declare class HumanAvatar extends CommonAvatar {
13
+ constructor(address: Address, core: Core, contractRunner?: ContractRunner, avatarInfo?: AvatarRow);
14
+ readonly balances: {
15
+ getTotal: () => Promise<bigint>;
16
+ getTokenBalances: () => Promise<TokenBalanceRow[]>;
17
+ getTotalSupply: () => Promise<bigint>;
18
+ /**
19
+ * Get the maximum amount that can be replenished (converted to unwrapped personal CRC)
20
+ * This calculates how much of your wrapped tokens and other tokens can be converted
21
+ * into your own unwrapped ERC1155 personal CRC tokens using pathfinding
22
+ *
23
+ * @param options Optional pathfinding options
24
+ * @returns Maximum replenishable amount in atto-circles
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const maxReplenishable = await avatar.balances.getMaxReplenishable();
29
+ * console.log('Can replenish:', CirclesConverter.attoCirclesToCircles(maxReplenishable), 'CRC');
30
+ * ```
31
+ */
32
+ getMaxReplenishable: (options?: PathfindingOptions) => Promise<bigint>;
33
+ /**
34
+ * Replenish unwrapped personal CRC tokens by converting wrapped/other tokens
35
+ *
36
+ * This method uses pathfinding to find the best way to convert your available tokens
37
+ * (including wrapped tokens) into unwrapped ERC1155 personal CRC tokens.
38
+ *
39
+ * Useful when you have wrapped tokens or other people's tokens and want to
40
+ * convert them to your own personal unwrapped tokens for transfers.
41
+ *
42
+ * @param options Optional pathfinding options
43
+ * @returns Transaction receipt
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Convert all available wrapped/other tokens to unwrapped personal CRC
48
+ * const receipt = await avatar.balances.replenish();
49
+ * console.log('Replenished personal tokens, tx hash:', receipt.hash);
50
+ * ```
51
+ */
52
+ replenish: (options?: PathfindingOptions) => Promise<TransactionReceipt>;
53
+ };
54
+ readonly invite: {
55
+ /**
56
+ * Invite someone to Circles by escrowing 100 CRC tokens
57
+ *
58
+ * This batches two transactions atomically:
59
+ * 1. Establishes trust with the invitee (with indefinite expiry)
60
+ * 2. Transfers 100 of your personal CRC tokens to the InvitationEscrow contract
61
+ *
62
+ * The tokens are held in escrow until the invitee redeems the invitation by registering.
63
+ *
64
+ * Requirements:
65
+ * - You must have at least 100 CRC available
66
+ * - Invitee must not be already registered in Circles
67
+ * - You can only have one active invitation per invitee
68
+ *
69
+ * @param invitee The address to invite
70
+ * @returns Transaction response
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Invite someone with 100 CRC (automatically establishes trust)
75
+ * await avatar.invite.send('0x123...');
76
+ * ```
77
+ */
78
+ send: (invitee: Address) => Promise<TransactionReceipt>;
79
+ /**
80
+ * Revoke a previously sent invitation
81
+ *
82
+ * This returns the escrowed tokens (with demurrage applied) back to you
83
+ * as wrapped ERC20 tokens.
84
+ *
85
+ * @param invitee The address whose invitation to revoke
86
+ * @returns Transaction response
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * await avatar.invite.revoke('0x123...');
91
+ * ```
92
+ */
93
+ revoke: (invitee: Address) => Promise<TransactionReceipt>;
94
+ /**
95
+ * Revoke all active invitations at once
96
+ *
97
+ * This returns all escrowed tokens (with demurrage applied) back to you
98
+ * as wrapped ERC20 tokens in a single transaction.
99
+ *
100
+ * @returns Transaction response
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * await avatar.invite.revokeAll();
105
+ * ```
106
+ */
107
+ revokeAll: () => Promise<TransactionReceipt>;
108
+ /**
109
+ * Redeem an invitation received from an inviter
110
+ *
111
+ * This claims the escrowed tokens from a specific inviter and refunds
112
+ * all other inviters' escrows back to them.
113
+ *
114
+ * @param inviter The address of the inviter whose invitation to redeem
115
+ * @returns Transaction response
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Get all inviters first
120
+ * const inviters = await avatar.invite.getInviters();
121
+ *
122
+ * // Redeem invitation from the first inviter
123
+ * await avatar.invite.redeem(inviters[0]);
124
+ * ```
125
+ */
126
+ redeem: (inviter: Address) => Promise<TransactionReceipt>;
127
+ /**
128
+ * Get all addresses that have sent invitations to you
129
+ *
130
+ * @returns Array of inviter addresses
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const inviters = await avatar.invite.getInviters();
135
+ * console.log(`You have ${inviters.length} pending invitations`);
136
+ * ```
137
+ */
138
+ getInviters: () => Promise<Address[]>;
139
+ /**
140
+ * Get all addresses you have invited
141
+ *
142
+ * @returns Array of invitee addresses
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const invitees = await avatar.invite.getInvitees();
147
+ * console.log(`You have invited ${invitees.length} people`);
148
+ * ```
149
+ */
150
+ getInvitees: () => Promise<Address[]>;
151
+ /**
152
+ * Get the escrowed amount and days since escrow for a specific invitation
153
+ *
154
+ * The amount returned has demurrage applied, so it decreases over time.
155
+ *
156
+ * @param inviter The inviter address (when checking invitations you received)
157
+ * @param invitee The invitee address (when checking invitations you sent)
158
+ * @returns Object with escrowedAmount (in atto-circles) and days since escrow
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Check an invitation you sent
163
+ * const { escrowedAmount, days_ } = await avatar.invite.getEscrowedAmount(
164
+ * avatar.address,
165
+ * '0xinvitee...'
166
+ * );
167
+ * console.log(`Escrowed: ${CirclesConverter.attoCirclesToCircles(escrowedAmount)} CRC`);
168
+ * console.log(`Days since escrow: ${days_}`);
169
+ *
170
+ * // Check an invitation you received
171
+ * const { escrowedAmount, days_ } = await avatar.invite.getEscrowedAmount(
172
+ * '0xinviter...',
173
+ * avatar.address
174
+ * );
175
+ * ```
176
+ */
177
+ getEscrowedAmount: (inviter: Address, invitee: Address) => Promise<import("@aboutcircles/sdk-types").EscrowedAmountAndDays>;
178
+ };
179
+ readonly personalToken: {
180
+ /**
181
+ * Get the available amount of personal tokens that can be minted
182
+ *
183
+ * This method calls the HubV2 contract's calculateIssuance function which returns:
184
+ * - Total issuance amount: The total amount of tokens that can be minted
185
+ * - Start period: The period when minting started
186
+ * - End period: The current period
187
+ *
188
+ * @returns Object containing issuance amount (in atto-circles), start period, and end period
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const { amount, startPeriod, endPeriod } = await avatar.personalToken.getMintableAmount();
193
+ * console.log('Mintable amount:', CirclesConverter.attoCirclesToCircles(amount), 'CRC');
194
+ * console.log('Start period:', startPeriod.toString());
195
+ * console.log('End period:', endPeriod.toString());
196
+ * ```
197
+ */
198
+ getMintableAmount: () => Promise<{
199
+ amount: bigint;
200
+ startPeriod: bigint;
201
+ endPeriod: bigint;
202
+ }>;
203
+ /**
204
+ * Mint personal Circles tokens
205
+ * This claims all available personal tokens that have accrued since last mint
206
+ *
207
+ * @returns Transaction response
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const receipt = await avatar.personalToken.mint();
212
+ * console.log('Minted tokens, tx hash:', receipt.hash);
213
+ * ```
214
+ */
215
+ mint: () => Promise<TransactionReceipt>;
216
+ /**
217
+ * Stop personal token minting
218
+ * This permanently stops the ability to mint new personal tokens
219
+ *
220
+ * WARNING: This action is irreversible!
221
+ *
222
+ * @returns Transaction response
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const receipt = await avatar.personalToken.stop();
227
+ * console.log('Stopped minting, tx hash:', receipt.hash);
228
+ * ```
229
+ */
230
+ stop: () => Promise<TransactionReceipt>;
231
+ };
232
+ readonly groupToken: {
233
+ /**
234
+ * Mint group tokens by transferring collateral to the group's mint handler
235
+ * Uses pathfinding to transfer tokens along the trust network, including wrapped tokens
236
+ *
237
+ * @param group The group address to mint tokens from
238
+ * @param amount Amount of tokens to transfer to the mint handler (in atto-circles)
239
+ * @returns Transaction receipt
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // Mint group tokens by sending 100 CRC to the group's mint handler
244
+ * const receipt = await avatar.groupToken.mint('0xGroupAddress...', BigInt(100e18));
245
+ * ```
246
+ */
247
+ mint: (group: Address, amount: bigint) => Promise<TransactionReceipt>;
248
+ /**
249
+ * Get the maximum amount that can be minted for a group
250
+ * This calculates the maximum transferable amount to the group's mint handler
251
+ * including wrapped token balances
252
+ *
253
+ * @param group The group address
254
+ * @returns Maximum mintable amount in atto-circles
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const maxMintable = await avatar.groupToken.getMaxMintableAmount('0xGroupAddress...');
259
+ * console.log('Can mint up to:', maxMintable.toString(), 'atto-circles');
260
+ * ```
261
+ */
262
+ getMaxMintableAmount: (group: Address) => Promise<bigint>;
263
+ /**
264
+ * Automatically redeem collateral tokens from a Base Group's treasury
265
+ *
266
+ * Performs automatic redemption by determining trusted collaterals and using pathfinder for optimal flow.
267
+ * Only supports Base Group types. The function uses pathfinder to determine the optimal redemption path
268
+ * and validates that sufficient liquidity exists before attempting redemption.
269
+ *
270
+ * @param group The address of the Base Group from which to redeem collateral tokens
271
+ * @param amount The amount of group tokens to redeem for collateral (must be > 0 and <= max redeemable)
272
+ * @returns A Promise resolving to the transaction receipt upon successful automatic redemption
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * // Redeem 100 group tokens for collateral
277
+ * const receipt = await avatar.groupToken.redeem('0xGroupAddress...', BigInt(100e18));
278
+ * ```
279
+ */
280
+ redeem: (group: Address, amount: bigint) => Promise<TransactionReceipt>;
281
+ properties: {
282
+ /**
283
+ * Get the owner of a specific group
284
+ * @param group The group address
285
+ * @returns The owner address of the group
286
+ */
287
+ owner: (group: Address) => Promise<Address>;
288
+ /**
289
+ * Get the mint handler address of a specific group
290
+ * @param group The group address
291
+ * @returns The mint handler address
292
+ */
293
+ mintHandler: (group: Address) => Promise<Address>;
294
+ /**
295
+ * Get the treasury (redemption handler) address of a specific group
296
+ * @param group The group address
297
+ * @returns The treasury address where redemptions are handled
298
+ */
299
+ treasury: (group: Address) => Promise<Address>;
300
+ /**
301
+ * Get the service address of a specific group
302
+ * @param group The group address
303
+ * @returns The service address
304
+ */
305
+ service: (group: Address) => Promise<Address>;
306
+ /**
307
+ * Get the fee collection address of a specific group
308
+ * @param group The group address
309
+ * @returns The fee collection address
310
+ */
311
+ feeCollection: (group: Address) => Promise<Address>;
312
+ /**
313
+ * Get all membership conditions for a specific group
314
+ * @param group The group address
315
+ * @returns Array of membership condition addresses
316
+ */
317
+ getMembershipConditions: (group: Address) => Promise<Address[]>;
318
+ };
319
+ };
320
+ readonly group: {
321
+ properties: {
322
+ /**
323
+ * Get the owner of a specific group
324
+ * @param group The group address
325
+ * @returns The owner address of the group
326
+ */
327
+ owner: (group: Address) => Promise<Address>;
328
+ /**
329
+ * Get the mint handler address of a specific group
330
+ * @param group The group address
331
+ * @returns The mint handler address
332
+ */
333
+ mintHandler: (group: Address) => Promise<Address>;
334
+ /**
335
+ * Get the treasury (redemption handler) address of a specific group
336
+ * @param group The group address
337
+ * @returns The treasury address where redemptions are handled
338
+ */
339
+ treasury: (group: Address) => Promise<Address>;
340
+ /**
341
+ * Get the service address of a specific group
342
+ * @param group The group address
343
+ * @returns The service address
344
+ */
345
+ service: (group: Address) => Promise<Address>;
346
+ /**
347
+ * Get the fee collection address of a specific group
348
+ * @param group The group address
349
+ * @returns The fee collection address
350
+ */
351
+ feeCollection: (group: Address) => Promise<Address>;
352
+ /**
353
+ * Get all membership conditions for a specific group
354
+ * @param group The group address
355
+ * @returns Array of membership condition addresses
356
+ */
357
+ getMembershipConditions: (group: Address) => Promise<Address[]>;
358
+ };
359
+ /**
360
+ * Get group memberships for this avatar using cursor-based pagination
361
+ *
362
+ * Returns a PagedQuery instance for iterating through all groups that this avatar is a member of,
363
+ * including membership details such as expiry time and when the membership was created.
364
+ *
365
+ * @param limit Number of memberships per page (default: 50)
366
+ * @param sortOrder Sort order for results (default: 'DESC')
367
+ * @returns PagedQuery instance for iterating through memberships
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const query = avatar.group.getGroupMemberships();
372
+ *
373
+ * // Get first page
374
+ * await query.queryNextPage();
375
+ * console.log(`Member of ${query.currentPage.size} groups (page 1)`);
376
+ *
377
+ * // Iterate through all memberships
378
+ * while (await query.queryNextPage()) {
379
+ * query.currentPage.results.forEach(membership => {
380
+ * console.log(`Group: ${membership.group}`);
381
+ * console.log(`Expiry: ${new Date(membership.expiryTime * 1000).toLocaleDateString()}`);
382
+ * });
383
+ * }
384
+ * ```
385
+ */
386
+ getGroupMemberships: (limit?: number, sortOrder?: "ASC" | "DESC") => import("@aboutcircles/sdk-rpc").PagedQuery<GroupMembershipRow>;
387
+ /**
388
+ * Get detailed information about all groups this avatar is a member of
389
+ *
390
+ * This method fetches group memberships and enriches them with full group details including
391
+ * name, symbol, owner, treasury, mint handler, member count, and other properties.
392
+ *
393
+ * @param limit Maximum number of memberships to return (default: 50)
394
+ * @returns Array of group detail rows
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * // Get detailed information about all group memberships
399
+ * const groups = await avatar.group.getGroupMembershipsWithDetails();
400
+ *
401
+ * groups.forEach(group => {
402
+ * console.log(`Group: ${group.name} (${group.symbol})`);
403
+ * console.log(`Owner: ${group.owner}`);
404
+ * console.log(`Member count: ${group.memberCount}`);
405
+ * console.log(`Treasury: ${group.treasury}`);
406
+ * });
407
+ * ```
408
+ */
409
+ getGroupMembershipsWithDetails: (limit?: number) => Promise<GroupRow[]>;
410
+ };
411
+ }
412
+ //# sourceMappingURL=HumanAvatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HumanAvatar.d.ts","sourceRoot":"","sources":["../../src/avatars/HumanAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,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