From a2f852b2bb31f447d9acbdc6f338b69a9f2e05d0 Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Fri, 26 Apr 2024 11:54:46 +0200 Subject: [PATCH 01/21] common: wasmToSchema: Base custom section resolution on module version (#233) ## Purpose Ensure that `getEmbeddedSchema` (on `ConcordiumGRPCClient`) is able to resolve legacy schemas (i.e. schemas without embedded versions). Also make parsing of contract schema more precise based by using the module version information that is now exposed by the gRPC client. This in turn also documents the relationship between module and schema versions. ## Changes The module version is now used to determine what custom sections to look for. Added comments explain the expected results. The extraction code is migrated from the dapp-library [`@concordium/react-components`](https://github.com/Concordium/concordium-dapp-libraries/blob/a045f3b8bc11c7389190c789072f313686b6c639/packages/react-components/src/useModuleSchemaRpc.ts). Specifically, the contents of function `getEmbeddedModuleSchema` was replaced with the contents of `findSchema` and its helper function `findCustomSections` was added and adjusted to use the SDK types. Finally, `getEmbeddedModuleSchema` was made non-async and `wasmToSchema` removed because it was nothing but a more limited version of `getEmbeddedModuleSchema`. Addresses https://github.com/Concordium/concordium-dapp-libraries/issues/66. --- examples/nodejs/client/getEmbeddedSchema.ts | 4 +- .../getEmbeddedSchemaFromInstance.ts | 4 +- .../initAndUpdateContract.ts | 6 +- packages/ccd-js-gen/src/lib.ts | 4 +- packages/sdk/CHANGELOG.md | 10 +++ packages/sdk/src/GenericContract.ts | 9 ++- packages/sdk/src/grpc/GRPCClient.ts | 18 ++--- packages/sdk/src/pub/types.ts | 2 +- packages/sdk/src/schemaTypes.ts | 2 +- .../sdk/src/types/VersionedModuleSource.ts | 75 +++++++++++++------ packages/sdk/src/util.ts | 45 ----------- packages/sdk/test/ci/module-schema.test.ts | 16 ++-- packages/sdk/test/ci/util.test.ts | 12 ++- packages/sdk/test/client/clientV2.test.ts | 2 +- 14 files changed, 104 insertions(+), 105 deletions(-) diff --git a/examples/nodejs/client/getEmbeddedSchema.ts b/examples/nodejs/client/getEmbeddedSchema.ts index dcb81bb27..9bdbea1e3 100644 --- a/examples/nodejs/client/getEmbeddedSchema.ts +++ b/examples/nodejs/client/getEmbeddedSchema.ts @@ -57,7 +57,9 @@ const client = new ConcordiumGRPCNodeClient( const schema = await client.getEmbeddedSchema(moduleRef); // #endregion documentation-snippet - fs.writeFileSync(cli.flags.outPath, schema); + if (schema) { + fs.writeFileSync(cli.flags.outPath, new Uint8Array(schema.buffer)); + } console.log('Wrote schema to file: ', cli.flags.outPath); })(); diff --git a/examples/nodejs/composed-examples/getEmbeddedSchemaFromInstance.ts b/examples/nodejs/composed-examples/getEmbeddedSchemaFromInstance.ts index c1dea6d12..525c05062 100644 --- a/examples/nodejs/composed-examples/getEmbeddedSchemaFromInstance.ts +++ b/examples/nodejs/composed-examples/getEmbeddedSchemaFromInstance.ts @@ -67,7 +67,9 @@ const client = new ConcordiumGRPCNodeClient( const schema = await client.getEmbeddedSchema(moduleRef); // #endregion documentation-snippet - fs.writeFileSync(cli.flags.outPath, schema); + if (schema) { + fs.writeFileSync(cli.flags.outPath, new Uint8Array(schema.buffer)); + } console.log('Wrote schema to file: ', cli.flags.outPath); })(); diff --git a/examples/nodejs/composed-examples/initAndUpdateContract.ts b/examples/nodejs/composed-examples/initAndUpdateContract.ts index c61a63a8f..8988e043c 100644 --- a/examples/nodejs/composed-examples/initAndUpdateContract.ts +++ b/examples/nodejs/composed-examples/initAndUpdateContract.ts @@ -103,7 +103,7 @@ const client = new ConcordiumGRPCNodeClient( const initParams = serializeInitContractParameters( contractName, sunnyWeather, - schema + schema!.buffer ); const initPayload: InitContractPayload = { @@ -155,7 +155,7 @@ const client = new ConcordiumGRPCNodeClient( contractName, EntrypointName.fromString('set'), rainyWeather, - schema + schema!.buffer ); const updatePayload: UpdateContractPayload = { @@ -205,7 +205,7 @@ const client = new ConcordiumGRPCNodeClient( const rawReturnValue = unwrap(invokedPostInit.returnValue); const returnValue = deserializeReceiveReturnValue( ReturnValue.toBuffer(rawReturnValue), - schema, + schema!.buffer, contractName, EntrypointName.fromString('get') ); diff --git a/packages/ccd-js-gen/src/lib.ts b/packages/ccd-js-gen/src/lib.ts index 56350ab09..a9e244e38 100644 --- a/packages/ccd-js-gen/src/lib.ts +++ b/packages/ccd-js-gen/src/lib.ts @@ -199,9 +199,7 @@ async function generateCode( notifier.done('Parse smart contract module.'); const moduleSchema = - rawModuleSchema === null - ? null - : SDK.parseRawModuleSchema(rawModuleSchema); + rawModuleSchema && SDK.parseRawModuleSchema(rawModuleSchema); const outputFilePath = path.format({ dir: outDirPath, diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index af08c667b..869e573b1 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -22,6 +22,16 @@ - Serialization of nonces with `serializeCIS4RevocationDataHolder` to serialize as little endian. +### Breaking changes + +- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. + It also no longer is `async` because there isn't any need for it to be so. +- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` + (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). + This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. + It also means that it returns `null` instead of an error when no embedded schema was found. + + ## 7.3.2 ### Added diff --git a/packages/sdk/src/GenericContract.ts b/packages/sdk/src/GenericContract.ts index a1add36bc..c47ece0fc 100644 --- a/packages/sdk/src/GenericContract.ts +++ b/packages/sdk/src/GenericContract.ts @@ -583,10 +583,11 @@ export class Contract< const raw = await grpcClient.getEmbeddedSchema( instanceInfo.sourceModule ); - const encoded = Buffer.from(raw).toString('base64'); - - if (encoded) { - mSchema = encoded; + if (raw) { + const encoded = Buffer.from(raw.buffer).toString('base64'); + if (encoded) { + mSchema = encoded; + } } } catch { // Do nothing. diff --git a/packages/sdk/src/grpc/GRPCClient.ts b/packages/sdk/src/grpc/GRPCClient.ts index 2e0d85080..a73bc7418 100644 --- a/packages/sdk/src/grpc/GRPCClient.ts +++ b/packages/sdk/src/grpc/GRPCClient.ts @@ -28,7 +28,6 @@ import { mapRecord, mapStream, unwrap, - wasmToSchema, } from '../util.js'; import { serializeAccountTransactionPayload } from '../serialization.js'; import type { @@ -46,6 +45,8 @@ import * as Energy from '../types/Energy.js'; import * as SequenceNumber from '../types/SequenceNumber.js'; import * as ReceiveName from '../types/ReceiveName.js'; import * as Timestamp from '../types/Timestamp.js'; +import { getEmbeddedModuleSchema } from '../types/VersionedModuleSource.js'; +import { RawModuleSchema } from '../schemaTypes.js'; /** * @hidden @@ -225,19 +226,16 @@ export class ConcordiumGRPCClient { * @param moduleRef the module's reference, represented by the ModuleReference class. * @param blockHash optional block hash to get the module embedded schema at, otherwise retrieves from last finalized block * - * @returns the module schema as a buffer. - * @throws An error of type `RpcError` if not found in the block. - * @throws If the module or schema cannot be parsed + * @returns the module schema as a {@link RawModuleSchema} or `null` if not found in the block. + * @throws An error of type `RpcError` if the module was not found in the block. + * @throws If the module source cannot be parsed or contains duplicate schema sections. */ async getEmbeddedSchema( moduleRef: ModuleReference.Type, blockHash?: BlockHash.Type - ): Promise { - const versionedSource = await this.getModuleSource( - moduleRef, - blockHash - ); - return wasmToSchema(versionedSource.source); + ): Promise { + const source = await this.getModuleSource(moduleRef, blockHash); + return getEmbeddedModuleSchema(source); } /** diff --git a/packages/sdk/src/pub/types.ts b/packages/sdk/src/pub/types.ts index 3fee55145..c429c13cf 100644 --- a/packages/sdk/src/pub/types.ts +++ b/packages/sdk/src/pub/types.ts @@ -25,7 +25,7 @@ export * from '../signHelpers.js'; export * from '../versionedTypeHelpers.js'; export * from '../accountHelpers.js'; -export { isHex, streamToList, wasmToSchema, unwrap } from '../util.js'; +export { isHex, streamToList, unwrap } from '../util.js'; export * from '../accountTransactions.js'; export * from '../energyCost.js'; diff --git a/packages/sdk/src/schemaTypes.ts b/packages/sdk/src/schemaTypes.ts index 0230eeea7..7f7402b86 100644 --- a/packages/sdk/src/schemaTypes.ts +++ b/packages/sdk/src/schemaTypes.ts @@ -39,7 +39,7 @@ export function toOptionJson(value: T | undefined): OptionJson { } /** Schema version from before the schema bytes contained version information. */ -type UnversionedSchemaVersion = 0 | 1; +export type UnversionedSchemaVersion = 0 | 1; /** * Represents unparsed bytes for a smart contract module schema. diff --git a/packages/sdk/src/types/VersionedModuleSource.ts b/packages/sdk/src/types/VersionedModuleSource.ts index a0c27a944..94e8304a7 100644 --- a/packages/sdk/src/types/VersionedModuleSource.ts +++ b/packages/sdk/src/types/VersionedModuleSource.ts @@ -3,8 +3,7 @@ import * as H from '../contractHelpers.js'; import { sha256 } from '../hash.js'; import { Buffer } from 'buffer/index.js'; import { VersionedModuleSource } from '../types.js'; -import { schemaBytesFromWasmModule } from '../util.js'; -import { RawModuleSchema } from '../schemaTypes.js'; +import { RawModuleSchema, UnversionedSchemaVersion } from '../schemaTypes.js'; import { Cursor, deserializeUInt32BE } from '../deserializationHelpers.js'; import { encodeWord32 } from '../serializationHelpers.js'; @@ -109,33 +108,61 @@ export async function parseModuleInterface( * Extract the embedded smart contract schema bytes. Returns `null` if no schema is embedded. * @param {VersionedModuleSource} moduleSource The smart contract module source. * @returns {RawModuleSchema | null} The raw module schema if found. + * @throws If the module source cannot be parsed or contains duplicate schema sections. */ -export async function getEmbeddedModuleSchema( - moduleSource: VersionedModuleSource -): Promise { - const wasmModule = await WebAssembly.compile(moduleSource.source); - const versionedSchema = schemaBytesFromWasmModule( - wasmModule, - 'concordium-schema' +export function getEmbeddedModuleSchema({ + source, + version, +}: VersionedModuleSource): RawModuleSchema | undefined { + const sections = findCustomSections( + new WebAssembly.Module(source), + version ); - if (versionedSchema !== null) { - return { type: 'versioned', buffer: versionedSchema }; + if (sections === undefined) { + return undefined; } - const unversionedSchemaV0 = schemaBytesFromWasmModule( - wasmModule, - 'concordium-schema-v1' - ); - if (unversionedSchemaV0 !== null) { - return { type: 'unversioned', version: 0, buffer: unversionedSchemaV0 }; + const { sectionName, unversionedSchemaVersion, contents } = sections; + if (contents.length !== 1) { + throw new Error( + `invalid module: expected to find at most one custom section named "${sectionName}", but found ${contents.length}` + ); } - const unversionedSchemaV1 = schemaBytesFromWasmModule( - wasmModule, - 'concordium-schema-v2' - ); - if (unversionedSchemaV1 !== null) { - return { type: 'unversioned', version: 1, buffer: unversionedSchemaV1 }; + const schema = contents[0]; + if (unversionedSchemaVersion !== undefined) { + return { + type: 'unversioned', + version: unversionedSchemaVersion, + buffer: schema, + }; + } + return { type: 'versioned', buffer: schema }; +} + +function findCustomSections(m: WebAssembly.Module, moduleVersion: number) { + function getCustomSections( + sectionName: string, + unversionedSchemaVersion: UnversionedSchemaVersion | undefined + ) { + const s = WebAssembly.Module.customSections(m, sectionName); + return s.length === 0 + ? undefined + : { sectionName, unversionedSchemaVersion, contents: s }; + } + + // First look for section containing schema with embedded version, then "-v1" or "-v2" depending on the module version. + switch (moduleVersion) { + case 0: + return ( + getCustomSections('concordium-schema', undefined) || // always v0 + getCustomSections('concordium-schema-v1', 0) // v0 (not a typo) + ); + case 1: + return ( + getCustomSections('concordium-schema', undefined) || // v1, v2, or v3 + getCustomSections('concordium-schema-v2', 1) // v1 (not a typo) + ); } - return null; + return getCustomSections('concordium-schema', undefined); // expecting to find this section in future module versions } /** diff --git a/packages/sdk/src/util.ts b/packages/sdk/src/util.ts index c383b6655..86e6ed02a 100644 --- a/packages/sdk/src/util.ts +++ b/packages/sdk/src/util.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { Buffer } from 'buffer/index.js'; import { AccountTransactionSignature, @@ -68,50 +67,6 @@ export function countSignatures( return totalSignatureCount; } -/** - * Compiles a wasm module and extracts the smart contract schema. - * - * @param wasm the wasm module as a Buffer - * - * @throws If WASM module contains no schema - * @throws If WASM module provided is invalid - * - * @returns the smart contract schema as a Buffer - */ -export function wasmToSchema(wasm: ArrayBuffer): Uint8Array { - const wasmModule = new WebAssembly.Module(wasm); - const schemaBytes = schemaBytesFromWasmModule( - wasmModule, - 'concordium-schema' - ); - if (schemaBytes === null) { - throw Error('WASM-Module contains no schema!'); - } - return new Uint8Array(schemaBytes); -} - -/** - * Extracts custom-section containing the smart contract schema if present. - * @param wasmModule the WebAssembly module. - * @returns the smart contract schema as a Buffer or null if not present. - */ -export function schemaBytesFromWasmModule( - wasmModule: WebAssembly.Module, - sectionName: - | 'concordium-schema' - | 'concordium-schema-v1' - | 'concordium-schema-v2' -): ArrayBuffer | null { - const sections = WebAssembly.Module.customSections(wasmModule, sectionName); - if (sections.length === 1) { - return sections[0]; - } else if (sections.length === 0) { - return null; - } else { - throw Error('Invalid WASM-Module retrieved!'); - } -} - /** * Convert a Date to seconds since epoch. */ diff --git a/packages/sdk/test/ci/module-schema.test.ts b/packages/sdk/test/ci/module-schema.test.ts index 0e225aeb9..5676dc55a 100644 --- a/packages/sdk/test/ci/module-schema.test.ts +++ b/packages/sdk/test/ci/module-schema.test.ts @@ -19,8 +19,8 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { ) ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = await getEmbeddedModuleSchema(moduleSource); - if (moduleSchema === null) { + const moduleSchema = getEmbeddedModuleSchema(moduleSource); + if (moduleSchema === undefined) { fail('Failed to find module schame'); } expect(moduleSchema.type).toBe('versioned'); @@ -34,8 +34,8 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { ) ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = await getEmbeddedModuleSchema(moduleSource); - if (moduleSchema === null) { + const moduleSchema = getEmbeddedModuleSchema(moduleSource); + if (moduleSchema === undefined) { fail('Failed to find module schame'); } expect(moduleSchema.type).toBe('versioned'); @@ -52,8 +52,8 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { version: 0, source: Buffer.from(unversionedContractModule), } as const; - const moduleSchema = await getEmbeddedModuleSchema(moduleSource); - if (moduleSchema === null) { + const moduleSchema = getEmbeddedModuleSchema(moduleSource); + if (moduleSchema === undefined) { fail('Failed to find module schame'); } expect(moduleSchema.type).toBe('unversioned'); @@ -67,8 +67,8 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { ) ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = await getEmbeddedModuleSchema(moduleSource); - if (moduleSchema === null) { + const moduleSchema = getEmbeddedModuleSchema(moduleSource); + if (moduleSchema === undefined) { fail('Failed to find module schame'); } expect(moduleSchema.type).toBe('unversioned'); diff --git a/packages/sdk/test/ci/util.test.ts b/packages/sdk/test/ci/util.test.ts index 7479a1250..a96e1ffcb 100644 --- a/packages/sdk/test/ci/util.test.ts +++ b/packages/sdk/test/ci/util.test.ts @@ -1,5 +1,6 @@ -import { stringToInt, wasmToSchema } from '../../src/util.js'; +import { stringToInt } from '../../src/util.js'; import { readFileSync } from 'fs'; +import { getEmbeddedModuleSchema } from '../../src/index.js'; test('stringToInt transforms chosen field, but not others', () => { const keysToTransform = ['a']; @@ -39,7 +40,12 @@ test('Embedded schema is the same as a seperate schema file', () => { const seperateSchema = readFileSync( 'test/ci/resources/icecream-schema.bin' ); - const embeddedSchema = wasmToSchema(wasmModule); + const embeddedSchema = getEmbeddedModuleSchema({ + source: wasmModule, + version: 1, + }); - expect(new Uint8Array(seperateSchema)).toEqual(embeddedSchema); + expect(new Uint8Array(seperateSchema)).toEqual( + new Uint8Array(embeddedSchema!.buffer) + ); }); diff --git a/packages/sdk/test/client/clientV2.test.ts b/packages/sdk/test/client/clientV2.test.ts index 68f2965be..128240db8 100644 --- a/packages/sdk/test/client/clientV2.test.ts +++ b/packages/sdk/test/client/clientV2.test.ts @@ -745,7 +745,7 @@ test.each(clients)('getEmbeddedSchema', async (client) => { const rawReturnValue = invoked.returnValue; const returnValue = v1.deserializeReceiveReturnValue( v1.ReturnValue.toBuffer(rawReturnValue), - schema, + schema!.buffer, v1.ContractName.fromStringUnchecked('weather'), v1.EntrypointName.fromStringUnchecked('get') ); From f6ca2f0a421aaef781ffa9a4d615b7b8a7a1988a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 27 Aug 2024 14:32:42 +0200 Subject: [PATCH 02/21] Update concordium-base reference --- deps/concordium-base | 2 +- examples/reactnative/ios/Podfile.lock | 2 +- packages/rust-bindings/Cargo.lock | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deps/concordium-base b/deps/concordium-base index 6fcfe4ba3..8c925efc1 160000 --- a/deps/concordium-base +++ b/deps/concordium-base @@ -1 +1 @@ -Subproject commit 6fcfe4ba3276de73d953dba29c3e153ea5772692 +Subproject commit 8c925efc17405cc2927f20df46ed5b57275840c2 diff --git a/examples/reactnative/ios/Podfile.lock b/examples/reactnative/ios/Podfile.lock index f95249369..d8dfed029 100644 --- a/examples/reactnative/ios/Podfile.lock +++ b/examples/reactnative/ios/Podfile.lock @@ -716,4 +716,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: c70448f9d8b13c40c47391af88ee9f69ffe85d63 -COCOAPODS: 1.14.3 +COCOAPODS: 1.15.2 diff --git a/packages/rust-bindings/Cargo.lock b/packages/rust-bindings/Cargo.lock index dfcf43d56..36a5b398b 100644 --- a/packages/rust-bindings/Cargo.lock +++ b/packages/rust-bindings/Cargo.lock @@ -350,7 +350,7 @@ dependencies = [ [[package]] name = "concordium-contracts-common" -version = "9.1.0" +version = "9.2.0" dependencies = [ "base64", "bs58", @@ -379,7 +379,7 @@ dependencies = [ [[package]] name = "concordium_base" -version = "5.0.0" +version = "6.0.0" dependencies = [ "anyhow", "ark-bls12-381", @@ -1818,7 +1818,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wallet_library" -version = "0.3.0" +version = "0.4.0" dependencies = [ "anyhow", "chrono", From affcd780eac824095641baf3d0e01cc949a86354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 27 Aug 2024 14:46:24 +0200 Subject: [PATCH 03/21] Align `TransactionType` enum with the corresponding type from `concordium-grpc-api` --- packages/sdk/src/types.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 9b97bf22c..3658f41e6 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -1187,18 +1187,18 @@ export enum AccountTransactionType { UpdateBakerStake = 6, UpdateBakerRestakeEarnings = 7, UpdateBakerKeys = 8, - UpdateCredentialKeys = 13, - EncryptedAmountTransfer = 16, - TransferToEncrypted = 17, - TransferToPublic = 18, - TransferWithSchedule = 19, - UpdateCredentials = 20, - RegisterData = 21, - TransferWithMemo = 22, - EncryptedAmountTransferWithMemo = 23, - TransferWithScheduleAndMemo = 24, - ConfigureBaker = 25, - ConfigureDelegation = 26, + UpdateCredentialKeys = 9, + EncryptedAmountTransfer = 10, + TransferToEncrypted = 11, + TransferToPublic = 12, + TransferWithSchedule = 13, + UpdateCredentials = 14, + RegisterData = 15, + TransferWithMemo = 16, + EncryptedAmountTransferWithMemo = 17, + TransferWithScheduleAndMemo = 18, + ConfigureBaker = 19, + ConfigureDelegation = 20, } export function isAccountTransactionType(candidate: number): candidate is AccountTransactionType { From 26c3517e05abf02e14a7ac84b830d748f5e57433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 27 Aug 2024 15:19:23 +0200 Subject: [PATCH 04/21] Update `AccountInfo` with cooldown fields --- packages/sdk/src/types.ts | 98 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 3658f41e6..69ce74419 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -939,27 +939,59 @@ type PoolStatusWrapper = S & { }; export interface BakerPoolStatusDetails { + /** The pool owner */ bakerId: BakerId; + /** The account address of the pool owner */ bakerAddress: AccountAddress.Type; - bakerEquityCapital: CcdAmount.Type; - delegatedCapital: CcdAmount.Type; - delegatedCapitalCap: CcdAmount.Type; - poolInfo: BakerPoolInfo; + /** The equity capital provided by the pool owner. Absent if the pool is removed. */ + bakerEquityCapital?: CcdAmount.Type; + /** The capital delegated to the pool by other accounts. Absent if the pool is removed. */ + delegatedCapital?: CcdAmount.Type; + /** + * The maximum amount that may be delegated to the pool, accounting for leverage and stake limits. + * Absent if the pool is removed + */ + delegatedCapitalCap?: CcdAmount.Type; + /** + * The pool info associated with the pool: open status, metadata URL and commission rates. + * Absent if the pool is removed + */ + poolInfo?: BakerPoolInfo; + /** Any pending change to the equity capital. This is not used from protocol version 7 onwards, as stake changes are immediate. */ bakerStakePendingChange: BakerPoolPendingChange; - currentPaydayStatus: CurrentPaydayBakerPoolStatus | null; + /** Information of the pool in the current reward period. */ + currentPaydayStatus?: CurrentPaydayBakerPoolStatus | null; + /** Total capital staked across all pools, including passive delegation. */ allPoolTotalCapital: CcdAmount.Type; } +/** + * Contains information about a given pool at the end of a given block. + * From protocol version 7, pool removal has immediate effect, however, the + * pool may still be present for the current (and possibly next) reward period. + * In this case, the `current_payday_info` field will be set, but the + * `equity_capital`, `delegated_capital`, `delegated_capital_cap` and, + * `pool_info` fields will all be absent. The `equity_pending_change` field + * will also be absent, as stake changes are immediate. + */ export type BakerPoolStatus = PoolStatusWrapper; export interface PassiveDelegationStatusDetails { + /** The total capital delegated passively. */ delegatedCapital: CcdAmount.Type; + /** The passive delegation commission rates. */ commissionRates: CommissionRates; + /** The transaction fees accruing to the passive delegators in the current reward period. */ currentPaydayTransactionFeesEarned: CcdAmount.Type; + /** The effective delegated capital of passive delegators for the current reward period. */ currentPaydayDelegatedCapital: CcdAmount.Type; + /** Total capital staked across all pools, including passive delegation. */ allPoolTotalCapital: CcdAmount.Type; } +/** + * Contains information about passive delegators at the end of a given block. + */ export type PassiveDelegationStatus = PoolStatusWrapper< PoolStatusType.PassiveDelegation, PassiveDelegationStatusDetails @@ -1037,6 +1069,21 @@ interface AccountInfoCommon { accountEncryptedAmount: AccountEncryptedAmount; accountReleaseSchedule: AccountReleaseSchedule; accountCredentials: Record; + /** + * The stake on the account that is in cooldown. + * There can be multiple amounts in cooldown that expire at different times. + * This was introduced in protocol version 7, and so is not present in + * earlier protocol versions. + */ + accountCooldowns: Cooldown[]; + /** + * The available (unencrypted) balance of the account (i.e. that can be transferred + * or used to pay for transactions). This is the balance minus the locked amount. + * The locked amount is the maximum of the amount in the release schedule and + * the total amount that is actively staked or in cooldown (inactive stake). + * This was introduced with node version 7.0 + */ + accountAvailableBalance: CcdAmount.Type; } export interface AccountInfoSimple extends AccountInfoCommon { @@ -1832,3 +1879,44 @@ export type BlockItem = expiry: number; }; }; + +/** + * The status of a cooldown. When stake is removed from a baker or delegator + * (from protocol version 7) it first enters the pre-pre-cooldown state. + * The next time the stake snaphot is taken (at the epoch transition before + * a payday) it enters the pre-cooldown state. At the subsequent payday, it + * enters the cooldown state. At the payday after the end of the cooldown + * period, the stake is finally released. + */ +export enum CooldownStatus { + /** + * The amount is in cooldown and will expire at the specified time, becoming available + * at the subsequent pay day. + */ + Cooldown, + /** + * The amount will enter cooldown at the next pay day. The specified end time is + * projected to be the end of the cooldown period, but the actual end time will be + * determined at the payday, and may be different if the global cooldown period + * changes. + */ + PreCooldown, + /** + * The amount will enter pre-cooldown at the next snapshot epoch (i.e. the epoch + * transition before a pay day transition). As with pre-cooldown, the specified + * end time is projected, but the actual end time will be determined later. + */ + PrePreCooldown, +} + +/** + * Describes a cooldown associated with removal of stake from a baker/delegator account + */ +export type Cooldown = { + /** The time at which the cooldown will end */ + timestamp: Timestamp.Type; + /** The amount that is in cooldown and set to be released at the end of the cooldown period */ + amount: CcdAmount.Type; + /** The status of the cooldown */ + cooldownStatus: CooldownStatus; +}; From 3174697cd622e287343da447d8d7d28d00588547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 08:14:00 +0200 Subject: [PATCH 05/21] Translation of updated grpc types --- packages/sdk/src/grpc/translation.ts | 35 ++++++++++++++++++---------- packages/sdk/src/types.ts | 4 ++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/sdk/src/grpc/translation.ts b/packages/sdk/src/grpc/translation.ts index 290536572..961a00be1 100644 --- a/packages/sdk/src/grpc/translation.ts +++ b/packages/sdk/src/grpc/translation.ts @@ -314,10 +314,7 @@ function transPoolInfo(info: v2.BakerPoolInfo): v1.BakerPoolInfo { }; } -function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.CurrentPaydayBakerPoolStatus | null { - if (!status) { - return null; - } +function transPaydayStatus(status: v2.PoolCurrentPaydayInfo): v1.CurrentPaydayBakerPoolStatus { return { blocksBaked: status.blocksBaked, finalizationLive: status.finalizationLive, @@ -330,6 +327,14 @@ function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.Cur }; } +function transCooldown(cooldown: v2.Cooldown): v1.Cooldown { + return { + amount: CcdAmount.fromProto(unwrap(cooldown.amount)), + timestamp: Timestamp.fromProto(unwrap(cooldown.endTime)), + status: cooldown.status as number, + }; +} + export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo { const aggAmount = acc.encryptedBalance?.aggregatedAmount?.value; const numAggregated = acc.encryptedBalance?.numAggregated; @@ -346,6 +351,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo { total: CcdAmount.fromProto(unwrap(acc.schedule?.total)), schedule: unwrap(acc.schedule?.schedules).map(trRelease), }; + const cooldowns = acc.cooldowns.map(transCooldown); + const availableBalance = CcdAmount.fromProto(unwrap(acc.availableBalance)); const accInfoCommon: v1.AccountInfoSimple = { type: v1.AccountInfoType.Simple, accountAddress: AccountAddress.fromProto(unwrap(acc.address)), @@ -357,6 +364,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo { accountEncryptedAmount: encryptedAmount, accountReleaseSchedule: releaseSchedule, accountCredentials: mapRecord(acc.creds, trCred), + accountCooldowns: cooldowns, + accountAvailableBalance: availableBalance, }; if (acc.stake?.stakingInfo.oneofKind === 'delegator') { @@ -531,12 +540,14 @@ export function bakerPoolInfo(info: v2.PoolInfoResponse): v1.BakerPoolStatus { poolType: v1.PoolStatusType.BakerPool, bakerId: unwrap(info.baker?.value), bakerAddress: AccountAddress.fromProto(unwrap(info.address)), - bakerEquityCapital: CcdAmount.fromProto(unwrap(info.equityCapital)), - delegatedCapital: CcdAmount.fromProto(unwrap(info.delegatedCapital)), - delegatedCapitalCap: CcdAmount.fromProto(unwrap(info.delegatedCapitalCap)), - poolInfo: transPoolInfo(unwrap(info?.poolInfo)), + bakerEquityCapital: info.equityCapital !== undefined ? CcdAmount.fromProto(info.equityCapital) : undefined, + delegatedCapital: info.delegatedCapital !== undefined ? CcdAmount.fromProto(info.delegatedCapital) : undefined, + delegatedCapitalCap: + info.delegatedCapitalCap !== undefined ? CcdAmount.fromProto(info.delegatedCapitalCap) : undefined, + poolInfo: info.poolInfo !== undefined ? transPoolInfo(info.poolInfo) : undefined, bakerStakePendingChange: transPoolPendingChange(info.equityPendingChange), - currentPaydayStatus: transPaydayStatus(info.currentPaydayInfo), + currentPaydayStatus: + info.currentPaydayInfo !== undefined ? transPaydayStatus(info.currentPaydayInfo) : undefined, allPoolTotalCapital: CcdAmount.fromProto(unwrap(info.allPoolTotalCapital)), }; } @@ -830,8 +841,8 @@ function trBakerEvent(bakerEvent: v2.BakerEvent, account: AccountAddress.Type): account, }; } - case undefined: - throw Error('Failed translating BakerEvent, encountered undefined'); + default: + throw Error('Unrecognized event type. This should be impossible.'); } } @@ -847,7 +858,7 @@ function trDelegTarget(delegationTarget: v2.DelegationTarget | undefined): v1.Ev delegateType: v1.DelegationTargetType.PassiveDelegation, }; } else { - throw 'Failed translating DelegationTarget, encountered undefined'; + throw Error('Failed translating DelegationTarget, encountered undefined'); } } diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 69ce74419..252169229 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -960,7 +960,7 @@ export interface BakerPoolStatusDetails { /** Any pending change to the equity capital. This is not used from protocol version 7 onwards, as stake changes are immediate. */ bakerStakePendingChange: BakerPoolPendingChange; /** Information of the pool in the current reward period. */ - currentPaydayStatus?: CurrentPaydayBakerPoolStatus | null; + currentPaydayStatus?: CurrentPaydayBakerPoolStatus; /** Total capital staked across all pools, including passive delegation. */ allPoolTotalCapital: CcdAmount.Type; } @@ -1918,5 +1918,5 @@ export type Cooldown = { /** The amount that is in cooldown and set to be released at the end of the cooldown period */ amount: CcdAmount.Type; /** The status of the cooldown */ - cooldownStatus: CooldownStatus; + status: CooldownStatus; }; From ca952cd751460b1131fcfa14fa9d5bfce3ae0183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 10:19:43 +0200 Subject: [PATCH 06/21] Revert "Align `TransactionType` enum with the corresponding type from" This reverts commit affcd780eac824095641baf3d0e01cc949a86354. --- packages/sdk/src/types.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 252169229..11af926f4 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -1234,18 +1234,18 @@ export enum AccountTransactionType { UpdateBakerStake = 6, UpdateBakerRestakeEarnings = 7, UpdateBakerKeys = 8, - UpdateCredentialKeys = 9, - EncryptedAmountTransfer = 10, - TransferToEncrypted = 11, - TransferToPublic = 12, - TransferWithSchedule = 13, - UpdateCredentials = 14, - RegisterData = 15, - TransferWithMemo = 16, - EncryptedAmountTransferWithMemo = 17, - TransferWithScheduleAndMemo = 18, - ConfigureBaker = 19, - ConfigureDelegation = 20, + UpdateCredentialKeys = 13, + EncryptedAmountTransfer = 16, + TransferToEncrypted = 17, + TransferToPublic = 18, + TransferWithSchedule = 19, + UpdateCredentials = 20, + RegisterData = 21, + TransferWithMemo = 22, + EncryptedAmountTransferWithMemo = 23, + TransferWithScheduleAndMemo = 24, + ConfigureBaker = 25, + ConfigureDelegation = 26, } export function isAccountTransactionType(candidate: number): candidate is AccountTransactionType { From 00733232d4f7a988e018f3a6c6211509bf7c51b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 10:24:36 +0200 Subject: [PATCH 07/21] Fix changelog --- packages/sdk/CHANGELOG.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 4806a1c49..e5fa0f556 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 8.0.0 + +### Breaking changes + +- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. + It also no longer is `async` because there isn't any need for it to be so. +- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` + (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). + This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. + It also means that it returns `null` instead of an error when no embedded schema was found. + + ## 7.5.1 ### Fixed @@ -36,16 +48,6 @@ - Serialization of nonces with `serializeCIS4RevocationDataHolder` to serialize as little endian. -### Breaking changes - -- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. - It also no longer is `async` because there isn't any need for it to be so. -- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` - (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). - This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. - It also means that it returns `null` instead of an error when no embedded schema was found. - - ## 7.3.2 ### Added From 865b614b50a3aabbe4939c2d686d9d5c8dffb5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 10:40:26 +0200 Subject: [PATCH 08/21] Update changelog with p7 conformance changes --- packages/sdk/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index e5fa0f556..2a13e6b20 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -10,7 +10,7 @@ (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. It also means that it returns `null` instead of an error when no embedded schema was found. - +- Update `AccountInfo` and `BakerPoolStatus` according to the changes introduced in the GRPC types introduced with node version 7 ## 7.5.1 From ea4d1935d499382b8fe615f1e957e36c52af5a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 11:02:36 +0200 Subject: [PATCH 09/21] Bump version --- packages/ccd-js-gen/package.json | 4 ++-- packages/sdk/package.json | 2 +- packages/wallet-connectors/package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/ccd-js-gen/package.json b/packages/ccd-js-gen/package.json index ead2c2857..9db16029e 100644 --- a/packages/ccd-js-gen/package.json +++ b/packages/ccd-js-gen/package.json @@ -40,10 +40,10 @@ }, "license": "Apache-2.0", "peerDependencies": { - "@concordium/web-sdk": "7.x" + "@concordium/web-sdk": ">= 7" }, "dependencies": { - "@concordium/web-sdk": "workspace:^7.0.0", + "@concordium/web-sdk": "workspace:^8.0.0", "buffer": "^6.0.3", "commander": "^11.0.0", "sanitize-filename": "^1.6.3", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 2589f2062..ea4b2390a 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/web-sdk", - "version": "7.5.1", + "version": "8.0.0", "license": "Apache-2.0", "engines": { "node": ">=16" diff --git a/packages/wallet-connectors/package.json b/packages/wallet-connectors/package.json index 7c5bb46c5..90902d7ae 100644 --- a/packages/wallet-connectors/package.json +++ b/packages/wallet-connectors/package.json @@ -38,7 +38,7 @@ "buffer": "^6.0.3" }, "peerDependencies": { - "@concordium/web-sdk": "7.x", + "@concordium/web-sdk": ">= 7", "@walletconnect/types": "^2.13.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index d43d3ecbd..0eac0e0a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3565,7 +3565,7 @@ __metadata: version: 0.0.0-use.local resolution: "@concordium/ccd-js-gen@workspace:packages/ccd-js-gen" dependencies: - "@concordium/web-sdk": "workspace:^7.0.0" + "@concordium/web-sdk": "workspace:^8.0.0" "@types/jest": ^26.0.23 "@types/node": ^20.5.0 buffer: ^6.0.3 @@ -3578,7 +3578,7 @@ __metadata: ts-morph: ^19.0.0 typescript: ^5.2.2 peerDependencies: - "@concordium/web-sdk": 7.x + "@concordium/web-sdk": 8.x bin: ccd-js-gen: bin/ccd-js-gen.js languageName: unknown @@ -3690,12 +3690,12 @@ __metadata: ts-node: ^10.9.2 typescript: ^5.2.2 peerDependencies: - "@concordium/web-sdk": 7.x + "@concordium/web-sdk": ">= 7" "@walletconnect/types": ^2.13.1 languageName: unknown linkType: soft -"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:^7.0.0, @concordium/web-sdk@workspace:packages/sdk": +"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:^8.0.0, @concordium/web-sdk@workspace:packages/sdk": version: 0.0.0-use.local resolution: "@concordium/web-sdk@workspace:packages/sdk" dependencies: From e75709bf639595bc39333fd88b339c4e9285304b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 11:02:36 +0200 Subject: [PATCH 10/21] Bump version --- packages/ccd-js-gen/package.json | 4 ++-- packages/sdk/package.json | 2 +- packages/wallet-connectors/package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/ccd-js-gen/package.json b/packages/ccd-js-gen/package.json index ead2c2857..9db16029e 100644 --- a/packages/ccd-js-gen/package.json +++ b/packages/ccd-js-gen/package.json @@ -40,10 +40,10 @@ }, "license": "Apache-2.0", "peerDependencies": { - "@concordium/web-sdk": "7.x" + "@concordium/web-sdk": ">= 7" }, "dependencies": { - "@concordium/web-sdk": "workspace:^7.0.0", + "@concordium/web-sdk": "workspace:^8.0.0", "buffer": "^6.0.3", "commander": "^11.0.0", "sanitize-filename": "^1.6.3", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 2589f2062..ea4b2390a 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/web-sdk", - "version": "7.5.1", + "version": "8.0.0", "license": "Apache-2.0", "engines": { "node": ">=16" diff --git a/packages/wallet-connectors/package.json b/packages/wallet-connectors/package.json index 7c5bb46c5..90902d7ae 100644 --- a/packages/wallet-connectors/package.json +++ b/packages/wallet-connectors/package.json @@ -38,7 +38,7 @@ "buffer": "^6.0.3" }, "peerDependencies": { - "@concordium/web-sdk": "7.x", + "@concordium/web-sdk": ">= 7", "@walletconnect/types": "^2.13.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index d43d3ecbd..9827863ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3565,7 +3565,7 @@ __metadata: version: 0.0.0-use.local resolution: "@concordium/ccd-js-gen@workspace:packages/ccd-js-gen" dependencies: - "@concordium/web-sdk": "workspace:^7.0.0" + "@concordium/web-sdk": "workspace:^8.0.0" "@types/jest": ^26.0.23 "@types/node": ^20.5.0 buffer: ^6.0.3 @@ -3578,7 +3578,7 @@ __metadata: ts-morph: ^19.0.0 typescript: ^5.2.2 peerDependencies: - "@concordium/web-sdk": 7.x + "@concordium/web-sdk": ">= 7" bin: ccd-js-gen: bin/ccd-js-gen.js languageName: unknown @@ -3690,12 +3690,12 @@ __metadata: ts-node: ^10.9.2 typescript: ^5.2.2 peerDependencies: - "@concordium/web-sdk": 7.x + "@concordium/web-sdk": ">= 7" "@walletconnect/types": ^2.13.1 languageName: unknown linkType: soft -"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:^7.0.0, @concordium/web-sdk@workspace:packages/sdk": +"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:^8.0.0, @concordium/web-sdk@workspace:packages/sdk": version: 0.0.0-use.local resolution: "@concordium/web-sdk@workspace:packages/sdk" dependencies: From 80f4bf95a61fd8367c91699758603aca8d544a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 11:24:33 +0200 Subject: [PATCH 11/21] Added new transaction events --- packages/sdk/src/grpc/translation.ts | 15 +++++++++++++-- packages/sdk/src/types.ts | 2 +- packages/sdk/src/types/transactionEvent.ts | 18 ++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/sdk/src/grpc/translation.ts b/packages/sdk/src/grpc/translation.ts index 961a00be1..80581f694 100644 --- a/packages/sdk/src/grpc/translation.ts +++ b/packages/sdk/src/grpc/translation.ts @@ -841,7 +841,13 @@ function trBakerEvent(bakerEvent: v2.BakerEvent, account: AccountAddress.Type): account, }; } - default: + case 'delegationRemoved': { + return { + tag: v1.TransactionEventTag.BakerDelegationRemoved, + delegatorId: unwrap(event.delegationRemoved.delegatorId?.id?.value), + }; + } + case undefined: throw Error('Unrecognized event type. This should be impossible.'); } } @@ -913,7 +919,12 @@ function trDelegationEvent(delegationEvent: v2.DelegationEvent, account: Account delegatorId: unwrap(event.delegationRemoved.id?.value), account, }; - default: + case 'bakerRemoved': + return { + tag: v1.TransactionEventTag.DelegationBakerRemoved, + bakerId: unwrap(event.bakerRemoved.bakerId?.value), + }; + case undefined: throw Error('Unrecognized event type. This should be impossible.'); } } diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 11af926f4..35da39b10 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -1072,7 +1072,7 @@ interface AccountInfoCommon { /** * The stake on the account that is in cooldown. * There can be multiple amounts in cooldown that expire at different times. - * This was introduced in protocol version 7, and so is not present in + * This was introduced in protocol version 7, and will be empty in * earlier protocol versions. */ accountCooldowns: Cooldown[]; diff --git a/packages/sdk/src/types/transactionEvent.ts b/packages/sdk/src/types/transactionEvent.ts index a865ccee8..a49e559e7 100644 --- a/packages/sdk/src/types/transactionEvent.ts +++ b/packages/sdk/src/types/transactionEvent.ts @@ -43,12 +43,14 @@ export enum TransactionEventTag { BakerSetTransactionFeeCommission = 'BakerSetTransactionFeeCommission', BakerSetBakingRewardCommission = 'BakerSetBakingRewardCommission', BakerSetFinalizationRewardCommission = 'BakerSetFinalizationRewardCommission', + BakerDelegationRemoved = 'BakerDelegationRemoved', DelegationStakeIncreased = 'DelegationStakeIncreased', DelegationStakeDecreased = 'DelegationStakeDecreased', DelegationSetRestakeEarnings = 'DelegationSetRestakeEarnings', DelegationSetDelegationTarget = 'DelegationSetDelegationTarget', DelegationAdded = 'DelegationAdded', DelegationRemoved = 'DelegationRemoved', + DelegationBakerRemoved = 'DelegationBakerRemoved', TransferMemo = 'TransferMemo', Transferred = 'Transferred', Interrupted = 'Interrupted', @@ -247,6 +249,11 @@ export interface DelegationStakeChangedEvent { newStake: CcdAmount.Type; } +export interface DelegationBakerRemovedEvent { + tag: TransactionEventTag.DelegationBakerRemoved; + bakerId: BakerId; +} + // Baker Events export interface BakerAddedEvent { @@ -324,6 +331,11 @@ export interface BakerSetTransactionFeeCommissionEvent { transactionFeeCommission: number; } +export interface BakerDelegationRemovedEvent { + tag: TransactionEventTag.BakerDelegationRemoved; + delegatorId: DelegatorId; +} + export interface UpdateEnqueuedEvent { tag: TransactionEventTag.UpdateEnqueued; effectiveTime: number; @@ -341,9 +353,11 @@ export type BakerEvent = | BakerStakeChangedEvent | BakerAddedEvent | BakerRemovedEvent - | BakerKeysUpdatedEvent; + | BakerKeysUpdatedEvent + | BakerDelegationRemovedEvent; export type DelegationEvent = | DelegatorEvent | DelegationSetDelegationTargetEvent | DelegationSetRestakeEarningsEvent - | DelegationStakeChangedEvent; + | DelegationStakeChangedEvent + | DelegationBakerRemovedEvent; From 377c93ee75411ead9310aa9ccbc0bbd9fb201f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 11:46:48 +0200 Subject: [PATCH 12/21] Fix examples build --- examples/nodejs/client/getPoolInfo.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/nodejs/client/getPoolInfo.ts b/examples/nodejs/client/getPoolInfo.ts index 0cf433f51..f449965fb 100644 --- a/examples/nodejs/client/getPoolInfo.ts +++ b/examples/nodejs/client/getPoolInfo.ts @@ -53,11 +53,17 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block); const bakerPool: BakerPoolStatus = await client.getPoolInfo(BigInt(cli.flags.poolOwner), blockHash); - console.log('Open status:', bakerPool.poolInfo.openStatus); + console.log('Open status:', bakerPool.poolInfo?.openStatus); console.log('Baker address:', bakerPool.bakerAddress); - console.log('CCD provided by the baker to the pool:', CcdAmount.toCcd(bakerPool.bakerEquityCapital)); - console.log('CCD provided by the delegators to the pool:', CcdAmount.toCcd(bakerPool.delegatedCapital)); + console.log( + 'CCD provided by the baker to the pool:', + bakerPool.bakerEquityCapital !== undefined ? CcdAmount.toCcd(bakerPool.bakerEquityCapital) : undefined + ); + console.log( + 'CCD provided by the delegators to the pool:', + bakerPool.delegatedCapital !== undefined ? CcdAmount.toCcd(bakerPool.delegatedCapital) : undefined + ); console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(bakerPool.allPoolTotalCapital)); - console.log('Pool commision rates:', bakerPool.poolInfo.commissionRates); + console.log('Pool commision rates:', bakerPool.poolInfo?.commissionRates); // #endregion documentation-snippet })(); From 3c5b92b2c0835c4ae01e610842b689206060de4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 14:26:16 +0200 Subject: [PATCH 13/21] Fix build fail --- packages/sdk/test/client/resources/expectedJsons.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/sdk/test/client/resources/expectedJsons.ts b/packages/sdk/test/client/resources/expectedJsons.ts index d6cd9b72e..fd232ba8d 100644 --- a/packages/sdk/test/client/resources/expectedJsons.ts +++ b/packages/sdk/test/client/resources/expectedJsons.ts @@ -1403,6 +1403,8 @@ export const bakerAccountInfo: AccountInfoBaker = { restakeEarnings: true, stakedAmount: CcdAmount.fromMicroCcd(7349646704751788n), }, + accountCooldowns: [], + accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... }; export const delegatorAccountInfo: AccountInfoDelegator = { @@ -1508,6 +1510,8 @@ export const delegatorAccountInfo: AccountInfoDelegator = { restakeEarnings: true, stakedAmount: CcdAmount.fromMicroCcd(620942412516n), }, + accountCooldowns: [], + accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... }; export const credIdAccountInfo: AccountInfoSimple = { @@ -1582,6 +1586,8 @@ export const credIdAccountInfo: AccountInfoSimple = { 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', accountIndex: 11n, accountAddress: AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'), + accountCooldowns: [], + accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... }; export const regularAccountInfo: AccountInfoSimple = { @@ -1656,6 +1662,8 @@ export const regularAccountInfo: AccountInfoSimple = { 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', accountIndex: 11n, accountAddress: AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'), + accountCooldowns: [], + accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... }; const rootKeys = { @@ -2024,7 +2032,6 @@ export const bakerPoolStatusWithPendingChange: BakerPoolStatus = { pendingChangeType: BakerPoolPendingChangeType.RemovePool, effectiveTime: new Date('2022-12-08T07:54:00.000Z'), }, - currentPaydayStatus: null, allPoolTotalCapital: CcdAmount.fromMicroCcd(46470271917743628n), }; From 26b9fbe53335a382ce070201d2dafb78c9015269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 15:50:53 +0200 Subject: [PATCH 14/21] Set available balance for client test data --- packages/sdk/test/client/resources/expectedJsons.ts | 11 +++++++---- packages/sdk/test/client/testHelpers.ts | 5 +---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/sdk/test/client/resources/expectedJsons.ts b/packages/sdk/test/client/resources/expectedJsons.ts index fd232ba8d..7184c0467 100644 --- a/packages/sdk/test/client/resources/expectedJsons.ts +++ b/packages/sdk/test/client/resources/expectedJsons.ts @@ -148,6 +148,9 @@ export const accountInfo = { }, }, }, + availableBalance: { + value: '35495453082577742', + }, threshold: { value: 1, }, @@ -1404,7 +1407,7 @@ export const bakerAccountInfo: AccountInfoBaker = { stakedAmount: CcdAmount.fromMicroCcd(7349646704751788n), }, accountCooldowns: [], - accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... + accountAvailableBalance: CcdAmount.fromMicroCcd(100000000000000n), }; export const delegatorAccountInfo: AccountInfoDelegator = { @@ -1511,7 +1514,7 @@ export const delegatorAccountInfo: AccountInfoDelegator = { stakedAmount: CcdAmount.fromMicroCcd(620942412516n), }, accountCooldowns: [], - accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... + accountAvailableBalance: CcdAmount.fromMicroCcd(6088626n), }; export const credIdAccountInfo: AccountInfoSimple = { @@ -1587,7 +1590,7 @@ export const credIdAccountInfo: AccountInfoSimple = { accountIndex: 11n, accountAddress: AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'), accountCooldowns: [], - accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... + accountAvailableBalance: CcdAmount.fromMicroCcd(35495453082577742n), }; export const regularAccountInfo: AccountInfoSimple = { @@ -1663,7 +1666,7 @@ export const regularAccountInfo: AccountInfoSimple = { accountIndex: 11n, accountAddress: AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'), accountCooldowns: [], - accountAvailableBalance: CcdAmount.zero(), // FIXME: when this is available on testnet... + accountAvailableBalance: CcdAmount.fromMicroCcd(35495453082577742n), }; const rootKeys = { diff --git a/packages/sdk/test/client/testHelpers.ts b/packages/sdk/test/client/testHelpers.ts index 0399f744a..150505166 100644 --- a/packages/sdk/test/client/testHelpers.ts +++ b/packages/sdk/test/client/testHelpers.ts @@ -24,10 +24,7 @@ export function getNodeClientV2(address = TESTNET_NODE, port = GRPCV2_PORT): Con * Creates a gRPC v2 client (for web) to communicate with a local concordium-node * used for automatic tests. */ -export function getNodeClientWeb( - address = 'http://node.testnet.concordium.com', - port = GRPCV2_PORT -): ConcordiumGRPCClient { +export function getNodeClientWeb(address = `http://${TESTNET_NODE}`, port = GRPCV2_PORT): ConcordiumGRPCClient { return new ConcordiumGRPCWebClient(address, port, { timeout: 15000 }); } From 1e4bbb6cc9ded0ad3bf612f3eb8035375ce79454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Wed, 28 Aug 2024 15:59:58 +0200 Subject: [PATCH 15/21] Remove credID equality tests --- packages/sdk/test/client/clientV2.test.ts | 12 --- .../test/client/resources/expectedJsons.ts | 76 ------------------- 2 files changed, 88 deletions(-) diff --git a/packages/sdk/test/client/clientV2.test.ts b/packages/sdk/test/client/clientV2.test.ts index b5fd22bd6..a465e843b 100644 --- a/packages/sdk/test/client/clientV2.test.ts +++ b/packages/sdk/test/client/clientV2.test.ts @@ -28,9 +28,6 @@ const clientWeb = getNodeClientWeb(); const clients = testEnvironment === 'node' ? [clientV2, clientWeb] : [clientWeb]; const testAccount = v1.AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'); -const testCredId = v1.CredentialRegistrationId.fromHexString( - 'aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f' -); const testAccBaker = v1.AccountAddress.fromBase58('4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L'); const testAccDeleg = v1.AccountAddress.fromBase58('3bFo43GiPnkk5MmaSdsRVboaX2DNSKaRkLseQbyB3WPW1osPwh'); const testBlockHash = v1.BlockHash.fromHexString('fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e'); @@ -96,23 +93,14 @@ test.each(clients)('getAccountInfo for delegator', async (client) => { } }); -test.each(clients)('getAccountInfo: Account Address and CredentialRegistrationId is equal', async (client) => { - const accInfo = await client.getAccountInfo(testAccount, testBlockHash); - const credIdInfo = await client.getAccountInfo(testCredId, testBlockHash); - - expect(accInfo).toEqual(credIdInfo); -}); - test.each(clients)( // TODO: fails.. 'accountInfo implementations is the same', async (client) => { const regular = await client.getAccountInfo(testAccount, testBlockHash); - const credId = await client.getAccountInfo(testCredId, testBlockHash); const baker = await client.getAccountInfo(testAccBaker, testBlockHash); const deleg = await client.getAccountInfo(testAccDeleg, testBlockHash); expect(regular).toEqual(expected.regularAccountInfo); - expect(credId).toEqual(expected.credIdAccountInfo); expect(baker).toEqual(expected.bakerAccountInfo); expect(deleg).toEqual(expected.delegatorAccountInfo); } diff --git a/packages/sdk/test/client/resources/expectedJsons.ts b/packages/sdk/test/client/resources/expectedJsons.ts index 7184c0467..132d0cbab 100644 --- a/packages/sdk/test/client/resources/expectedJsons.ts +++ b/packages/sdk/test/client/resources/expectedJsons.ts @@ -1517,82 +1517,6 @@ export const delegatorAccountInfo: AccountInfoDelegator = { accountAvailableBalance: CcdAmount.fromMicroCcd(6088626n), }; -export const credIdAccountInfo: AccountInfoSimple = { - type: AccountInfoType.Simple, - accountNonce: SequenceNumber.create(19), - accountAmount: CcdAmount.fromMicroCcd(35495453082577742n), - accountReleaseSchedule: { total: CcdAmount.zero(), schedule: [] }, - accountCredentials: { - '0': { - v: 0, - value: { - contents: { - arData: { - '1': { - encIdCredPubShare: - 'a91e570e54b9ee7c304570bc3a066ea75dd833086c683a421c11e565482de01ffc2fb742408cf1dbd6c744cdde8835469120ce6a0e0c12fbfd53e9be81656900a95109f80418e7cbba510c457f15a0cb347bdc3f5508d46cec87a9214686a61d', - }, - }, - commitments: { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - cmmAttributes: {}, - cmmCredCounter: - 'b0aa65f420a9f3fab61d3f875eebcc221e43154bfaf1b6365dace99bff20778de7003437631222e845fd9917c8d2874b', - cmmIdCredSecSharingCoeff: [ - '8bac440a2e46ccbfbfa768c6ad99f2abf25f8b327a795ecf23b2b804c327022f06d0aced0b5eed65899a3ef3029804ec', - ], - cmmMaxAccounts: - '869e2bddb2c60703ecd512b55b772baf75691f81bbc45362f88e5abcdab85a23714a92d46fe40457364d506abc2202a3', - cmmPrf: 'b8930e48976902f67f0cbb50b8c2911fcc0646fbccf4bfb6a442ef7d40a8351f48ae7206ee8083e28d357be808803f82', - }, - credId: 'aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', - credentialPublicKeys: { - keys: { - '0': { - schemeId: 'Ed25519', - verifyKey: '9e975c838d037136cff54f7f5b741922dd9bc31e5dd3c9eb793a026b7d1f5125', - }, - '1': { - schemeId: 'Ed25519', - verifyKey: '2d322b8744fa5d01823adce3f6a13bbebdd7b8503c08ccc3d8497e6c46021976', - }, - '2': { - schemeId: 'Ed25519', - verifyKey: '9a77df3f869206a7c085bc1ab821f1e248762a22bb37471b3cefcb83740764c9', - }, - }, - threshold: 2, - }, - ipIdentity: 0, - policy: { - createdAt: '202206', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - revealedAttributes: {}, - validTo: '202306', - }, - revocationThreshold: 1, - }, - type: 'normal', - }, - }, - }, - accountThreshold: 1, - accountEncryptedAmount: { - incomingAmounts: [], - selfAmount: - 'c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', - startIndex: 0n, - }, - accountEncryptionKey: - 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', - accountIndex: 11n, - accountAddress: AccountAddress.fromBase58('3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G'), - accountCooldowns: [], - accountAvailableBalance: CcdAmount.fromMicroCcd(35495453082577742n), -}; - export const regularAccountInfo: AccountInfoSimple = { type: AccountInfoType.Simple, accountNonce: SequenceNumber.create(19), From ba63393e450916d80ec1b3ef8586832bb21a99c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Thu, 29 Aug 2024 10:02:10 +0200 Subject: [PATCH 16/21] Bump versions of depending packages --- packages/ccd-js-gen/CHANGELOG.md | 6 +++++- packages/react-components/CHANGELOG.md | 6 ++++++ packages/react-components/package.json | 4 ++-- packages/wallet-connectors/CHANGELOG.md | 6 ++++++ packages/wallet-connectors/package.json | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/ccd-js-gen/CHANGELOG.md b/packages/ccd-js-gen/CHANGELOG.md index 51c5c9841..89c3aa240 100644 --- a/packages/ccd-js-gen/CHANGELOG.md +++ b/packages/ccd-js-gen/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog - ccd-js-gen -## Unreleased +## 1.2.1 + +### Changed + +- Update peer depedency for `@concordium/web-sdk` to support any version above `7` ## 1.2.0 diff --git a/packages/react-components/CHANGELOG.md b/packages/react-components/CHANGELOG.md index 064a493f4..1fb26c882 100644 --- a/packages/react-components/CHANGELOG.md +++ b/packages/react-components/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.1] + +### Changed + +- Update peer depedency for `@concordium/web-sdk` to support any version above `7` + ## [0.6.0] - 2024-06-12 ### Changed diff --git a/packages/react-components/package.json b/packages/react-components/package.json index da324d1fd..791e79d2f 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/react-components", - "version": "0.6.0", + "version": "0.6.1", "description": "Utility library of React components for building dApps that interact with the Concordium blockchain.", "author": "Concordium Software", "license": "Apache-2.0", @@ -42,7 +42,7 @@ "typescript": "^5.2.2" }, "peerDependencies": { - "@concordium/web-sdk": "7.x", + "@concordium/web-sdk": ">= 7", "react": "^18" } } diff --git a/packages/wallet-connectors/CHANGELOG.md b/packages/wallet-connectors/CHANGELOG.md index 1f0162d2e..a3f7f8624 100644 --- a/packages/wallet-connectors/CHANGELOG.md +++ b/packages/wallet-connectors/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.1] + +### Changed + +- Update peer depedency for `@concordium/web-sdk` to support any version above `7` + ## [0.6.0] - 2024-06-12 ### Fixed diff --git a/packages/wallet-connectors/package.json b/packages/wallet-connectors/package.json index 90902d7ae..eb6de6d1f 100644 --- a/packages/wallet-connectors/package.json +++ b/packages/wallet-connectors/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/wallet-connectors", - "version": "0.6.0", + "version": "0.6.1", "description": "Utility interface for dApps to interact with wallets without depending on the underlying protocol and implementations for Concordium Browser Wallet and Wallet Connect v2.", "author": "Concordium Software", "license": "Apache-2.0", From a76f5b955a04c3ba9349d57035799514c9d6c9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Fri, 6 Sep 2024 11:59:49 +0200 Subject: [PATCH 17/21] Alpha version bump --- packages/ccd-js-gen/package.json | 2 +- packages/sdk/package.json | 2 +- yarn.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ccd-js-gen/package.json b/packages/ccd-js-gen/package.json index 9db16029e..b6efd9dae 100644 --- a/packages/ccd-js-gen/package.json +++ b/packages/ccd-js-gen/package.json @@ -43,7 +43,7 @@ "@concordium/web-sdk": ">= 7" }, "dependencies": { - "@concordium/web-sdk": "workspace:^8.0.0", + "@concordium/web-sdk": "workspace:^", "buffer": "^6.0.3", "commander": "^11.0.0", "sanitize-filename": "^1.6.3", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index ea4b2390a..97e905dc5 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/web-sdk", - "version": "8.0.0", + "version": "8.0.0-alpha.0", "license": "Apache-2.0", "engines": { "node": ">=16" diff --git a/yarn.lock b/yarn.lock index c71963913..e6385dfad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3565,7 +3565,7 @@ __metadata: version: 0.0.0-use.local resolution: "@concordium/ccd-js-gen@workspace:packages/ccd-js-gen" dependencies: - "@concordium/web-sdk": "workspace:^8.0.0" + "@concordium/web-sdk": "workspace:^" "@types/jest": ^26.0.23 "@types/node": ^20.5.0 buffer: ^6.0.3 @@ -3695,7 +3695,7 @@ __metadata: languageName: unknown linkType: soft -"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:^8.0.0, @concordium/web-sdk@workspace:packages/sdk": +"@concordium/web-sdk@workspace:^, @concordium/web-sdk@workspace:packages/sdk": version: 0.0.0-use.local resolution: "@concordium/web-sdk@workspace:packages/sdk" dependencies: From c4c54fe53626fd57d331e05a95388ac66a0966c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Fri, 6 Sep 2024 12:16:15 +0200 Subject: [PATCH 18/21] Add fallback for available balance to be compatible with node version 6 --- packages/sdk/src/grpc/translation.ts | 47 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/packages/sdk/src/grpc/translation.ts b/packages/sdk/src/grpc/translation.ts index 80581f694..1ef27c169 100644 --- a/packages/sdk/src/grpc/translation.ts +++ b/packages/sdk/src/grpc/translation.ts @@ -339,7 +339,7 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo { const aggAmount = acc.encryptedBalance?.aggregatedAmount?.value; const numAggregated = acc.encryptedBalance?.numAggregated; - const encryptedAmount: v1.AccountEncryptedAmount = { + const accountEncryptedAmount: v1.AccountEncryptedAmount = { selfAmount: unwrapValToHex(acc.encryptedBalance?.selfAmount), startIndex: unwrap(acc.encryptedBalance?.startIndex), incomingAmounts: unwrap(acc.encryptedBalance?.incomingAmounts).map(unwrapValToHex), @@ -347,25 +347,54 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo { ...(numAggregated && { numAggregated: numAggregated }), ...(aggAmount && { aggregatedAmount: unwrapToHex(aggAmount) }), }; - const releaseSchedule = { + const accountReleaseSchedule = { total: CcdAmount.fromProto(unwrap(acc.schedule?.total)), schedule: unwrap(acc.schedule?.schedules).map(trRelease), }; - const cooldowns = acc.cooldowns.map(transCooldown); - const availableBalance = CcdAmount.fromProto(unwrap(acc.availableBalance)); + const accountCooldowns = acc.cooldowns.map(transCooldown); + const accountAmount = CcdAmount.fromProto(unwrap(acc.amount)); + + let accountAvailableBalance: CcdAmount.Type; + + // This is undefined for node version <7, so we add this check to be backwards compatible. + if (acc.availableBalance !== undefined) { + accountAvailableBalance = CcdAmount.fromProto(unwrap(acc.availableBalance)); + } else { + // NOTE: implementation borrowed from concordium-browser-wallet. + let staked = 0n; + switch (acc.stake?.stakingInfo.oneofKind) { + case 'baker': { + staked = unwrap(acc.stake.stakingInfo.baker.stakedAmount?.value); + break; + } + case 'delegator': { + staked = unwrap(acc.stake.stakingInfo.delegator.stakedAmount?.value); + break; + } + } + + const scheduled = accountReleaseSchedule ? BigInt(accountReleaseSchedule.total.microCcdAmount) : 0n; + + const max = (first: bigint, second: bigint) => { + return first > second ? first : second; + }; + + const atDisposal = accountAmount.microCcdAmount - max(scheduled, staked); + accountAvailableBalance = CcdAmount.fromMicroCcd(atDisposal); + } const accInfoCommon: v1.AccountInfoSimple = { type: v1.AccountInfoType.Simple, accountAddress: AccountAddress.fromProto(unwrap(acc.address)), accountNonce: SequenceNumber.fromProto(unwrap(acc.sequenceNumber)), - accountAmount: CcdAmount.fromProto(unwrap(acc.amount)), + accountAmount, accountIndex: unwrap(acc.index?.value), accountThreshold: unwrap(acc.threshold?.value), accountEncryptionKey: unwrapValToHex(acc.encryptionKey), - accountEncryptedAmount: encryptedAmount, - accountReleaseSchedule: releaseSchedule, + accountEncryptedAmount, + accountReleaseSchedule, accountCredentials: mapRecord(acc.creds, trCred), - accountCooldowns: cooldowns, - accountAvailableBalance: availableBalance, + accountCooldowns, + accountAvailableBalance, }; if (acc.stake?.stakingInfo.oneofKind === 'delegator') { From f762398593220c93096a7cf3d151eb144ea6c7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Mon, 9 Sep 2024 14:00:16 +0200 Subject: [PATCH 19/21] Version bump --- packages/sdk/CHANGELOG.md | 4 +--- packages/sdk/package.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 4a109bd59..a2b832a07 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,11 +1,9 @@ # Changelog -## 8.0.0 +## 8.0.1 ### Breaking changes -- Minimum supported Concordium node version changes to 7.0 with the changes introduced. - - `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. It also no longer is `async` because there isn't any need for it to be so. - `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 97e905dc5..a71c90bbd 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@concordium/web-sdk", - "version": "8.0.0-alpha.0", + "version": "8.0.1", "license": "Apache-2.0", "engines": { "node": ">=16" From df090d55c512bb7245dda99b0bf1e9fcf6b3f23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 10 Sep 2024 14:27:16 +0200 Subject: [PATCH 20/21] Non-blocking wasm compilation --- packages/sdk/CHANGELOG.md | 1 - packages/sdk/src/types/VersionedModuleSource.ts | 7 +++++-- packages/sdk/test/ci/module-schema.test.ts | 8 ++++---- packages/sdk/test/ci/util.test.ts | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index a2b832a07..a0498c755 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -5,7 +5,6 @@ ### Breaking changes - `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. - It also no longer is `async` because there isn't any need for it to be so. - `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. diff --git a/packages/sdk/src/types/VersionedModuleSource.ts b/packages/sdk/src/types/VersionedModuleSource.ts index 2d4f93239..19b4a41f4 100644 --- a/packages/sdk/src/types/VersionedModuleSource.ts +++ b/packages/sdk/src/types/VersionedModuleSource.ts @@ -101,8 +101,11 @@ export async function parseModuleInterface(moduleSource: VersionedModuleSource): * @returns {RawModuleSchema | null} The raw module schema if found. * @throws If the module source cannot be parsed or contains duplicate schema sections. */ -export function getEmbeddedModuleSchema({ source, version }: VersionedModuleSource): RawModuleSchema | undefined { - const sections = findCustomSections(new WebAssembly.Module(source), version); +export async function getEmbeddedModuleSchema({ + source, + version, +}: VersionedModuleSource): Promise { + const sections = findCustomSections(await WebAssembly.compile(source), version); if (sections === undefined) { return undefined; } diff --git a/packages/sdk/test/ci/module-schema.test.ts b/packages/sdk/test/ci/module-schema.test.ts index 32f004918..3f3d9a4de 100644 --- a/packages/sdk/test/ci/module-schema.test.ts +++ b/packages/sdk/test/ci/module-schema.test.ts @@ -12,7 +12,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-versioned.wasm.v1') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -24,7 +24,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis1-wccd-embedded-schema-v0-versioned.wasm.v0') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -39,7 +39,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { version: 0, source: Buffer.from(unversionedContractModule), } as const; - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -51,7 +51,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-unversioned.wasm.v1') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } diff --git a/packages/sdk/test/ci/util.test.ts b/packages/sdk/test/ci/util.test.ts index 178434a60..efa9d4d88 100644 --- a/packages/sdk/test/ci/util.test.ts +++ b/packages/sdk/test/ci/util.test.ts @@ -26,13 +26,13 @@ test('stringToInt will not change the string if no keys match', () => { expect(transformed).toEqual(input); }); -test('Embedded schema is the same as a seperate schema file', () => { +test('Embedded schema is the same as a seperate schema file', async () => { const versionedWasmModule = readFileSync('test/ci/resources/icecream-with-schema.wasm'); // Strip module version information const wasmModule = versionedWasmModule.subarray(8); const seperateSchema = readFileSync('test/ci/resources/icecream-schema.bin'); - const embeddedSchema = getEmbeddedModuleSchema({ + const embeddedSchema = await getEmbeddedModuleSchema({ source: wasmModule, version: 1, }); From b26271741afa881667f3b43f0fe705b6b407d350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 10 Sep 2024 14:52:24 +0200 Subject: [PATCH 21/21] Remove node version requirement from readme --- packages/sdk/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/sdk/README.md b/packages/sdk/README.md index e70d1cc41..e9948db2c 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -4,8 +4,6 @@ Wrappers for interacting with the Concordium node, for the web environment. -**Minimum supported node version is 7.0** - Please see the [documentation](https://developer.concordium.software/concordium-node-sdk-js/index.html) for more information