Skip to content

Commit

Permalink
Merge pull request #30 from aboutcircles/jaensen/crc-503-migrate-only…
Browse files Browse the repository at this point in the history
…-tokens-of-users-that-already-are-on-v2

fix: (0.15.1) auto migrate all balances of tokens whose owners are al…
  • Loading branch information
jaensen authored Dec 16, 2024
2 parents 2ecdc27 + 4ac2644 commit c5fec3d
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
},
"name": "@cirlces-sdk/root",
"license": "MIT",
"version": "0.15.0"
"version": "0.15.1"
}
2 changes: 1 addition & 1 deletion packages/abi-v1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v1",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v2",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-cometh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-cometh",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.15.0",
"@circles-sdk/adapter": "0.15.1",
"@cometh/connect-sdk": "1.2.29"
},
"keywords": [],
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-ethers",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -18,8 +18,8 @@
},
"dependencies": {
"ethers": "^6.13.2",
"@circles-sdk/adapter": "0.15.0",
"@circles-sdk/utils": "0.15.0"
"@circles-sdk/adapter": "0.15.1",
"@circles-sdk/utils": "0.15.1"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-safe-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-safe-app",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.15.0",
"@circles-sdk/adapter": "0.15.1",
"@safe-global/safe-apps-sdk": "^9.1.0"
},
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-safe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-safe",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/data",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.15.0"
"@circles-sdk/utils": "0.15.1"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/profiles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/profiles",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.15.0"
"@circles-sdk/utils": "0.15.1"
},
"keywords": [],
"author": "",
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/sdk",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,11 +17,11 @@
"author": "",
"license": "MIT",
"dependencies": {
"@circles-sdk/abi-v1": "0.15.0",
"@circles-sdk/abi-v2": "0.15.0",
"@circles-sdk/data": "0.15.0",
"@circles-sdk/profiles": "0.15.0",
"@circles-sdk/adapter-ethers": "0.15.0",
"@circles-sdk/abi-v1": "0.15.1",
"@circles-sdk/abi-v2": "0.15.1",
"@circles-sdk/data": "0.15.1",
"@circles-sdk/profiles": "0.15.1",
"@circles-sdk/adapter-ethers": "0.15.1",
"ethers": "^6.13.2",
"multihashes": "^4.0.3"
},
Expand Down
22 changes: 17 additions & 5 deletions packages/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ interface SdkInterface {
canSelfMigrate: (avatarInfo: AvatarRow) => Promise<boolean>;
}

/**
* Wraps a contract runner with its address.
*/


/**
* The SDK provides a high-level interface to interact with the Circles protocol.
Expand Down Expand Up @@ -479,7 +475,23 @@ export class Sdk implements SdkInterface {
batch.addTransaction(calculateIssuanceTx);
}

// 4. Migrate trust relations
// 4. Migrate v1 balances of the avatar. But only if the tokenOwner of the migrated token is already on v2 or if it's the own token.
const balances = await this.data.getTokenBalances(avatar);
const v1Balances = balances.filter(o => o.version === 1);
const tokenOwners = v1Balances.map(o => o.tokenOwner);
const tokenOwnerInfo = await this.data.getAvatarInfoBatch(tokenOwners);
const tokenOwnerInfoMap = tokenOwnerInfo.reduce((acc: Record<string, AvatarRow>, o) => {
acc[o.avatar] = o;
return acc;
}, {});

const tokensToMigrate = v1Balances.filter(o => o.tokenOwner == avatar || tokenOwnerInfoMap[o.tokenOwner]?.version === 2);
if (tokensToMigrate.length > 0) {
// Add 'migrate' to the batch
await this.migrateV1TokensBatch(avatar, tokensToMigrate.map(o => o.tokenAddress), batch);
}

// 5. Migrate trust relations
if (trustRelations) {
// Add 'trust' to the batch
for (const trustRelation of trustRelations) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/utils",
"version": "0.15.0",
"version": "0.15.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down

0 comments on commit c5fec3d

Please sign in to comment.