Skip to content

Commit cce0ef1

Browse files
authored
Merge pull request #476 from Concordium/bugfix/support-token-creation
Bugfix/support token creation
2 parents a384a9b + ffdf42b commit cce0ef1

File tree

5 files changed

+201
-23
lines changed

5 files changed

+201
-23
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
## Unreleased
44

5+
## 10.0.1
6+
7+
### Fixed
8+
9+
- Added missing support for the new transaction summary type `TokenCreation`. This has been added to the
10+
`BlockItemSummary` union type.
11+
512
## 10.0.0
613

7-
Adds support for integrating with Concordium nodes running version 9.
14+
- Adds support for integrating with Concordium nodes running version 9.
815

916
### Breaking changes
1017

@@ -51,6 +58,146 @@ Adds support for integrating with Concordium nodes running version 9.
5158
with `buildAccountSigner`
5259
- A new optional field `createPlt` to `AuthorizationsV1` which exposes the access structure for PLT creation.
5360

61+
## 10.0.0-alpha.? (Unreleased)
62+
63+
### Fixed
64+
65+
- Fix conversion in `TokenAmount.fromDecimals` function when used with large `tokenAmount` values with small `decimal` values.
66+
67+
## 10.0.0-alpha.15
68+
69+
### Fixed
70+
71+
- Fix conversion in `TokenAmount.fromDecimals` function when used with large `decimal` values.
72+
73+
### Changed
74+
75+
- Remove authorization validation for PLT `Token` client.
76+
- All `Token` operations' validations are done in a separate respective functions.
77+
- Removed `UnauthorizedGovernanceOperationError` from `Token` PLT client.
78+
79+
### Added
80+
81+
- Add helper function `validateMint`, `validateBurn`, `validateAllowListUpdate`, `validateDenyListUpdate`
82+
for validating PLT token client operations.
83+
- Add `updateToken` method that returns the latest finilized block state of a token.
84+
85+
## 10.0.0-alpha.14
86+
87+
### Changed
88+
89+
- Enable `denyList`/`allowList` validation on plt token transfers.
90+
- Client side validation in the PLT `Token` client is now disabled by default and has to be enabled explicitly if wanted
91+
92+
### Added
93+
94+
- Add optional `initialSupply` field to `TokenInitializationParameters` type.
95+
- Add `protocolLevelTokens` field to `NextUpdateSequenceNumbers` type.
96+
- Add helper function `createPLTPayload` for creating `CreatePLTPayload`s for the corresponding chain update.
97+
98+
## 10.0.0-alpha.13
99+
100+
### Changed
101+
102+
- Disable `denyList`/`allowList` validation on plt token transfers.
103+
104+
## 10.0.0-alpha.12
105+
106+
### Breaking changes
107+
108+
- Changed the representation of `TokenEvent` to a more flattened version in line with the representation in concordium-base.
109+
- Replaced `TokenUpdateEvent` with the flattened `TokenEvent` mentioned above.
110+
- Revised the constraints associated with `TokenId`.
111+
112+
### Added
113+
114+
- `pause` and `unpause` functions added to the `Token` module, which can be used to pause/unpause execution of token operations respectively.
115+
- `moduleState` added to `Token` instances, which is the parsed token module state of a PLT instance.
116+
117+
### Changed
118+
119+
- Energy cost of PLT mint/burn changed from 100 to 50
120+
- Changed the functions exposed for submitting token updates on `Token` to take optional `TokenUpdateMetadata` instead of
121+
getting the corresponding data from chain.
122+
123+
## 10.0.0-alpha.11
124+
125+
### Fixed
126+
127+
- An issue where the token module state of a PLT could not be correctly decoded from it's CBOR representation.
128+
129+
## 10.0.0-alpha.10
130+
131+
### Fixed
132+
133+
- Fixed a bug where PLT transfer validation would fail when the reciever had no balance if the token had a deny list.
134+
135+
## 10.0.0-alpha.9
136+
137+
### Breaking changes
138+
139+
- Consolidate `TokenHolderPayload` and `TokenGovernancePayload` into `TokenUpdatePayload`, and correspondingly on the
140+
enums `AccountTransactionType` and `TransactionKindString`.
141+
- Consolidate `TokenHolderUpdateHandler` and `TokenGovernanceUpdateHandler` into `TokenUpdateHandler`.
142+
- Consolidate `TokenHolderSummary` and `TokenGovernanceSummary` into `TokenUpdateSummary`, and correspondingly on the `TransactionEvent` enum.
143+
- Consolidate `TokenHolderTransactionFailedRejectReason` and `TokenGovernanceTransactionFailedRejectReason`
144+
into `TokenUpdateTransactionFailedRejectReason`, and correspondingly on the `RejectReasonTag` enum.
145+
- Functionality exposed on `V1.Token` and `V1.Governance` is now available on `Token`, which is a client for interacting with PLTs.
146+
Any functionality previously exposed on the `V1` namespace, has been moved to the root of `@concordium/web-sdk/plt`.
147+
- Removed `UnauthorizedTokenGovernance` type and the corresponding `RejectReasonTag.UnauthorizedTokenGovernance`. This will now happen
148+
as a `EncodedTokenModuleEvent` instead.
149+
- Changed the representation of accounts on any PLT related type from `AccountAddress` to `TokenHolder`.
150+
151+
### Added
152+
153+
- `TokenHolder`: A representation of the different token holder entities. Currently, only accounts are supported.
154+
155+
## 10.0.0-alpha.8
156+
157+
### Breaking changes
158+
159+
- Add `TokenHolderSummary` and `TokenGovernanceSummary` to the possible transaction outcomes declared by
160+
- `AccountTransactionSummary`, and correspondingly `TokenHolderEvent` and `TokenGovernanceEvent` to `TransactionEvent`.
161+
- Added new variants `TokenHolder` and `TokenGovernance` to `TransactionEventTag`, `AccountTransactionType` and correspondingly `TransactionKindString`.
162+
- Added new variant `CreatePLT` to `UpdateType`.
163+
- Updated `AccountInfo` to hold information about the PLTs held by an account.
164+
- Removed `toProto` and `fromProto` from the exposed API for all custom types in the SDK. This should have no impact, as
165+
the parameter/return values are internal-only.
166+
- Added `TokenHolderPayload` and `TokenGovernancePayload` to `AccountTransactionPayload` union type.
167+
- Added reject reasons related to PLT transactions to `RejectReason` union type.
168+
- `CcdAmount.fromDecimal` no longer supports creation from a string with comma used as the decimal separator, e.g.
169+
"10,123".
170+
171+
### Added
172+
173+
- A new package export scoped to hold types and functionality for interacting with PLTs, available at
174+
`@concordium/web-sdk/plt`.
175+
- New types representing entities within the domain of protocol level tokens (PLTs)
176+
- `Cbor`: Represents CBOR encoded details for PLT module state, events, and operations
177+
- `CborMemo`: Represents CBOR encoded memos for PLT transactions
178+
- `TokenId`: A unique text identifier of a PLT
179+
- `TokenAmount`: A representation of a PLT amount
180+
- `TokenModuleReference`: The module reference of a PLT instance
181+
- `TokenMetadataUrl`: An object containing the url for token metadata
182+
- `TokenHolder`: A representation of the different token holder entities. Currently, only accounts are supported.
183+
- `TokenAccountState`, `TokenState`, `TokenInfo`, and `TokenAccountInfo`, all representing PLT related data returned by the
184+
GRPC API of a Concordium node.
185+
- `Token`, which is a client for interacting with PLTs
186+
- `parseModuleEvent`, which attempts to parse an `EncodedTokenModuleEvent` into a `TokenModuleEvent`.
187+
- CBOR conversion functionality to `AccountAddress`.
188+
- An extension for `cbor2`, which registers CBOR encoders for all relevant Concordium types. This is accessible at the
189+
`@concordium/web-sdk/extensions/cbor2` entrypoint.
190+
- `cborEncode` and `cborDecode` functions for deterministic encoding/decoding of objects composed of Concordium domain
191+
types.
192+
- `registerCborDecoders` and `registerCborEncoders` for registering Concordium domain type encoders/decoders globally
193+
for `cbor2`
194+
- **NOTE**: By registering decoders globally without using the returned cleanup function, the registration overrides
195+
any previously registered decoder for the corresponding CBOR tag.
196+
- `TokenUpdateHandler`, which is also accessible by passing the corresponding `TransactionType` to `getAccountTransactionHandler`.
197+
- Function `parseSimpleWallet` which parses a `SimpleWalletFormat` (also a subset of `GenesisFormat`), which can be used
198+
with `buildAccountSigner`
199+
- A new optional field `createPlt` to `AuthorizationsV1` which exposes the access structure for PLT creation.
200+
54201
## 9.2.0
55202

56203
### Fixed

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@concordium/web-sdk",
3-
"version": "10.0.0",
3+
"version": "10.0.1",
44
"license": "Apache-2.0",
55
"engines": {
66
"node": ">=16"

packages/sdk/src/grpc/translation.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,32 +2081,51 @@ function tokenEvent(event: GRPC_PLT.TokenEvent): TokenEvent {
20812081
}
20822082
}
20832083

2084+
function trCreatePltPayload(payload: GRPC_PLT.CreatePLT): PLT.CreatePLTPayload {
2085+
return {
2086+
tokenId: PLT.TokenId.fromProto(unwrap(payload.tokenId)),
2087+
decimals: payload.decimals,
2088+
moduleRef: PLT.TokenModuleReference.fromProto(unwrap(payload.tokenModule)),
2089+
initializationParameters: PLT.Cbor.fromProto(unwrap(payload.initializationParameters)),
2090+
};
2091+
}
2092+
20842093
export function blockItemSummary(summary: GRPC.BlockItemSummary): SDK.BlockItemSummary {
20852094
const base = {
20862095
index: unwrap(summary.index?.value),
20872096
energyCost: Energy.fromProto(unwrap(summary.energyCost)),
20882097
hash: TransactionHash.fromProto(unwrap(summary.hash)),
20892098
};
2090-
if (summary.details.oneofKind === 'accountTransaction') {
2091-
return trAccountTransactionSummary(summary.details.accountTransaction, base);
2092-
} else if (summary.details.oneofKind === 'accountCreation') {
2093-
return {
2094-
type: SDK.TransactionSummaryType.AccountCreation,
2095-
...base,
2096-
credentialType:
2097-
summary.details.accountCreation.credentialType === GRPC.CredentialType.INITIAL ? 'initial' : 'normal',
2098-
address: AccountAddress.fromProto(unwrap(summary.details.accountCreation.address)),
2099-
regId: unwrapValToHex(summary.details.accountCreation.regId),
2100-
};
2101-
} else if (summary.details.oneofKind === 'update') {
2102-
return {
2103-
type: SDK.TransactionSummaryType.UpdateTransaction,
2104-
...base,
2105-
effectiveTime: unwrap(summary.details.update.effectiveTime?.value),
2106-
payload: trUpdatePayload(summary.details.update.payload),
2107-
};
2108-
} else {
2109-
throw Error('Invalid BlockItemSummary encountered!');
2099+
switch (summary.details.oneofKind) {
2100+
case 'accountTransaction':
2101+
return trAccountTransactionSummary(summary.details.accountTransaction, base);
2102+
case 'accountCreation':
2103+
return {
2104+
type: SDK.TransactionSummaryType.AccountCreation,
2105+
...base,
2106+
credentialType:
2107+
summary.details.accountCreation.credentialType === GRPC.CredentialType.INITIAL
2108+
? 'initial'
2109+
: 'normal',
2110+
address: AccountAddress.fromProto(unwrap(summary.details.accountCreation.address)),
2111+
regId: unwrapValToHex(summary.details.accountCreation.regId),
2112+
};
2113+
case 'update':
2114+
return {
2115+
type: SDK.TransactionSummaryType.UpdateTransaction,
2116+
...base,
2117+
effectiveTime: unwrap(summary.details.update.effectiveTime?.value),
2118+
payload: trUpdatePayload(summary.details.update.payload),
2119+
};
2120+
case 'tokenCreation':
2121+
return {
2122+
type: SDK.TransactionSummaryType.TokenCreation,
2123+
...base,
2124+
payload: trCreatePltPayload(unwrap(summary.details.tokenCreation.createPlt)),
2125+
events: summary.details.tokenCreation.events.map(tokenEvent),
2126+
};
2127+
default:
2128+
throw Error('Invalid BlockItemSummary encountered!');
21102129
}
21112130
}
21122131

packages/sdk/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export enum TransactionSummaryType {
198198
CredentialDeploymentTransaction = 'credentialDeploymentTransaction',
199199
AccountCreation = 'accountCreation',
200200
UpdateTransaction = 'updateTransaction',
201+
TokenCreation = 'tokenCreation',
201202
}
202203

203204
interface BaseTransactionSummaryType {

packages/sdk/src/types/blockItemSummary.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isEqualContractAddress } from '../contractHelpers.js';
2+
import { CreatePLTPayload } from '../plt/types.js';
23
import { AccountTransactionType, TransactionStatusEnum, TransactionSummaryType } from '../types.js';
34
import { isDefined } from '../util.js';
45
import * as AccountAddress from './AccountAddress.js';
@@ -251,7 +252,17 @@ export interface UpdateSummary extends BaseBlockItemSummary {
251252
payload: UpdateInstructionPayload;
252253
}
253254

254-
export type BlockItemSummary = AccountTransactionSummary | AccountCreationSummary | UpdateSummary;
255+
export type TokenCreationSummary = {
256+
type: TransactionSummaryType.TokenCreation;
257+
payload: CreatePLTPayload;
258+
events: TokenEvent[];
259+
};
260+
261+
export type BlockItemSummary =
262+
| AccountTransactionSummary
263+
| AccountCreationSummary
264+
| UpdateSummary
265+
| TokenCreationSummary;
255266

256267
export interface BlockItemSummaryInBlock {
257268
blockHash: BlockHash.Type;

0 commit comments

Comments
 (0)