diff --git a/packages/data/src/rows/avatarRow.ts b/packages/data/src/rows/avatarRow.ts index b260494..8e18883 100644 --- a/packages/data/src/rows/avatarRow.ts +++ b/packages/data/src/rows/avatarRow.ts @@ -21,7 +21,7 @@ export interface AvatarRow extends EventRow { /** * The type of the avatar. */ - type: 'CrcV2_RegisterHuman' | 'CrcV2_RegisterGroup' | 'CrcV2_RegisterOrganization' | 'CrcV1_Signup'; + type: 'CrcV2_RegisterHuman' | 'CrcV2_RegisterGroup' | 'CrcV2_RegisterOrganization' | 'CrcV1_Signup' | 'CrcV1_OrganizationSignup'; /** * The address of the avatar. */ diff --git a/packages/sdk/src/sdk.ts b/packages/sdk/src/sdk.ts index cfce853..c2e20a4 100644 --- a/packages/sdk/src/sdk.ts +++ b/packages/sdk/src/sdk.ts @@ -382,25 +382,40 @@ export class Sdk implements SdkInterface { if (avatarInfo.version === 1) { // Add 'registerHumanV2' to the batch const metadataDigest = await this.createProfileIfNecessary(profile); - const registerHumanData = this.v2Hub.interface.encodeFunctionData('registerHuman', [ZeroAddress, metadataDigest]); - const registerHumanTx: TransactionRequest = { + + if (avatarInfo.type === "CrcV1_Signup") { + const registerHumanData = this.v2Hub.interface.encodeFunctionData('registerHuman', [ZeroAddress, metadataDigest]); + const registerHumanTx: TransactionRequest = { + to: this.circlesConfig.v2HubAddress!, + data: registerHumanData, + value: 0n, + }; + batch.addTransaction(registerHumanTx); + } else if (avatarInfo.type === "CrcV1_OrganizationSignup") { + const registerOrganizationData = this.v2Hub.interface.encodeFunctionData('registerOrganization', [profile.name, metadataDigest]); + const registerOrganizationTx: TransactionRequest = { + to: this.circlesConfig.v2HubAddress!, + data: registerOrganizationData, + value: 0n, + }; + batch.addTransaction(registerOrganizationTx); + } else { + throw new Error(`Avatar type ${avatarInfo.type} not supported`); + } + } + + if (avatarInfo.isHuman) { + // 3. Ensure the v1 token minting status is known to the v2 hub + // Add 'calculateIssuanceTx' to the batch + const calculateIssuanceData = this.v2Hub.interface.encodeFunctionData('calculateIssuanceWithCheck', [avatar]); + const calculateIssuanceTx: TransactionRequest = { to: this.circlesConfig.v2HubAddress!, - data: registerHumanData, + data: calculateIssuanceData, value: 0n, }; - batch.addTransaction(registerHumanTx); + batch.addTransaction(calculateIssuanceTx); } - // 3. Ensure the v1 token minting status is known to the v2 hub - // Add 'calculateIssuanceTx' to the batch - const calculateIssuanceData = this.v2Hub.interface.encodeFunctionData('calculateIssuanceWithCheck', [avatar]); - const calculateIssuanceTx: TransactionRequest = { - to: this.circlesConfig.v2HubAddress!, - data: calculateIssuanceData, - value: 0n, - }; - batch.addTransaction(calculateIssuanceTx); - // // 4. Migrate V1 tokens // // Add 'migrateV1Tokens' to the batch // await this.migrateV1TokensBatch(avatar, undefined, batch);