@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.
- package/README.md +249 -0
- package/dist/Sdk.d.ts +282 -0
- package/dist/Sdk.d.ts.map +1 -0
- package/dist/Sdk.js +501 -0
- package/dist/avatars/BaseGroupAvatar.d.ts +97 -0
- package/dist/avatars/BaseGroupAvatar.d.ts.map +1 -0
- package/dist/avatars/BaseGroupAvatar.js +221 -0
- package/dist/avatars/CommonAvatar.d.ts +402 -0
- package/dist/avatars/CommonAvatar.d.ts.map +1 -0
- package/dist/avatars/CommonAvatar.js +644 -0
- package/dist/avatars/HumanAvatar.d.ts +412 -0
- package/dist/avatars/HumanAvatar.d.ts.map +1 -0
- package/dist/avatars/HumanAvatar.js +610 -0
- package/dist/avatars/OrganisationAvatar.d.ts +187 -0
- package/dist/avatars/OrganisationAvatar.d.ts.map +1 -0
- package/dist/avatars/OrganisationAvatar.js +310 -0
- package/dist/avatars/index.d.ts +9 -0
- package/dist/avatars/index.d.ts.map +1 -0
- package/dist/avatars/index.js +7 -0
- package/dist/ccip-dw9vbgp0.js +4533 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +131 -0
- package/dist/index-3hqyeswk.js +25 -0
- package/dist/index-pps0tkk3.js +356 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15308 -0
- package/dist/native-45v6vh69.js +20 -0
- package/dist/secp256k1-mjj44cj6.js +2115 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { BaseGroupContract } from '@aboutcircles/sdk-core';
|
|
2
|
+
import { cidV0ToHex, ValidationError } from '@aboutcircles/sdk-utils';
|
|
3
|
+
import { SdkError } from '../errors';
|
|
4
|
+
import { CommonAvatar } from './CommonAvatar';
|
|
5
|
+
/**
|
|
6
|
+
* BaseGroupAvatar class implementation
|
|
7
|
+
* Provides a simplified wrapper around Circles protocol for base group avatars
|
|
8
|
+
*
|
|
9
|
+
* This class represents a base group avatar in the Circles ecosystem and provides
|
|
10
|
+
* methods for managing trust relationships, group properties, and metadata.
|
|
11
|
+
*/
|
|
12
|
+
export class BaseGroupAvatar extends CommonAvatar {
|
|
13
|
+
baseGroup;
|
|
14
|
+
constructor(address, core, contractRunner, avatarInfo) {
|
|
15
|
+
super(address, core, contractRunner, avatarInfo);
|
|
16
|
+
// Initialize BaseGroup contract
|
|
17
|
+
this.baseGroup = new BaseGroupContract({
|
|
18
|
+
address: this.address,
|
|
19
|
+
rpcUrl: core.rpcUrl,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Override Balance Methods
|
|
24
|
+
// ============================================================================
|
|
25
|
+
balances = {
|
|
26
|
+
getTotal: async () => {
|
|
27
|
+
return await this.rpc.balance.getTotalBalance(this.address);
|
|
28
|
+
},
|
|
29
|
+
getTokenBalances: async () => {
|
|
30
|
+
return await this.rpc.balance.getTokenBalances(this.address);
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Get total supply of this group's token
|
|
34
|
+
*/
|
|
35
|
+
getTotalSupply: async () => {
|
|
36
|
+
const tokenId = await this.core.hubV2.toTokenId(this.address);
|
|
37
|
+
return await this.core.hubV2.totalSupply(tokenId);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// Extend Trust Methods with Group-Specific Features
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// We override add/remove to use baseGroup.trust() instead of hubV2.trust()
|
|
44
|
+
// View methods (isTrusting, isTrustedBy, getAll) are inherited from CommonAvatar
|
|
45
|
+
trust = {
|
|
46
|
+
add: async (avatar, expiry) => {
|
|
47
|
+
const trustExpiry = expiry ?? BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFF');
|
|
48
|
+
const avatars = Array.isArray(avatar) ? avatar : [avatar];
|
|
49
|
+
if (avatars.length === 0) {
|
|
50
|
+
throw ValidationError.missingParameter('avatar');
|
|
51
|
+
}
|
|
52
|
+
const transactions = avatars.map((trustee) => this.baseGroup.trust(trustee, trustExpiry));
|
|
53
|
+
return await this.runner.sendTransaction(transactions);
|
|
54
|
+
},
|
|
55
|
+
remove: async (avatar) => {
|
|
56
|
+
const avatars = Array.isArray(avatar) ? avatar : [avatar];
|
|
57
|
+
if (avatars.length === 0) {
|
|
58
|
+
throw ValidationError.missingParameter('avatar');
|
|
59
|
+
}
|
|
60
|
+
const untrustExpiry = BigInt(0);
|
|
61
|
+
const transactions = avatars.map((trustee) => this.baseGroup.trust(trustee, untrustExpiry));
|
|
62
|
+
return await this.runner.sendTransaction(transactions);
|
|
63
|
+
},
|
|
64
|
+
// View methods - same implementation as CommonAvatar
|
|
65
|
+
isTrusting: async (otherAvatar) => {
|
|
66
|
+
return await this.core.hubV2.isTrusted(this.address, otherAvatar);
|
|
67
|
+
},
|
|
68
|
+
isTrustedBy: async (otherAvatar) => {
|
|
69
|
+
return await this.core.hubV2.isTrusted(otherAvatar, this.address);
|
|
70
|
+
},
|
|
71
|
+
getAll: async () => {
|
|
72
|
+
return await this.rpc.trust.getAggregatedTrustRelations(this.address);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Trust a batch of members with membership condition checks
|
|
76
|
+
*
|
|
77
|
+
* This is a group-specific method that validates members against membership conditions
|
|
78
|
+
* before establishing trust.
|
|
79
|
+
*
|
|
80
|
+
* @param members Array of member addresses
|
|
81
|
+
* @param expiry Trust expiry timestamp. Defaults to 0
|
|
82
|
+
* @returns Transaction response
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Trust multiple members with condition checks
|
|
87
|
+
* await groupAvatar.trust.addBatchWithConditions(
|
|
88
|
+
* ['0x123...', '0x456...', '0x789...'],
|
|
89
|
+
* BigInt(Date.now() / 1000 + 31536000) // 1 year expiry
|
|
90
|
+
* );
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
addBatchWithConditions: async (members, expiry) => {
|
|
94
|
+
const trustExpiry = expiry ?? BigInt(0);
|
|
95
|
+
const tx = this.baseGroup.trustBatchWithConditions(members, trustExpiry);
|
|
96
|
+
return await this.runner.sendTransaction([tx]);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// Override Profile Methods to use baseGroup instead of nameRegistry
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// get() and update() methods are the same as CommonAvatar
|
|
103
|
+
// updateMetadata and registerShortName use baseGroup instead of nameRegistry
|
|
104
|
+
profile = {
|
|
105
|
+
get: async () => {
|
|
106
|
+
const profileCid = this.avatarInfo?.cidV0;
|
|
107
|
+
if (this._cachedProfile && this._cachedProfileCid === profileCid) {
|
|
108
|
+
return this._cachedProfile;
|
|
109
|
+
}
|
|
110
|
+
if (!profileCid) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const profileData = await this.profiles.get(profileCid);
|
|
115
|
+
if (profileData) {
|
|
116
|
+
this._cachedProfile = profileData;
|
|
117
|
+
this._cachedProfileCid = profileCid;
|
|
118
|
+
return this._cachedProfile;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.warn(`Couldn't load profile for CID ${profileCid}`, e);
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
},
|
|
126
|
+
update: async (profile) => {
|
|
127
|
+
const cid = await this.profiles.create(profile);
|
|
128
|
+
if (!cid) {
|
|
129
|
+
throw SdkError.configError('Profile service did not return a CID', { profile });
|
|
130
|
+
}
|
|
131
|
+
const updateReceipt = await this.profile.updateMetadata(cid);
|
|
132
|
+
if (!updateReceipt) {
|
|
133
|
+
throw SdkError.configError('Failed to update metadata digest in name registry', { cid });
|
|
134
|
+
}
|
|
135
|
+
if (this.avatarInfo) {
|
|
136
|
+
this.avatarInfo.cidV0 = cid;
|
|
137
|
+
}
|
|
138
|
+
this._cachedProfile = undefined;
|
|
139
|
+
this._cachedProfileCid = undefined;
|
|
140
|
+
return cid;
|
|
141
|
+
},
|
|
142
|
+
updateMetadata: async (cid) => {
|
|
143
|
+
const cidHex = cidV0ToHex(cid);
|
|
144
|
+
const updateTx = this.baseGroup.updateMetadataDigest(cidHex);
|
|
145
|
+
return await this.runner.sendTransaction([updateTx]);
|
|
146
|
+
},
|
|
147
|
+
registerShortName: async (nonce) => {
|
|
148
|
+
const registerTx = this.baseGroup.registerShortNameWithNonce(BigInt(nonce));
|
|
149
|
+
return await this.runner.sendTransaction([registerTx]);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
// ============================================================================
|
|
153
|
+
// Group-Specific Property Methods
|
|
154
|
+
// ============================================================================
|
|
155
|
+
properties = {
|
|
156
|
+
/**
|
|
157
|
+
* Get the owner of this group
|
|
158
|
+
*/
|
|
159
|
+
owner: async () => {
|
|
160
|
+
return await this.baseGroup.owner();
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Get the mint handler address
|
|
164
|
+
*/
|
|
165
|
+
mintHandler: async () => {
|
|
166
|
+
return await this.baseGroup.BASE_MINT_HANDLER();
|
|
167
|
+
},
|
|
168
|
+
/**
|
|
169
|
+
* Get the service address
|
|
170
|
+
*/
|
|
171
|
+
service: async () => {
|
|
172
|
+
return await this.baseGroup.service();
|
|
173
|
+
},
|
|
174
|
+
/**
|
|
175
|
+
* Get the fee collection address
|
|
176
|
+
*/
|
|
177
|
+
feeCollection: async () => {
|
|
178
|
+
return await this.baseGroup.feeCollection();
|
|
179
|
+
},
|
|
180
|
+
/**
|
|
181
|
+
* Get all membership conditions
|
|
182
|
+
*/
|
|
183
|
+
getMembershipConditions: async () => {
|
|
184
|
+
const conditions = await this.baseGroup.getMembershipConditions();
|
|
185
|
+
return Array.from(conditions);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Group Property Setters
|
|
190
|
+
// ============================================================================
|
|
191
|
+
setProperties = {
|
|
192
|
+
/**
|
|
193
|
+
* Set a new owner for this group
|
|
194
|
+
*/
|
|
195
|
+
owner: async (newOwner) => {
|
|
196
|
+
const tx = this.baseGroup.setOwner(newOwner);
|
|
197
|
+
return await this.runner.sendTransaction([tx]);
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* Set a new service address
|
|
201
|
+
*/
|
|
202
|
+
service: async (newService) => {
|
|
203
|
+
const tx = this.baseGroup.setService(newService);
|
|
204
|
+
return await this.runner.sendTransaction([tx]);
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Set a new fee collection address
|
|
208
|
+
*/
|
|
209
|
+
feeCollection: async (newFeeCollection) => {
|
|
210
|
+
const tx = this.baseGroup.setFeeCollection(newFeeCollection);
|
|
211
|
+
return await this.runner.sendTransaction([tx]);
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* Enable or disable a membership condition
|
|
215
|
+
*/
|
|
216
|
+
membershipCondition: async (condition, enabled) => {
|
|
217
|
+
const tx = this.baseGroup.setMembershipCondition(condition, enabled);
|
|
218
|
+
return await this.runner.sendTransaction([tx]);
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import type { Address, ContractRunner, Profile, AdvancedTransferOptions, FindPathParams, AvatarRow, TokenBalanceRow, AggregatedTrustRelation } from '@aboutcircles/sdk-types';
|
|
2
|
+
import type { TransactionReceipt } from 'viem';
|
|
3
|
+
import type { Core } from '@aboutcircles/sdk-core';
|
|
4
|
+
import type { CirclesEvent, Observable } from '@aboutcircles/sdk-rpc';
|
|
5
|
+
import { CirclesRpc } from '@aboutcircles/sdk-rpc';
|
|
6
|
+
import { Profiles } from '@aboutcircles/sdk-profiles';
|
|
7
|
+
import { TransferBuilder } from '@aboutcircles/sdk-transfers';
|
|
8
|
+
/**
|
|
9
|
+
* Advanced pathfinding options (reuses FindPathParams optional fields)
|
|
10
|
+
*/
|
|
11
|
+
export type PathfindingOptions = Omit<FindPathParams, 'from' | 'to' | 'targetFlow'>;
|
|
12
|
+
/**
|
|
13
|
+
* CommonAvatar abstract class
|
|
14
|
+
* Provides common functionality shared across all avatar types (Human, Organisation, Group)
|
|
15
|
+
*
|
|
16
|
+
* This class extracts common logic for:
|
|
17
|
+
* - Profile management (get, update, metadata)
|
|
18
|
+
* - Balance queries
|
|
19
|
+
* - Trust relationships
|
|
20
|
+
* - Transaction history
|
|
21
|
+
* - Event subscriptions
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class CommonAvatar {
|
|
24
|
+
readonly address: Address;
|
|
25
|
+
readonly avatarInfo: AvatarRow | undefined;
|
|
26
|
+
readonly core: Core;
|
|
27
|
+
readonly contractRunner?: ContractRunner;
|
|
28
|
+
events: Observable<CirclesEvent>;
|
|
29
|
+
protected readonly runner: ContractRunner;
|
|
30
|
+
protected readonly profiles: Profiles;
|
|
31
|
+
protected readonly rpc: CirclesRpc;
|
|
32
|
+
protected readonly transferBuilder: TransferBuilder;
|
|
33
|
+
protected _cachedProfile?: Profile;
|
|
34
|
+
protected _cachedProfileCid?: string;
|
|
35
|
+
protected _eventSubscription?: () => void;
|
|
36
|
+
constructor(address: Address, core: Core, contractRunner?: ContractRunner, avatarInfo?: AvatarRow);
|
|
37
|
+
readonly balances: {
|
|
38
|
+
/**
|
|
39
|
+
* Get total balance across all tokens
|
|
40
|
+
*/
|
|
41
|
+
getTotal: () => Promise<bigint>;
|
|
42
|
+
/**
|
|
43
|
+
* Get detailed token balances
|
|
44
|
+
*/
|
|
45
|
+
getTokenBalances: () => Promise<TokenBalanceRow[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get total supply of this avatar's token
|
|
48
|
+
* Override this in subclasses if needed
|
|
49
|
+
*/
|
|
50
|
+
getTotalSupply: () => Promise<bigint>;
|
|
51
|
+
};
|
|
52
|
+
readonly trust: {
|
|
53
|
+
/**
|
|
54
|
+
* Trust another avatar or multiple avatars
|
|
55
|
+
*
|
|
56
|
+
* When using Safe runner, all trust operations are executed atomically in a single transaction.
|
|
57
|
+
* When using EOA runner, only single avatars are supported (pass array length 1).
|
|
58
|
+
*
|
|
59
|
+
* @param avatar Single avatar address or array of avatar addresses
|
|
60
|
+
* @param expiry Trust expiry timestamp (in seconds since epoch). Defaults to max uint96 for indefinite trust
|
|
61
|
+
* @returns Transaction response
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Trust single avatar indefinitely
|
|
66
|
+
* await avatar.trust.add('0x123...');
|
|
67
|
+
*
|
|
68
|
+
* // Trust with custom expiry
|
|
69
|
+
* const oneYear = BigInt(Date.now() / 1000 + 31536000);
|
|
70
|
+
* await avatar.trust.add('0x123...', oneYear);
|
|
71
|
+
*
|
|
72
|
+
* // Trust multiple avatars (Safe only - throws error with EOA)
|
|
73
|
+
* await avatar.trust.add(['0x123...', '0x456...', '0x789...']);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
add: (avatar: Address | Address[], expiry?: bigint) => Promise<TransactionReceipt>;
|
|
77
|
+
/**
|
|
78
|
+
* Remove trust from another avatar or multiple avatars
|
|
79
|
+
* This is done by setting the trust expiry to 0
|
|
80
|
+
*
|
|
81
|
+
* When using Safe runner, all operations are batched atomically.
|
|
82
|
+
* When using EOA runner, only single avatars are supported (pass array length 1).
|
|
83
|
+
*
|
|
84
|
+
* @param avatar Single avatar address or array of avatar addresses
|
|
85
|
+
* @returns Transaction response
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Remove trust from single avatar
|
|
90
|
+
* await avatar.trust.remove('0x123...');
|
|
91
|
+
*
|
|
92
|
+
* // Remove trust from multiple avatars (Safe only)
|
|
93
|
+
* await avatar.trust.remove(['0x123...', '0x456...', '0x789...']);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
remove: (avatar: Address | Address[]) => Promise<TransactionReceipt>;
|
|
97
|
+
/**
|
|
98
|
+
* Check if this avatar trusts another avatar
|
|
99
|
+
* @param otherAvatar The avatar address to check
|
|
100
|
+
* @returns True if this avatar trusts the other avatar
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const trusting = await avatar.trust.isTrusting('0x123...');
|
|
105
|
+
* if (trusting) {
|
|
106
|
+
* console.log('You trust this avatar');
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
isTrusting: (otherAvatar: Address) => Promise<boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* Check if another avatar trusts this avatar
|
|
113
|
+
* @param otherAvatar The avatar address to check
|
|
114
|
+
* @returns True if the other avatar trusts this avatar
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const trustedBy = await avatar.trust.isTrustedBy('0x123...');
|
|
119
|
+
* if (trustedBy) {
|
|
120
|
+
* console.log('This avatar trusts you');
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
isTrustedBy: (otherAvatar: Address) => Promise<boolean>;
|
|
125
|
+
/**
|
|
126
|
+
* Get all trust relations for this avatar
|
|
127
|
+
*/
|
|
128
|
+
getAll: () => Promise<AggregatedTrustRelation[]>;
|
|
129
|
+
};
|
|
130
|
+
readonly profile: {
|
|
131
|
+
/**
|
|
132
|
+
* Get the profile for this avatar from IPFS
|
|
133
|
+
* Uses caching to avoid redundant fetches for the same CID
|
|
134
|
+
*
|
|
135
|
+
* @returns The profile data, or undefined if no profile is set or fetch fails
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const profile = await avatar.profile.get();
|
|
140
|
+
* if (profile) {
|
|
141
|
+
* console.log('Name:', profile.name);
|
|
142
|
+
* console.log('Description:', profile.description);
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
get: () => Promise<Profile | undefined>;
|
|
147
|
+
/**
|
|
148
|
+
* Update the profile for this avatar
|
|
149
|
+
* This will:
|
|
150
|
+
* 1. Pin the new profile data to IPFS via the profile service
|
|
151
|
+
* 2. Update the metadata digest in the name registry contract
|
|
152
|
+
*
|
|
153
|
+
* @param profile The profile data to update
|
|
154
|
+
* @returns The CID of the newly pinned profile
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const profile = {
|
|
159
|
+
* name: 'Alice',
|
|
160
|
+
* description: 'Hello, Circles!',
|
|
161
|
+
* avatarUrl: 'https://example.com/avatar.png'
|
|
162
|
+
* };
|
|
163
|
+
*
|
|
164
|
+
* const cid = await avatar.profile.update(profile);
|
|
165
|
+
* console.log('Profile updated with CID:', cid);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
update: (profile: Profile) => Promise<string>;
|
|
169
|
+
/**
|
|
170
|
+
* Update the metadata digest (CID) in the name registry
|
|
171
|
+
* This updates the on-chain pointer to the profile data stored on IPFS
|
|
172
|
+
*
|
|
173
|
+
* @param cid The IPFS CIDv0 to set as the metadata digest (e.g., "QmXxxx...")
|
|
174
|
+
* @returns Transaction receipt
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const receipt = await avatar.profile.updateMetadata('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG');
|
|
179
|
+
* console.log('Metadata updated, tx hash:', receipt.hash);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
updateMetadata: (cid: string) => Promise<TransactionReceipt>;
|
|
183
|
+
/**
|
|
184
|
+
* Register a short name for this avatar using a specific nonce
|
|
185
|
+
* Short names are numeric identifiers that can be used instead of addresses
|
|
186
|
+
*
|
|
187
|
+
* @param nonce The nonce to use for generating the short name
|
|
188
|
+
* @returns Transaction receipt
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Find available nonce first
|
|
193
|
+
* const [shortName, nonce] = await core.nameRegistry.searchShortName(avatar.address);
|
|
194
|
+
* console.log('Available short name:', shortName.toString());
|
|
195
|
+
*
|
|
196
|
+
* // Register it
|
|
197
|
+
* const receipt = await avatar.profile.registerShortName(Number(nonce));
|
|
198
|
+
* console.log('Short name registered, tx hash:', receipt.hash);
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
registerShortName: (nonce: number) => Promise<TransactionReceipt>;
|
|
202
|
+
};
|
|
203
|
+
readonly history: {
|
|
204
|
+
/**
|
|
205
|
+
* Get transaction history for this avatar using cursor-based pagination
|
|
206
|
+
* Returns incoming/outgoing transactions and minting events
|
|
207
|
+
*
|
|
208
|
+
* @param limit Number of transactions per page (default: 50)
|
|
209
|
+
* @param sortOrder Sort order for results (default: 'DESC')
|
|
210
|
+
* @returns PagedQuery instance for iterating through transactions
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const query = avatar.history.getTransactions(20);
|
|
215
|
+
*
|
|
216
|
+
* // Get first page
|
|
217
|
+
* await query.queryNextPage();
|
|
218
|
+
* query.currentPage.results.forEach(tx => {
|
|
219
|
+
* console.log(`${tx.from} -> ${tx.to}: ${tx.circles} CRC`);
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* // Get next page if available
|
|
223
|
+
* if (query.currentPage.hasMore) {
|
|
224
|
+
* await query.queryNextPage();
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
getTransactions: (limit?: number, sortOrder?: "ASC" | "DESC") => import("@aboutcircles/sdk-rpc").PagedQuery<import("@aboutcircles/sdk-rpc").TransactionHistoryRow>;
|
|
229
|
+
};
|
|
230
|
+
readonly transfer: {
|
|
231
|
+
/**
|
|
232
|
+
* Send Circles tokens directly to another address
|
|
233
|
+
* This is a simple direct transfer without pathfinding
|
|
234
|
+
*
|
|
235
|
+
* Supports both ERC1155 (personal/group tokens) and ERC20 (wrapped tokens) transfers.
|
|
236
|
+
* The token type is automatically detected and the appropriate transfer method is used.
|
|
237
|
+
*
|
|
238
|
+
* For transfers using pathfinding (which can use trust network and multiple token types),
|
|
239
|
+
* use transfer.advanced() instead.
|
|
240
|
+
*
|
|
241
|
+
* @param to Recipient address
|
|
242
|
+
* @param amount Amount to transfer (in atto-circles)
|
|
243
|
+
* @param tokenAddress Token address to transfer (defaults to sender's personal token)
|
|
244
|
+
* @param txData Optional transaction data (only used for ERC1155 transfers)
|
|
245
|
+
* @returns Transaction receipt
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // Send 100 of your personal CRC directly
|
|
250
|
+
* const receipt = await avatar.transfer.direct('0x123...', BigInt(100e18));
|
|
251
|
+
*
|
|
252
|
+
* // Send wrapped tokens
|
|
253
|
+
* const receipt = await avatar.transfer.direct('0x123...', BigInt(100e18), '0xWrappedTokenAddress...');
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
direct: (to: Address, amount: bigint, tokenAddress?: Address, txData?: Uint8Array) => Promise<TransactionReceipt>;
|
|
257
|
+
/**
|
|
258
|
+
* Send tokens using pathfinding through the trust network
|
|
259
|
+
* This enables transfers even when you don't have the recipient's token
|
|
260
|
+
*
|
|
261
|
+
* @param to Recipient address
|
|
262
|
+
* @param amount Amount to transfer (in atto-circles or CRC)
|
|
263
|
+
* @param options Advanced transfer options (pathfinding parameters)
|
|
264
|
+
* @returns Transaction receipt
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* // Send 100 CRC using pathfinding
|
|
269
|
+
* await avatar.transfer.advanced('0x123...', BigInt(100e18));
|
|
270
|
+
*
|
|
271
|
+
* // With custom options
|
|
272
|
+
* await avatar.transfer.advanced('0x123...', 100, {
|
|
273
|
+
* maxTransfers: 5,
|
|
274
|
+
* maxDistance: 3
|
|
275
|
+
* });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
advanced: (to: Address, amount: number | bigint, options?: AdvancedTransferOptions) => Promise<TransactionReceipt>;
|
|
279
|
+
/**
|
|
280
|
+
* Get the maximum amount that can be transferred to an address using pathfinding
|
|
281
|
+
*
|
|
282
|
+
* @param to Recipient address
|
|
283
|
+
* @returns Maximum transferable amount (in atto-circles)
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const maxAmount = await avatar.transfer.getMaxAmount('0x123...');
|
|
288
|
+
* console.log(`Can transfer up to: ${maxAmount}`);
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
getMaxAmount: (to: Address) => Promise<bigint>;
|
|
292
|
+
/**
|
|
293
|
+
* Get the maximum amount that can be transferred with custom pathfinding options
|
|
294
|
+
*
|
|
295
|
+
* @param to Recipient address
|
|
296
|
+
* @param options Pathfinding options (maxTransfers, maxDistance, etc.)
|
|
297
|
+
* @returns Maximum transferable amount (in atto-circles)
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const maxAmount = await avatar.transfer.getMaxAmountAdvanced('0x123...', {
|
|
302
|
+
* maxTransfers: 3,
|
|
303
|
+
* maxDistance: 2
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
getMaxAmountAdvanced: (to: Address, options?: PathfindingOptions) => Promise<bigint>;
|
|
308
|
+
};
|
|
309
|
+
readonly wrap: {
|
|
310
|
+
/**
|
|
311
|
+
* Wrap personal CRC tokens as demurraged ERC20 tokens
|
|
312
|
+
*
|
|
313
|
+
* @param avatarAddress The avatar whose tokens to wrap
|
|
314
|
+
* @param amount Amount to wrap (in atto-circles)
|
|
315
|
+
* @returns Transaction receipt
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* // Wrap 100 CRC as demurraged ERC20
|
|
320
|
+
* const receipt = await avatar.wrap.asDemurraged(avatar.address, BigInt(100e18));
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
asDemurraged: (avatarAddress: Address, amount: bigint) => Promise<TransactionReceipt>;
|
|
324
|
+
/**
|
|
325
|
+
* Wrap personal CRC tokens as inflationary ERC20 tokens
|
|
326
|
+
*
|
|
327
|
+
* @param avatarAddress The avatar whose tokens to wrap
|
|
328
|
+
* @param amount Amount to wrap (in atto-circles)
|
|
329
|
+
* @returns Transaction receipt
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* // Wrap 100 CRC as inflationary ERC20
|
|
334
|
+
* const receipt = await avatar.wrap.asInflationary(avatar.address, BigInt(100e18));
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
asInflationary: (avatarAddress: Address, amount: bigint) => Promise<TransactionReceipt>;
|
|
338
|
+
/**
|
|
339
|
+
* Unwrap demurraged ERC20 tokens back to personal CRC
|
|
340
|
+
*
|
|
341
|
+
* @param tokenAddress The demurraged token address to unwrap
|
|
342
|
+
* @param amount Amount to unwrap (in atto-circles)
|
|
343
|
+
* @returns Transaction receipt
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const receipt = await avatar.wrap.unwrapDemurraged('0xTokenAddress...', BigInt(100e18));
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
unwrapDemurraged: (tokenAddress: Address, amount: bigint) => Promise<TransactionReceipt>;
|
|
351
|
+
/**
|
|
352
|
+
* Unwrap inflationary ERC20 tokens back to personal CRC
|
|
353
|
+
*
|
|
354
|
+
* @param tokenAddress The inflationary token address to unwrap
|
|
355
|
+
* @param amount Amount to unwrap (in atto-circles)
|
|
356
|
+
* @returns Transaction receipt
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const receipt = await avatar.wrap.unwrapInflationary('0xTokenAddress...', BigInt(100e18));
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
unwrapInflationary: (tokenAddress: Address, amount: bigint) => Promise<TransactionReceipt>;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Subscribe to Circles events for this avatar
|
|
367
|
+
* Events are filtered to only include events related to this avatar's address
|
|
368
|
+
*
|
|
369
|
+
* @returns Promise that resolves when subscription is established
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* await avatar.subscribeToEvents();
|
|
374
|
+
*
|
|
375
|
+
* // Listen for events
|
|
376
|
+
* avatar.events.subscribe((event) => {
|
|
377
|
+
* console.log('Event received:', event.$event, event);
|
|
378
|
+
*
|
|
379
|
+
* if (event.$event === 'CrcV2_PersonalMint') {
|
|
380
|
+
* console.log('Minted:', event.amount);
|
|
381
|
+
* }
|
|
382
|
+
* });
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
subscribeToEvents(): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Unsubscribe from events
|
|
388
|
+
* Cleans up the WebSocket connection and event listeners
|
|
389
|
+
*/
|
|
390
|
+
unsubscribeFromEvents(): void;
|
|
391
|
+
/**
|
|
392
|
+
* Transfer ERC1155 tokens using safeTransferFrom
|
|
393
|
+
* @protected
|
|
394
|
+
*/
|
|
395
|
+
protected _transferErc1155(tokenAddress: Address, to: Address, amount: bigint, txData?: Uint8Array): Promise<TransactionReceipt>;
|
|
396
|
+
/**
|
|
397
|
+
* Transfer ERC20 tokens using the standard transfer function
|
|
398
|
+
* @protected
|
|
399
|
+
*/
|
|
400
|
+
protected _transferErc20(to: Address, amount: bigint, tokenAddress: Address): Promise<TransactionReceipt>;
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=CommonAvatar.d.ts.map
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