From ce459fd9e65c58fd5b86470e858efef6d8b1c7b9 Mon Sep 17 00:00:00 2001 From: daniel <4954577+jaensen@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:24:36 +0200 Subject: [PATCH] * 0.10.1 fix pathfinder responses (always output as Circles) * make registerHumanV2 private --- package.json | 2 +- packages/abi-v1/package.json | 2 +- packages/abi-v2/package.json | 2 +- packages/adapter-cometh/package.json | 4 +-- packages/adapter-cometh/src/index.ts | 2 +- packages/adapter-ethers/package.json | 4 +-- packages/adapter-ethers/src/index.ts | 7 ++++++ packages/adapter-safe-app/package.json | 4 +-- packages/adapter-safe/package.json | 2 +- packages/adapter/package.json | 2 +- packages/data/package.json | 4 +-- packages/data/src/circlesData.ts | 2 +- packages/profiles/package.json | 4 +-- packages/sdk/package.json | 12 ++++----- packages/sdk/src/AvatarInterface.ts | 2 +- packages/sdk/src/avatar.ts | 2 +- packages/sdk/src/sdk.ts | 34 +++++++++++++------------- packages/sdk/src/v1/v1Avatar.ts | 12 +++++---- packages/sdk/src/v2/v2Avatar.ts | 13 +++++++--- packages/utils/package.json | 2 +- 20 files changed, 66 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 3b7459d..bd663e0 100644 --- a/package.json +++ b/package.json @@ -36,5 +36,5 @@ }, "name": "@cirlces-sdk/root", "license": "MIT", - "version": "0.10.0" + "version": "0.10.1" } diff --git a/packages/abi-v1/package.json b/packages/abi-v1/package.json index 8fc8b87..77aff70 100644 --- a/packages/abi-v1/package.json +++ b/packages/abi-v1/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/abi-v1", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/abi-v2/package.json b/packages/abi-v2/package.json index 7427f69..810f03b 100644 --- a/packages/abi-v2/package.json +++ b/packages/abi-v2/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/abi-v2", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/adapter-cometh/package.json b/packages/adapter-cometh/package.json index abdf003..80cbff9 100644 --- a/packages/adapter-cometh/package.json +++ b/packages/adapter-cometh/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-cometh", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/adapter": "0.10.0", + "@circles-sdk/adapter": "0.10.1", "@cometh/connect-sdk": "1.2.29" }, "keywords": [], diff --git a/packages/adapter-cometh/src/index.ts b/packages/adapter-cometh/src/index.ts index 2a5914a..1dad48f 100644 --- a/packages/adapter-cometh/src/index.ts +++ b/packages/adapter-cometh/src/index.ts @@ -70,7 +70,7 @@ export class ComethSdkContractRunner implements SdkContractRunner { chainId: network.chainId }; }; - sendBatchTransaction?: () => BatchRun = () => { + sendBatchTransaction() { return new ComethBatchRun(this.comethWallet); } } diff --git a/packages/adapter-ethers/package.json b/packages/adapter-ethers/package.json index cc47f3e..55e5205 100644 --- a/packages/adapter-ethers/package.json +++ b/packages/adapter-ethers/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-ethers", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -18,7 +18,7 @@ }, "dependencies": { "ethers": "^6.13.2", - "@circles-sdk/adapter": "0.10.0" + "@circles-sdk/adapter": "0.10.1" }, "keywords": [], "author": "", diff --git a/packages/adapter-ethers/src/index.ts b/packages/adapter-ethers/src/index.ts index 34d52c1..3d156cf 100644 --- a/packages/adapter-ethers/src/index.ts +++ b/packages/adapter-ethers/src/index.ts @@ -206,4 +206,11 @@ export class SdkContractRunnerWrapper implements EthersContractRunner { return {...transactionResponse}; }; + sendBatchTransaction() { + if (!this.sdkContractRunner.sendBatchTransaction) { + throw new Error('sendBatchTransaction not supported'); + } + + return this.sdkContractRunner.sendBatchTransaction(); + } } \ No newline at end of file diff --git a/packages/adapter-safe-app/package.json b/packages/adapter-safe-app/package.json index 3fa34be..7d8b843 100644 --- a/packages/adapter-safe-app/package.json +++ b/packages/adapter-safe-app/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-safe-app", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/adapter": "0.10.0", + "@circles-sdk/adapter": "0.10.1", "@safe-global/safe-apps-sdk": "^9.1.0" }, "keywords": [], diff --git a/packages/adapter-safe/package.json b/packages/adapter-safe/package.json index bd2f9f1..29a421c 100644 --- a/packages/adapter-safe/package.json +++ b/packages/adapter-safe/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter-safe", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/adapter/package.json b/packages/adapter/package.json index 84672f2..1584a98 100644 --- a/packages/adapter/package.json +++ b/packages/adapter/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/adapter", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/packages/data/package.json b/packages/data/package.json index 97ae2de..d4789f5 100644 --- a/packages/data/package.json +++ b/packages/data/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/data", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/utils": "0.10.0" + "@circles-sdk/utils": "0.10.1" }, "keywords": [], "author": "", diff --git a/packages/data/src/circlesData.ts b/packages/data/src/circlesData.ts index a59bbc6..7cbd007 100644 --- a/packages/data/src/circlesData.ts +++ b/packages/data/src/circlesData.ts @@ -561,7 +561,7 @@ export class CirclesData implements CirclesDataInterface { ); return parseRpcSubscriptionMessage(response.result); } - + /** * Gets the invitations sent by an avatar. * @param avatar The avatar to get the invitations for. diff --git a/packages/profiles/package.json b/packages/profiles/package.json index d0958b7..178c1f8 100644 --- a/packages/profiles/package.json +++ b/packages/profiles/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/profiles", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,7 +17,7 @@ "build": "rollup -c" }, "dependencies": { - "@circles-sdk/utils": "0.10.0" + "@circles-sdk/utils": "0.10.1" }, "keywords": [], "author": "", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index d3c8b0c..ab5645f 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/sdk", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js", @@ -17,11 +17,11 @@ "author": "", "license": "MIT", "dependencies": { - "@circles-sdk/abi-v1": "0.10.0", - "@circles-sdk/abi-v2": "0.10.0", - "@circles-sdk/data": "0.10.0", - "@circles-sdk/profiles": "0.10.0", - "@circles-sdk/adapter-ethers": "0.10.0", + "@circles-sdk/abi-v1": "0.10.1", + "@circles-sdk/abi-v2": "0.10.1", + "@circles-sdk/data": "0.10.1", + "@circles-sdk/profiles": "0.10.1", + "@circles-sdk/adapter-ethers": "0.10.1", "ethers": "^6.13.2", "multihashes": "^4.0.3" }, diff --git a/packages/sdk/src/AvatarInterface.ts b/packages/sdk/src/AvatarInterface.ts index 6ebf11f..2ad1733 100644 --- a/packages/sdk/src/AvatarInterface.ts +++ b/packages/sdk/src/AvatarInterface.ts @@ -30,7 +30,7 @@ export interface AvatarInterface { * @param tokenId The token to transfer (address). Leave empty to allow transitive transfers. * @returns The maximum amount that can be transferred. */ - getMaxTransferableAmount(to: string, tokenId?: string): Promise; + getMaxTransferableAmount(to: string, tokenId?: string): Promise; /** * Transfers Circles to another avatar. diff --git a/packages/sdk/src/avatar.ts b/packages/sdk/src/avatar.ts index 790d8b1..8998462 100644 --- a/packages/sdk/src/avatar.ts +++ b/packages/sdk/src/avatar.ts @@ -154,7 +154,7 @@ export class Avatar implements AvatarInterfaceV2 { * @param tokenId The token ID to transfer. If not specified, a transitve transfer is calculated. * @returns The maximum Circles amount that can be transferred. */ - getMaxTransferableAmount = (to: string, tokenId?: string): Promise => this.onlyIfInitialized(() => this._avatar!.getMaxTransferableAmount(to, tokenId)); + getMaxTransferableAmount = (to: string, tokenId?: string): Promise => this.onlyIfInitialized(() => this._avatar!.getMaxTransferableAmount(to, tokenId)); /** * Transfers Circles to another avatar. diff --git a/packages/sdk/src/sdk.ts b/packages/sdk/src/sdk.ts index 4f24c0a..f32cff3 100644 --- a/packages/sdk/src/sdk.ts +++ b/packages/sdk/src/sdk.ts @@ -65,20 +65,20 @@ interface SdkInterface { * @returns The Avatar instance. */ registerHuman: () => Promise; - - /** - * Registers the connected wallet as a human avatar in Circles v2 and creates a profile. - * @param profile The profile data of the avatar. - * @returns The Avatar instance. - */ - registerHumanV2(profile: Profile): Promise; - - /** - * Registers the connected wallet as a human avatar in Circles v2 and using an existing CID as profile. - * @param cidV0 The CIDv0 of the avatar's ERC1155 token metadata. - * @returns The Avatar instance. - */ - registerHumanV2(cidV0: string): Promise; + // + // /** + // * Registers the connected wallet as a human avatar in Circles v2 and creates a profile. + // * @param profile The profile data of the avatar. + // * @returns The Avatar instance. + // */ + // registerHumanV2(profile: Profile): Promise; + + // /** + // * Registers the connected wallet as a human avatar in Circles v2 and using an existing CID as profile. + // * @param cidV0 The CIDv0 of the avatar's ERC1155 token metadata. + // * @returns The Avatar instance. + // */ + // registerHumanV2(cidV0: string): Promise; /** * Registers the connected wallet as an organization avatar in Circles v1. @@ -219,7 +219,7 @@ export class Sdk implements SdkInterface { * @param profile The profile data of the avatar. * @returns The Avatar instance. */ - registerHumanV2(profile: Profile): Promise; + private registerHumanV2(profile: Profile): Promise; /** * Registers the connected wallet as a human avatar in Circles v2 using an existing CID as profile. * Note: This will only work if you already have a v1 avatar and only during the migration period. @@ -227,12 +227,12 @@ export class Sdk implements SdkInterface { * @param cidV0 The CIDv0 of the avatar's ERC1155 token metadata. * @returns The Avatar instance. */ - registerHumanV2(cidV0: string): Promise; + private registerHumanV2(cidV0: string): Promise; /** * Registers the connected wallet as a human avatar in Circles v2. * @param profile The profile data of the avatar. */ - async registerHumanV2(profile: Profile | string): Promise { + private async registerHumanV2(profile: Profile | string): Promise { return this._registerHuman(ZeroAddress, profile); }; diff --git a/packages/sdk/src/v1/v1Avatar.ts b/packages/sdk/src/v1/v1Avatar.ts index 0b52c9c..858abfe 100644 --- a/packages/sdk/src/v1/v1Avatar.ts +++ b/packages/sdk/src/v1/v1Avatar.ts @@ -58,7 +58,7 @@ export class V1Avatar implements AvatarInterface { * @param tokenId The token to transfer (address). Leave empty to allow transitive transfers. * @returns The max. transferable amount at the time. */ - async getMaxTransferableAmount(to: string, tokenId?: string): Promise { + async getMaxTransferableAmount(to: string, tokenId?: string): Promise { this.throwIfNotInitialized(); if (tokenId) { @@ -68,8 +68,8 @@ export class V1Avatar implements AvatarInterface { } const tokenBalances = await this.sdk.data.getTokenBalances(this.address); - const tokenBalance = tokenBalances.filter(b => b.version === 1 && b.tokenAddress === tokenId)[0]?.attoCircles; - return BigInt(tokenBalance ?? "0"); + const tokenBalance = tokenBalances.filter(b => b.version === 1 && b.tokenAddress === tokenId)[0]?.circles; + return tokenBalance ?? "0"; } this.throwIfPathfinderIsNotAvailable(); @@ -81,10 +81,10 @@ export class V1Avatar implements AvatarInterface { largeAmount); if (!transferPath.isValid) { - return Promise.resolve(BigInt(0)); + return 0; } - return transferPath.maxFlow; + return crcToTc(new Date(), transferPath.maxFlow); } /** @@ -108,6 +108,8 @@ export class V1Avatar implements AvatarInterface { throw new Error(`Couldn't find a valid path from ${this.address} to ${to} for ${amount}.`); } + console.log('transferPath', transferPath); + const tokenOwners = transferPath.transferSteps.map(o => o.token_owner); const srcs = transferPath.transferSteps.map(o => o.from); const dests = transferPath.transferSteps.map(o => o.to); diff --git a/packages/sdk/src/v2/v2Avatar.ts b/packages/sdk/src/v2/v2Avatar.ts index ca808d8..ddee89d 100644 --- a/packages/sdk/src/v2/v2Avatar.ts +++ b/packages/sdk/src/v2/v2Avatar.ts @@ -4,6 +4,7 @@ import { } from 'ethers'; import {Sdk} from '../sdk'; import { + attoCirclesToCircles, AvatarRow, CirclesQuery, TokenBalanceRow, @@ -71,7 +72,7 @@ export class V2Avatar implements AvatarInterfaceV2 { return receipt; } - async getMaxTransferableAmount(to: string, tokenId?: string): Promise { + async getMaxTransferableAmount(to: string, tokenId?: string): Promise { this.throwIfV2IsNotAvailable(); if (tokenId) { @@ -82,7 +83,7 @@ export class V2Avatar implements AvatarInterfaceV2 { const tokenBalances = await this.sdk.data.getTokenBalances(this.address); const tokenBalance = tokenBalances.filter(b => b.version === 2 && b.tokenOwner.toString() === tokenInfo.token.toString())[0]; - return BigInt(tokenBalance?.attoCircles ?? "0"); + return tokenBalance?.circles ?? 0; } const largeAmount = BigInt('79228162514264337593543950335'); @@ -91,11 +92,15 @@ export class V2Avatar implements AvatarInterfaceV2 { to, largeAmount); + if (transferPath.transferSteps.length == 0) { + return 0; + } + if (!transferPath.isValid) { - return Promise.resolve(BigInt(0)); + return 0; } - return transferPath.maxFlow; + return attoCirclesToCircles(transferPath.maxFlow); } async getMintableAmount(): Promise { diff --git a/packages/utils/package.json b/packages/utils/package.json index bcbf41c..618bfa2 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@circles-sdk/utils", - "version": "0.10.0", + "version": "0.10.1", "description": "", "type": "module", "main": "./dist/index.js",