Skip to content

Commit

Permalink
allow to migrate orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Oct 14, 2024
1 parent 0f6323e commit 12ad5ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/data/src/rows/avatarRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
43 changes: 29 additions & 14 deletions packages/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 12ad5ac

Please sign in to comment.