@aboutcircles/sdk 0.1.0 → 0.1.2
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 +19 -22
- package/dist/Sdk.d.ts +5 -1
- package/dist/Sdk.d.ts.map +1 -1
- package/dist/Sdk.js +20 -6
- package/dist/avatars/CommonAvatar.d.ts +2 -0
- package/dist/avatars/CommonAvatar.d.ts.map +1 -1
- package/dist/avatars/CommonAvatar.js +18 -3
- package/dist/avatars/HumanAvatar.d.ts +38 -1
- package/dist/avatars/HumanAvatar.d.ts.map +1 -1
- package/dist/avatars/HumanAvatar.js +97 -1
- package/dist/ccip-bj4hszbh.js +4584 -0
- package/dist/index.js +18982 -12250
- package/dist/secp256k1-qqsamwnk.js +2117 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -203,27 +203,23 @@ await sdk.profiles.createOrUpdate({
|
|
|
203
203
|
|
|
204
204
|
## Implementation Status
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
✅ **Status**: This SDK is feature-complete and production-ready. All core functionality has been implemented.
|
|
207
207
|
|
|
208
208
|
### Implemented Features
|
|
209
209
|
|
|
210
210
|
- ✅ SDK initialization with configuration
|
|
211
|
-
- ✅ Avatar retrieval (getAvatar)
|
|
212
|
-
- ✅
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
- Profile updates
|
|
224
|
-
- Group operations
|
|
225
|
-
- Token wrapping
|
|
226
|
-
- Event streaming
|
|
211
|
+
- ✅ Avatar retrieval and type detection (getAvatar)
|
|
212
|
+
- ✅ Registration methods (asHuman, asOrganization, asGroup)
|
|
213
|
+
- ✅ Balance operations (total, detailed token balances)
|
|
214
|
+
- ✅ Transfer operations (direct transfers, pathfinding with advanced options)
|
|
215
|
+
- ✅ Trust operations (add, remove, check trust status)
|
|
216
|
+
- ✅ Personal token minting and management
|
|
217
|
+
- ✅ Profile management (get, update, metadata, short names)
|
|
218
|
+
- ✅ Group operations (members, holders, collateral, treasury)
|
|
219
|
+
- ✅ Token wrapping (demurraged and inflationary ERC20)
|
|
220
|
+
- ✅ Event subscriptions and streaming
|
|
221
|
+
- ✅ Transaction history
|
|
222
|
+
- ✅ Profile creation and management via IPFS
|
|
227
223
|
|
|
228
224
|
## Architecture
|
|
229
225
|
|
|
@@ -237,12 +233,13 @@ The SDK package wraps and simplifies the following packages:
|
|
|
237
233
|
|
|
238
234
|
## Contributing
|
|
239
235
|
|
|
240
|
-
To
|
|
236
|
+
To extend or improve the SDK:
|
|
241
237
|
|
|
242
|
-
1.
|
|
243
|
-
2.
|
|
244
|
-
3.
|
|
245
|
-
4.
|
|
238
|
+
1. Update existing methods or add new features as needed
|
|
239
|
+
2. Leverage the underlying packages (core, rpc, profiles, transfers, etc.)
|
|
240
|
+
3. Add tests and update documentation
|
|
241
|
+
4. Ensure all changes maintain backward compatibility
|
|
242
|
+
5. Follow the established patterns and code style in the SDK
|
|
246
243
|
|
|
247
244
|
## License
|
|
248
245
|
|
package/dist/Sdk.d.ts
CHANGED
|
@@ -48,9 +48,13 @@ export declare class Sdk {
|
|
|
48
48
|
/**
|
|
49
49
|
* Get an avatar by address
|
|
50
50
|
* Automatically detects the avatar type and returns the appropriate avatar instance
|
|
51
|
+
*
|
|
52
|
+
* @param avatarAddress The address of the avatar to fetch
|
|
53
|
+
* @param autoSubscribeEvents Whether to automatically subscribe to events for this avatar (default: false)
|
|
54
|
+
* If true, waits for event subscription to complete before returning
|
|
51
55
|
* @returns HumanAvatar, OrganisationAvatar, or BaseGroupAvatar depending on type
|
|
52
56
|
*/
|
|
53
|
-
getAvatar(avatarAddress: Address): Promise<HumanAvatar | OrganisationAvatar | BaseGroupAvatar>;
|
|
57
|
+
getAvatar(avatarAddress: Address, autoSubscribeEvents?: boolean): Promise<HumanAvatar | OrganisationAvatar | BaseGroupAvatar>;
|
|
54
58
|
/**
|
|
55
59
|
* Registration methods for creating new Circles identities
|
|
56
60
|
*/
|
package/dist/Sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sdk.d.ts","sourceRoot":"","sources":["../src/Sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,cAAc,EACd,OAAO,EAEP,YAAY,EACZ,SAAS,EAEV,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAiB,IAAI,EAAkC,MAAM,wBAAwB,CAAC;AAE7F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAI7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,qBAAa,GAAG;IACd,SAAgB,aAAa,EAAE,aAAa,CAAC;IAC7C,SAAgB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChD,SAAgB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxC,SAAgB,IAAI,EAAE,IAAI,CAAC;IAC3B,SAAgB,GAAG,EAAE,UAAU,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAW;IAE1C,SAAgB,IAAI,EAAE,WAAW,CAU/B;IAEF;;;;;;OAMG;gBACS,MAAM,GAAE,aAAkC,EAAE,cAAc,CAAC,EAAE,cAAc;IAsBvF
|
|
1
|
+
{"version":3,"file":"Sdk.d.ts","sourceRoot":"","sources":["../src/Sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,cAAc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;;;;;;;;;;;;;;;;;;;;;;;WA4BG;yBAEM,OAAO,WACL,OAAO,iBACD,OAAO,qBACH,OAAO,EAAE,QACtB,MAAM,UACJ,MAAM,WACL,OAAO,GAAG,MAAM,KACxB,OAAO,CAAC,eAAe,CAAC;MAsF3B;IAEF;;OAEG;IACH,SAAgB,QAAQ;QACtB;;;;WAIG;0BACqB,OAAO,KAAG,OAAO,CAAC,MAAM,CAAC;QAIjD;;;;WAIG;mBACc,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;MAGtD;IAEF;;OAEG;IACH,SAAgB,MAAM;QACpB;;;;WAIG;0CACqC,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;QAIlE;;;;WAIG;wCACmC,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;QAIhE;;;;;;;;;;;;;;;;;;;WAmBG;mCAEa,OAAO,UACd,MAAM,cACF,SAAS;MAItB;IAEF;;OAEG;IACH,SAAgB,MAAM;QACpB;;;;WAIG;0BACqB,OAAO,KAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QAIhE;;;;;;;;;;;;;;;;;;;;;;;;;;;WA2BG;mCAEa,OAAO,UACd,MAAM,cACF,KAAK,GAAG,MAAM;QAK3B;;;;;;;;;;;;;;;;;;;WAmBG;sCACiC,OAAO,KAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QAcrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6BG;mCACwB,OAAO,UAAS,MAAM,KAAS,UAAU,CAAC,mBAAmB,CAAC;MAGzF;CACH"}
|
package/dist/Sdk.js
CHANGED
|
@@ -78,21 +78,35 @@ export class Sdk {
|
|
|
78
78
|
/**
|
|
79
79
|
* Get an avatar by address
|
|
80
80
|
* Automatically detects the avatar type and returns the appropriate avatar instance
|
|
81
|
+
*
|
|
82
|
+
* @param avatarAddress The address of the avatar to fetch
|
|
83
|
+
* @param autoSubscribeEvents Whether to automatically subscribe to events for this avatar (default: false)
|
|
84
|
+
* If true, waits for event subscription to complete before returning
|
|
81
85
|
* @returns HumanAvatar, OrganisationAvatar, or BaseGroupAvatar depending on type
|
|
82
86
|
*/
|
|
83
|
-
async getAvatar(avatarAddress) {
|
|
87
|
+
async getAvatar(avatarAddress, autoSubscribeEvents = false) {
|
|
84
88
|
try {
|
|
85
89
|
const avatarInfo = await this.rpc.avatar.getAvatarInfo(avatarAddress);
|
|
86
90
|
// Detect avatar type and return appropriate avatar class
|
|
87
91
|
const avatarType = avatarInfo?.type;
|
|
92
|
+
let avatar;
|
|
88
93
|
if (avatarType === 'CrcV2_RegisterGroup') {
|
|
89
|
-
|
|
94
|
+
avatar = new BaseGroupAvatar(avatarAddress, this.core, this.contractRunner, avatarInfo);
|
|
95
|
+
}
|
|
96
|
+
else if (avatarType === 'CrcV2_RegisterOrganization') {
|
|
97
|
+
avatar = new OrganisationAvatar(avatarAddress, this.core, this.contractRunner, avatarInfo);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Default to HumanAvatar for human type
|
|
101
|
+
avatar = new HumanAvatar(avatarAddress, this.core, this.contractRunner, avatarInfo);
|
|
90
102
|
}
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
// If auto-subscription is enabled, wait for it to complete before returning
|
|
104
|
+
// This prevents race conditions where stores subscribe to avatar.events before it's ready
|
|
105
|
+
if (autoSubscribeEvents) {
|
|
106
|
+
console.log('🔔 Sdk.getAvatar: Auto-subscribing to events for', avatarAddress);
|
|
107
|
+
await avatar.subscribeToEvents();
|
|
93
108
|
}
|
|
94
|
-
|
|
95
|
-
return new HumanAvatar(avatarAddress, this.core, this.contractRunner, avatarInfo);
|
|
109
|
+
return avatar;
|
|
96
110
|
}
|
|
97
111
|
catch (error) {
|
|
98
112
|
throw SdkError.avatarNotFound(avatarAddress);
|
|
@@ -33,6 +33,7 @@ export declare abstract class CommonAvatar {
|
|
|
33
33
|
protected _cachedProfile?: Profile;
|
|
34
34
|
protected _cachedProfileCid?: string;
|
|
35
35
|
protected _eventSubscription?: () => void;
|
|
36
|
+
private _hasSubscribed;
|
|
36
37
|
constructor(address: Address, core: Core, contractRunner?: ContractRunner, avatarInfo?: AvatarRow);
|
|
37
38
|
readonly balances: {
|
|
38
39
|
/**
|
|
@@ -365,6 +366,7 @@ export declare abstract class CommonAvatar {
|
|
|
365
366
|
/**
|
|
366
367
|
* Subscribe to Circles events for this avatar
|
|
367
368
|
* Events are filtered to only include events related to this avatar's address
|
|
369
|
+
* This method is idempotent - calling it multiple times will not create duplicate subscriptions
|
|
368
370
|
*
|
|
369
371
|
* @returns Promise that resolves when subscription is established
|
|
370
372
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommonAvatar.d.ts","sourceRoot":"","sources":["../../src/avatars/CommonAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,OAAO,EACP,uBAAuB,EACvB,cAAc,EACd,SAAS,EACT,eAAe,EACf,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAiC,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAQtD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAAC,CAAC;AAEpF;;;;;;;;;;GAUG;AACH,8BAAsB,YAAY;IAChC,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,UAAU,EAAE,SAAS,GAAG,SAAS,CAAC;IAClD,SAAgB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QAS9B;;;;;;;;;;;WAWG;2CAEa,OAAO,UACb,MAAM,KACb,OAAO,CAAC,kBAAkB,CAAC;MAQ9B;IAMF;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC;;;OAGG;IACH,qBAAqB,IAAI,IAAI;IAW7B;;;OAGG;cACa,gBAAgB,CAC9B,YAAY,EAAE,OAAO,EACrB,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,kBAAkB,CAAC;IAoB9B;;;OAGG;cACa,cAAc,CAC5B,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,kBAAkB,CAAC;CAwB/B"}
|
|
@@ -29,6 +29,7 @@ export class CommonAvatar {
|
|
|
29
29
|
_cachedProfile;
|
|
30
30
|
_cachedProfileCid;
|
|
31
31
|
_eventSubscription;
|
|
32
|
+
_hasSubscribed = false;
|
|
32
33
|
constructor(address, core, contractRunner, avatarInfo) {
|
|
33
34
|
this.address = address;
|
|
34
35
|
this.core = core;
|
|
@@ -49,6 +50,7 @@ export class CommonAvatar {
|
|
|
49
50
|
// Initialize transfer builder
|
|
50
51
|
this.transferBuilder = new TransferBuilder(core);
|
|
51
52
|
// Event subscription is optional - initialize with stub observable
|
|
53
|
+
// Actual subscription is handled by Sdk.getAvatar() when autoSubscribeEvents is enabled
|
|
52
54
|
const stub = ObservableClass.create();
|
|
53
55
|
this.events = stub.property;
|
|
54
56
|
}
|
|
@@ -565,6 +567,7 @@ export class CommonAvatar {
|
|
|
565
567
|
/**
|
|
566
568
|
* Subscribe to Circles events for this avatar
|
|
567
569
|
* Events are filtered to only include events related to this avatar's address
|
|
570
|
+
* This method is idempotent - calling it multiple times will not create duplicate subscriptions
|
|
568
571
|
*
|
|
569
572
|
* @returns Promise that resolves when subscription is established
|
|
570
573
|
*
|
|
@@ -583,9 +586,21 @@ export class CommonAvatar {
|
|
|
583
586
|
* ```
|
|
584
587
|
*/
|
|
585
588
|
async subscribeToEvents() {
|
|
586
|
-
//
|
|
587
|
-
|
|
588
|
-
|
|
589
|
+
// Make idempotent - only subscribe once
|
|
590
|
+
if (this._hasSubscribed) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this._hasSubscribed = true;
|
|
594
|
+
try {
|
|
595
|
+
// Subscribe to events via RPC WebSocket
|
|
596
|
+
const observable = await this.rpc.client.subscribe(this.address);
|
|
597
|
+
this.events = observable;
|
|
598
|
+
}
|
|
599
|
+
catch (e) {
|
|
600
|
+
// Reset flag on error so it can be retried
|
|
601
|
+
this._hasSubscribed = false;
|
|
602
|
+
throw SdkError.operationFailed('subscribeToEvents', 'Failed to subscribe to avatar events', e);
|
|
603
|
+
}
|
|
589
604
|
}
|
|
590
605
|
/**
|
|
591
606
|
* Unsubscribe from events
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address, AvatarRow, ContractRunner, TokenBalanceRow, GroupMembershipRow, GroupRow } from '@aboutcircles/sdk-types';
|
|
2
|
-
import type { TransactionReceipt } from 'viem';
|
|
2
|
+
import type { TransactionReceipt, Hex } from 'viem';
|
|
3
3
|
import type { Core } from '@aboutcircles/sdk-core';
|
|
4
4
|
import { CommonAvatar, type PathfindingOptions } from './CommonAvatar';
|
|
5
5
|
/**
|
|
@@ -175,6 +175,43 @@ export declare class HumanAvatar extends CommonAvatar {
|
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
177
|
getEscrowedAmount: (inviter: Address, invitee: Address) => Promise<import("@aboutcircles/sdk-types").EscrowedAmountAndDays>;
|
|
178
|
+
/**
|
|
179
|
+
* Generate new invitations and return associated secrets and signer addresses
|
|
180
|
+
*
|
|
181
|
+
* This function:
|
|
182
|
+
* 1. Calls invitationFarm.claimInvites() to get invitation IDs via eth_call
|
|
183
|
+
* 2. Generates random secrets for each invitation
|
|
184
|
+
* 3. Derives signer addresses from the secrets using ECDSA
|
|
185
|
+
* 4. Batches the claimInvites write call with safeBatchTransferFrom to transfer
|
|
186
|
+
* invitation tokens (96 CRC each) to the invitation module
|
|
187
|
+
* 5. Returns the list of secrets and corresponding signers
|
|
188
|
+
*
|
|
189
|
+
* The data field in the batch transfer contains the count of generated secrets,
|
|
190
|
+
* which the contract uses to validate the transfer.
|
|
191
|
+
*
|
|
192
|
+
* @param numberOfInvites The number of invitations to generate
|
|
193
|
+
* @returns Promise containing arrays of secrets and signers for each generated invitation
|
|
194
|
+
*
|
|
195
|
+
* @throws {SdkError} If the transaction fails or invitations cannot be claimed
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* // Generate 5 invitations
|
|
200
|
+
* const result = await avatar.invite.generateInvites(5n);
|
|
201
|
+
*
|
|
202
|
+
* console.log('Generated invitations:');
|
|
203
|
+
* result.secrets.forEach((secret, index) => {
|
|
204
|
+
* console.log(`Invitation ${index + 1}:`);
|
|
205
|
+
* console.log(` Secret: ${secret}`);
|
|
206
|
+
* console.log(` Signer: ${result.signers[index]}`);
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
generateInvites: (numberOfInvites: bigint) => Promise<{
|
|
211
|
+
secrets: Hex[];
|
|
212
|
+
signers: Address[];
|
|
213
|
+
transactionReceipt: TransactionReceipt;
|
|
214
|
+
}>;
|
|
178
215
|
};
|
|
179
216
|
readonly personalToken: {
|
|
180
217
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HumanAvatar.d.ts","sourceRoot":"","sources":["../../src/avatars/HumanAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,QAAQ,EAET,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;
|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,KAAG,OAAO,CAAC,OAAO,EAAE,CAAC;;MAUrE;IAGF,SAAgB,KAAK;;YAnFjB;;;;eAIG;2BACkB,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;YAQ/C;;;;eAIG;iCACwB,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;YAQrD;;;;eAIG;8BACqB,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;YAQlD;;;;eAIG;6BACoB,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;YAQjD;;;;eAIG;mCAC0B,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;YAQvD;;;;eAIG;6CACoC,OAAO,KAAG,OAAO,CAAC,OAAO,EAAE,CAAC;;QAgBrE;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;sCAC0B,MAAM,cAAkB,KAAK,GAAG,MAAM;QAInE;;;;;;;;;;;;;;;;;;;;;WAqBG;iDAC2C,MAAM,KAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;MAyB/E;CAaH"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ValidationError } from '@aboutcircles/sdk-utils';
|
|
2
2
|
import { SdkError } from '../errors';
|
|
3
3
|
import { BaseGroupContract } from '@aboutcircles/sdk-core';
|
|
4
|
-
import { encodeAbiParameters, parseAbiParameters } from 'viem';
|
|
4
|
+
import { encodeAbiParameters, parseAbiParameters, encodeFunctionData } from 'viem';
|
|
5
|
+
import { referralsModuleAbi } from '@aboutcircles/sdk-abis';
|
|
6
|
+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
5
7
|
import { CommonAvatar } from './CommonAvatar';
|
|
6
8
|
/**
|
|
7
9
|
* HumanAvatar class implementation
|
|
@@ -246,6 +248,100 @@ export class HumanAvatar extends CommonAvatar {
|
|
|
246
248
|
getEscrowedAmount: async (inviter, invitee) => {
|
|
247
249
|
return await this.core.invitationEscrow.getEscrowedAmountAndDays(inviter, invitee);
|
|
248
250
|
},
|
|
251
|
+
/**
|
|
252
|
+
* Generate new invitations and return associated secrets and signer addresses
|
|
253
|
+
*
|
|
254
|
+
* This function:
|
|
255
|
+
* 1. Calls invitationFarm.claimInvites() to get invitation IDs via eth_call
|
|
256
|
+
* 2. Generates random secrets for each invitation
|
|
257
|
+
* 3. Derives signer addresses from the secrets using ECDSA
|
|
258
|
+
* 4. Batches the claimInvites write call with safeBatchTransferFrom to transfer
|
|
259
|
+
* invitation tokens (96 CRC each) to the invitation module
|
|
260
|
+
* 5. Returns the list of secrets and corresponding signers
|
|
261
|
+
*
|
|
262
|
+
* The data field in the batch transfer contains the count of generated secrets,
|
|
263
|
+
* which the contract uses to validate the transfer.
|
|
264
|
+
*
|
|
265
|
+
* @param numberOfInvites The number of invitations to generate
|
|
266
|
+
* @returns Promise containing arrays of secrets and signers for each generated invitation
|
|
267
|
+
*
|
|
268
|
+
* @throws {SdkError} If the transaction fails or invitations cannot be claimed
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* // Generate 5 invitations
|
|
273
|
+
* const result = await avatar.invite.generateInvites(5n);
|
|
274
|
+
*
|
|
275
|
+
* console.log('Generated invitations:');
|
|
276
|
+
* result.secrets.forEach((secret, index) => {
|
|
277
|
+
* console.log(`Invitation ${index + 1}:`);
|
|
278
|
+
* console.log(` Secret: ${secret}`);
|
|
279
|
+
* console.log(` Signer: ${result.signers[index]}`);
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
generateInvites: async (numberOfInvites) => {
|
|
284
|
+
if (numberOfInvites <= 0n) {
|
|
285
|
+
throw SdkError.operationFailed('generateInvites', 'numberOfInvites must be greater than 0');
|
|
286
|
+
}
|
|
287
|
+
// Step 1: Call eth_call to claimInvites to get invitation IDs (read-only simulation)
|
|
288
|
+
// This simulates the claimInvites call without actually modifying state
|
|
289
|
+
// to get the IDs that would be returned
|
|
290
|
+
const ids = (await this.core.invitationFarm.read('claimInvites', [numberOfInvites], {
|
|
291
|
+
from: this.address
|
|
292
|
+
}));
|
|
293
|
+
console.log("ids", ids);
|
|
294
|
+
if (!ids || ids.length === 0) {
|
|
295
|
+
throw SdkError.operationFailed('generateInvites', 'No invitation IDs returned from claimInvites');
|
|
296
|
+
}
|
|
297
|
+
// Step 2: Generate random secrets and derive signers
|
|
298
|
+
const secrets = [];
|
|
299
|
+
const signers = [];
|
|
300
|
+
for (let i = 0; i < numberOfInvites; i++) {
|
|
301
|
+
// Generate a random private key
|
|
302
|
+
const privateKey = generatePrivateKey();
|
|
303
|
+
secrets.push(privateKey);
|
|
304
|
+
// Derive the signer address from the private key
|
|
305
|
+
const account = privateKeyToAccount(privateKey);
|
|
306
|
+
signers.push(account.address.toLowerCase());
|
|
307
|
+
}
|
|
308
|
+
// Step 3: Get invitation module address
|
|
309
|
+
const invitationModuleAddress = await this.core.invitationFarm.invitationModule();
|
|
310
|
+
// Step 4: Referrals module address
|
|
311
|
+
const referralsModuleAddress = this.core.config.referralsModuleAddress;
|
|
312
|
+
// Step 5: Build the batch transaction
|
|
313
|
+
// - claimInvites write call (to actually claim the invites)
|
|
314
|
+
// - safeBatchTransferFrom to transfer invitation tokens to the invitation module
|
|
315
|
+
// Create the claimInvites write transaction
|
|
316
|
+
const claimInvitesWriteTx = this.core.invitationFarm.claimInvites(numberOfInvites);
|
|
317
|
+
// Step 6: Encode the createAccounts function call to the referrals module
|
|
318
|
+
// This call will be executed by the invitation module via the generic call proxy
|
|
319
|
+
const createAccountsCallData = encodeFunctionData({
|
|
320
|
+
abi: referralsModuleAbi,
|
|
321
|
+
functionName: 'createAccounts',
|
|
322
|
+
args: [signers],
|
|
323
|
+
});
|
|
324
|
+
// Step 7: Create safeBatchTransferFrom transaction to transfer invitation tokens to the invitation module
|
|
325
|
+
// - from: this avatar
|
|
326
|
+
// - to: invitation module
|
|
327
|
+
// - ids: the invitation IDs returned from claimInvites
|
|
328
|
+
// - amounts: all 96 CRC (96 * 10^18) per invitation
|
|
329
|
+
// - data: encoded as (address referralsModule, bytes callData) for the invitation module to execute
|
|
330
|
+
const amounts = [];
|
|
331
|
+
for (let i = 0; i < ids.length; i++) {
|
|
332
|
+
amounts.push(BigInt(96e18)); // 96 CRC in atto-circles
|
|
333
|
+
}
|
|
334
|
+
// Encode the data as (address, bytes) - referrals module address + createAccounts call data
|
|
335
|
+
const encodedData = encodeAbiParameters(parseAbiParameters('address, bytes'), [referralsModuleAddress, createAccountsCallData]);
|
|
336
|
+
const batchTransferTx = this.core.hubV2.safeBatchTransferFrom(this.address, invitationModuleAddress, ids, amounts, encodedData);
|
|
337
|
+
// Step 7: Execute the batch transaction
|
|
338
|
+
const receipt = await this.runner.sendTransaction([claimInvitesWriteTx, batchTransferTx]);
|
|
339
|
+
return {
|
|
340
|
+
secrets,
|
|
341
|
+
signers,
|
|
342
|
+
transactionReceipt: receipt,
|
|
343
|
+
};
|
|
344
|
+
},
|
|
249
345
|
};
|
|
250
346
|
// Personal token / Minting methods
|
|
251
347
|
personalToken = {
|