Skip to content

Commit

Permalink
* 0.10.1 fix pathfinder responses (always output as Circles)
Browse files Browse the repository at this point in the history
* make registerHumanV2 private
  • Loading branch information
jaensen committed Sep 20, 2024
1 parent 5fe024b commit ce459fd
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 52 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.10.0"
"version": "0.10.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.10.0",
"version": "0.10.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.10.0",
"version": "0.10.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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cometh/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ComethSdkContractRunner implements SdkContractRunner {
chainId: network.chainId
};
};
sendBatchTransaction?: () => BatchRun = () => {
sendBatchTransaction() {
return new ComethBatchRun(this.comethWallet);
}
}
Expand Down
4 changes: 2 additions & 2 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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -18,7 +18,7 @@
},
"dependencies": {
"ethers": "^6.13.2",
"@circles-sdk/adapter": "0.10.0"
"@circles-sdk/adapter": "0.10.1"
},
"keywords": [],
"author": "",
Expand Down
7 changes: 7 additions & 0 deletions packages/adapter-ethers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,11 @@ export class SdkContractRunnerWrapper implements EthersContractRunner {

return <SdkTransactionResponse><unknown>{...transactionResponse};
};
sendBatchTransaction() {
if (!this.sdkContractRunner.sendBatchTransaction) {
throw new Error('sendBatchTransaction not supported');
}

return this.sdkContractRunner.sendBatchTransaction();
}
}
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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -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": [],
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.10.0",
"version": "0.10.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.10.0",
"version": "0.10.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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.10.0"
"@circles-sdk/utils": "0.10.1"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/circlesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.10.0"
"@circles-sdk/utils": "0.10.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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/AvatarInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint>;
getMaxTransferableAmount(to: string, tokenId?: string): Promise<number>;

/**
* Transfers Circles to another avatar.
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint> => this.onlyIfInitialized(() => this._avatar!.getMaxTransferableAmount(to, tokenId));
getMaxTransferableAmount = (to: string, tokenId?: string): Promise<number> => this.onlyIfInitialized(() => this._avatar!.getMaxTransferableAmount(to, tokenId));

/**
* Transfers Circles to another avatar.
Expand Down
34 changes: 17 additions & 17 deletions packages/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ interface SdkInterface {
* @returns The Avatar instance.
*/
registerHuman: () => Promise<AvatarInterface>;

/**
* 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<AvatarInterface>;

/**
* 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<AvatarInterface>;
//
// /**
// * 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<AvatarInterface>;

// /**
// * 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<AvatarInterface>;

/**
* Registers the connected wallet as an organization avatar in Circles v1.
Expand Down Expand Up @@ -219,20 +219,20 @@ export class Sdk implements SdkInterface {
* @param profile The profile data of the avatar.
* @returns The Avatar instance.
*/
registerHumanV2(profile: Profile): Promise<AvatarInterface>;
private registerHumanV2(profile: Profile): Promise<AvatarInterface>;
/**
* 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.
* The only way to join after the migration period is to be invited by an existing member.
* @param cidV0 The CIDv0 of the avatar's ERC1155 token metadata.
* @returns The Avatar instance.
*/
registerHumanV2(cidV0: string): Promise<AvatarInterface>;
private registerHumanV2(cidV0: string): Promise<AvatarInterface>;
/**
* 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<AvatarInterface> {
private async registerHumanV2(profile: Profile | string): Promise<AvatarInterface> {
return this._registerHuman(ZeroAddress, profile);
};

Expand Down
12 changes: 7 additions & 5 deletions packages/sdk/src/v1/v1Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint> {
async getMaxTransferableAmount(to: string, tokenId?: string): Promise<number> {
this.throwIfNotInitialized();

if (tokenId) {
Expand All @@ -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();
Expand All @@ -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);
}

/**
Expand All @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions packages/sdk/src/v2/v2Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from 'ethers';
import {Sdk} from '../sdk';
import {
attoCirclesToCircles,
AvatarRow,
CirclesQuery,
TokenBalanceRow,
Expand Down Expand Up @@ -71,7 +72,7 @@ export class V2Avatar implements AvatarInterfaceV2 {
return receipt;
}

async getMaxTransferableAmount(to: string, tokenId?: string): Promise<bigint> {
async getMaxTransferableAmount(to: string, tokenId?: string): Promise<number> {
this.throwIfV2IsNotAvailable();

if (tokenId) {
Expand All @@ -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');
Expand All @@ -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<number> {
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.10.0",
"version": "0.10.1",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down

0 comments on commit ce459fd

Please sign in to comment.