@alephium/web3 0.8.2-test.3 → 0.9.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -334,6 +334,7 @@ export interface CompileContractResult {
334
334
  functions: FunctionSig[];
335
335
  events: EventSig[];
336
336
  warnings: string[];
337
+ stdInterfaceId?: string;
337
338
  }
338
339
  export interface CompileProjectResult {
339
340
  contracts: CompileContractResult[];
@@ -462,7 +463,7 @@ export interface Destination {
462
463
  /** @format hex-string */
463
464
  message?: string;
464
465
  }
465
- export declare type DiscoveryAction = Reachable | Unreachable;
466
+ export type DiscoveryAction = Reachable | Unreachable;
466
467
  export interface EventSig {
467
468
  name: string;
468
469
  fieldNames: string[];
@@ -540,7 +541,7 @@ export interface MinerAddresses {
540
541
  export interface MinerAddressesInfo {
541
542
  addresses: AddressInfo[];
542
543
  }
543
- export declare type MisbehaviorAction = Ban | Unban;
544
+ export type MisbehaviorAction = Ban | Unban;
544
545
  export interface MultipleCallContract {
545
546
  calls: CallContract[];
546
547
  }
@@ -564,7 +565,7 @@ export interface NotFound {
564
565
  detail: string;
565
566
  resource: string;
566
567
  }
567
- export declare type Output = AssetOutput | ContractOutput;
568
+ export type Output = AssetOutput | ContractOutput;
568
569
  export interface OutputRef {
569
570
  /** @format int32 */
570
571
  hint: number;
@@ -586,7 +587,7 @@ export interface PeerMisbehavior {
586
587
  peer: string;
587
588
  status: PeerStatus;
588
589
  }
589
- export declare type PeerStatus = Banned | Penalty;
590
+ export type PeerStatus = Banned | Penalty;
590
591
  export interface Penalty {
591
592
  /** @format int32 */
592
593
  value: number;
@@ -758,7 +759,7 @@ export interface TransferResults {
758
759
  export interface TxNotFound {
759
760
  type: string;
760
761
  }
761
- export declare type TxStatus = Confirmed | MemPooled | TxNotFound;
762
+ export type TxStatus = Confirmed | MemPooled | TxNotFound;
762
763
  export interface UTXO {
763
764
  ref: OutputRef;
764
765
  /** @format uint256 */
@@ -798,7 +799,7 @@ export interface UnsignedTx {
798
799
  inputs: AssetInput[];
799
800
  fixedOutputs: FixedAssetOutput[];
800
801
  }
801
- export declare type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
802
+ export type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
802
803
  export interface ValAddress {
803
804
  /** @format address */
804
805
  value: string;
@@ -868,8 +869,8 @@ export interface WalletUnlock {
868
869
  mnemonicPassphrase?: string;
869
870
  }
870
871
  import 'cross-fetch/polyfill';
871
- export declare type QueryParamsType = Record<string | number, any>;
872
- export declare type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
872
+ export type QueryParamsType = Record<string | number, any>;
873
+ export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
873
874
  export interface FullRequestParams extends Omit<RequestInit, 'body'> {
874
875
  /** set parameter to `true` for call `securityWorker` for this request */
875
876
  secure?: boolean;
@@ -888,7 +889,7 @@ export interface FullRequestParams extends Omit<RequestInit, 'body'> {
888
889
  /** request cancellation token */
889
890
  cancelToken?: CancelToken;
890
891
  }
891
- export declare type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
892
+ export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
892
893
  export interface ApiConfig<SecurityDataType = unknown> {
893
894
  baseUrl?: string;
894
895
  baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
@@ -899,7 +900,7 @@ export interface HttpResponse<D extends unknown, E extends unknown = unknown> ex
899
900
  data: D;
900
901
  error: E;
901
902
  }
902
- declare type CancelToken = Symbol | string | number;
903
+ type CancelToken = Symbol | string | number;
903
904
  export declare enum ContentType {
904
905
  Json = "application/json",
905
906
  FormData = "multipart/form-data",
@@ -928,7 +929,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
928
929
  }
929
930
  /**
930
931
  * @title Alephium API
931
- * @version 2.0.1
932
+ * @version 2.1.0
932
933
  * @baseUrl ../
933
934
  */
934
935
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 2.0.1
154
+ * @version 2.1.0
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -156,7 +156,7 @@ export interface NotFound {
156
156
  detail: string;
157
157
  resource: string;
158
158
  }
159
- export declare type Output = AssetOutput | ContractOutput;
159
+ export type Output = AssetOutput | ContractOutput;
160
160
  export interface OutputRef {
161
161
  /** @format int32 */
162
162
  hint: number;
@@ -261,11 +261,11 @@ export interface Transaction {
261
261
  scriptExecutionOk: boolean;
262
262
  coinbase: boolean;
263
263
  }
264
- export declare type TransactionLike = AcceptedTransaction | PendingTransaction;
264
+ export type TransactionLike = AcceptedTransaction | PendingTransaction;
265
265
  export interface Unauthorized {
266
266
  detail: string;
267
267
  }
268
- export declare type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
268
+ export type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
269
269
  export interface ValAddress {
270
270
  /** @format address */
271
271
  value: string;
@@ -295,8 +295,8 @@ export interface ValU256 {
295
295
  type: string;
296
296
  }
297
297
  import 'cross-fetch/polyfill';
298
- export declare type QueryParamsType = Record<string | number, any>;
299
- export declare type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
298
+ export type QueryParamsType = Record<string | number, any>;
299
+ export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
300
300
  export interface FullRequestParams extends Omit<RequestInit, 'body'> {
301
301
  /** set parameter to `true` for call `securityWorker` for this request */
302
302
  secure?: boolean;
@@ -315,7 +315,7 @@ export interface FullRequestParams extends Omit<RequestInit, 'body'> {
315
315
  /** request cancellation token */
316
316
  cancelToken?: CancelToken;
317
317
  }
318
- export declare type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
318
+ export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
319
319
  export interface ApiConfig<SecurityDataType = unknown> {
320
320
  baseUrl?: string;
321
321
  baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
@@ -326,7 +326,7 @@ export interface HttpResponse<D extends unknown, E extends unknown = unknown> ex
326
326
  data: D;
327
327
  error: E;
328
328
  }
329
- declare type CancelToken = Symbol | string | number;
329
+ type CancelToken = Symbol | string | number;
330
330
  export declare enum ContentType {
331
331
  Json = "application/json",
332
332
  FormData = "multipart/form-data",
@@ -1,7 +1,20 @@
1
1
  import { ApiRequestArguments, ApiRequestHandler, TokenMetaData } from './types';
2
2
  import { Api as NodeApi } from './api-alephium';
3
3
  import { HexString } from '../contract';
4
- export declare class NodeProvider {
4
+ interface NodeProviderApis {
5
+ wallets: NodeApi<string>['wallets'];
6
+ infos: NodeApi<string>['infos'];
7
+ blockflow: NodeApi<string>['blockflow'];
8
+ addresses: NodeApi<string>['addresses'];
9
+ transactions: NodeApi<string>['transactions'];
10
+ mempool: NodeApi<string>['mempool'];
11
+ contracts: NodeApi<string>['contracts'];
12
+ multisig: NodeApi<string>['multisig'];
13
+ utils: NodeApi<string>['utils'];
14
+ miners: NodeApi<string>['miners'];
15
+ events: NodeApi<string>['events'];
16
+ }
17
+ export declare class NodeProvider implements NodeProviderApis {
5
18
  readonly wallets: NodeApi<string>['wallets'];
6
19
  readonly infos: NodeApi<string>['infos'];
7
20
  readonly blockflow: NodeApi<string>['blockflow'];
@@ -20,4 +33,6 @@ export declare class NodeProvider {
20
33
  static Proxy(nodeProvider: NodeProvider): NodeProvider;
21
34
  static Remote(handler: ApiRequestHandler): NodeProvider;
22
35
  fetchStdTokenMetaData: (tokenId: HexString) => Promise<TokenMetaData>;
36
+ guessStdInterfaceId: (tokenId: HexString) => Promise<HexString | undefined>;
23
37
  }
38
+ export {};
@@ -39,15 +39,35 @@ class NodeProvider {
39
39
  };
40
40
  // Only use this when the token is following the standard token interface
41
41
  this.fetchStdTokenMetaData = async (tokenId) => {
42
- return fetchStdTokenMetaData(this.contracts, tokenId);
42
+ const group = 0;
43
+ const address = (0, utils_2.addressFromTokenId)(tokenId);
44
+ const calls = Array.from([0, 1, 2, 3], (index) => ({ methodIndex: index, group: group, address: address }));
45
+ const result = await this.contracts.postContractsMulticallContract({
46
+ calls: calls
47
+ });
48
+ return {
49
+ symbol: result.results[0].returns[0].value,
50
+ name: result.results[1].returns[0].value,
51
+ decimals: Number(result.results[2].returns[0].value),
52
+ totalSupply: BigInt(result.results[3].returns[0].value)
53
+ };
54
+ };
55
+ this.guessStdInterfaceId = async (tokenId) => {
56
+ const address = (0, utils_2.addressFromTokenId)(tokenId);
57
+ const group = (0, utils_2.groupOfAddress)(address);
58
+ const rawState = await this.contracts.getContractsAddressState((0, utils_2.addressFromTokenId)(tokenId), { group });
59
+ const lastImmField = rawState.immFields.slice(-1).pop()?.value;
60
+ const interfaceIdPrefix = '414c5048'; // the hex of 'ALPH'
61
+ if (typeof lastImmField === 'string' && lastImmField.startsWith(interfaceIdPrefix)) {
62
+ return lastImmField.slice(8);
63
+ }
64
+ else {
65
+ return undefined;
66
+ }
43
67
  };
44
68
  let nodeApi;
45
69
  if (typeof param0 === 'string') {
46
- const api = initializeNodeApi(param0, apiKey, customFetch);
47
- nodeApi = {
48
- ...api,
49
- fetchStdTokenMetaData: async (tokenId) => fetchStdTokenMetaData(api.contracts, tokenId)
50
- };
70
+ nodeApi = initializeNodeApi(param0, apiKey, customFetch);
51
71
  }
52
72
  else if (typeof param0 === 'function') {
53
73
  nodeApi = new NodeProvider('https://1.2.3.4:0');
@@ -77,17 +97,3 @@ class NodeProvider {
77
97
  }
78
98
  }
79
99
  exports.NodeProvider = NodeProvider;
80
- async function fetchStdTokenMetaData(contractAPI, tokenId) {
81
- const group = 0;
82
- const address = (0, utils_2.addressFromTokenId)(tokenId);
83
- const calls = Array.from([0, 1, 2, 3], (index) => ({ methodIndex: index, group: group, address: address }));
84
- const result = await contractAPI.postContractsMulticallContract({
85
- calls: calls
86
- });
87
- return {
88
- symbol: result.results[0].returns[0].value,
89
- name: result.results[1].returns[0].value,
90
- decimals: Number(result.results[2].returns[0].value),
91
- totalSupply: BigInt(result.results[3].returns[0].value)
92
- };
93
- }
@@ -1,7 +1,7 @@
1
1
  import * as node from './api-alephium';
2
- export declare type Number256 = bigint | string;
3
- export declare type Val = Number256 | boolean | string | Val[];
4
- export declare type NamedVals = Record<string, Val>;
2
+ export type Number256 = bigint | string;
3
+ export type Val = Number256 | boolean | string | Val[];
4
+ export type NamedVals = Record<string, Val>;
5
5
  export interface Token {
6
6
  id: string;
7
7
  amount: Number256;
@@ -18,7 +18,7 @@ export declare function toApiByteVec(v: Val): string;
18
18
  export declare function toApiAddress(v: Val): string;
19
19
  export declare function toApiArray(tpe: string, v: Val): node.Val;
20
20
  export declare function toApiVal(v: Val, tpe: string): node.Val;
21
- export declare function fromApiVals(vals: node.Val[], names: string[], types: string[], optionalNames?: string[], optionalTypes?: string[]): NamedVals;
21
+ export declare function fromApiVals(vals: node.Val[], names: string[], types: string[], systemEvent?: boolean): NamedVals;
22
22
  export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
23
23
  export declare function fromApiVal(v: node.Val, tpe: string): Val;
24
24
  export declare function typeLength(tpe: string): number;
@@ -27,7 +27,7 @@ export interface ApiRequestArguments {
27
27
  method: string;
28
28
  params: any[];
29
29
  }
30
- export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
30
+ export type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
31
31
  export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
32
32
  export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
33
33
  export interface TokenMetaData {
@@ -137,7 +137,7 @@ function toApiVal(v, tpe) {
137
137
  }
138
138
  }
139
139
  exports.toApiVal = toApiVal;
140
- function _fromApiVal(vals, valIndex, tpe) {
140
+ function _fromApiVal(vals, valIndex, tpe, systemEvent = false) {
141
141
  if (vals.length === 0) {
142
142
  throw new Error('Not enough Vals');
143
143
  }
@@ -148,7 +148,7 @@ function _fromApiVal(vals, valIndex, tpe) {
148
148
  else if ((tpe === 'U256' || tpe === 'I256') && firstVal.type === tpe) {
149
149
  return [fromApiNumber256(firstVal.value), valIndex + 1];
150
150
  }
151
- else if ((tpe === 'ByteVec' || tpe === 'Address') && firstVal.type === tpe) {
151
+ else if ((tpe === 'ByteVec' || tpe === 'Address') && (firstVal.type === tpe || systemEvent)) {
152
152
  return [firstVal.value, valIndex + 1];
153
153
  }
154
154
  else {
@@ -165,20 +165,16 @@ function _fromApiVal(vals, valIndex, tpe) {
165
165
  }
166
166
  }
167
167
  }
168
- function fromApiVals(vals, names, types, optionalNames = [], optionalTypes = []) {
168
+ function fromApiVals(vals, names, types, systemEvent = false) {
169
169
  let valIndex = 0;
170
170
  const result = {};
171
171
  types.forEach((currentType, index) => {
172
172
  const currentName = names[`${index}`];
173
- const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
173
+ const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType, systemEvent);
174
174
  valIndex = nextIndex;
175
175
  result[`${currentName}`] = val;
176
176
  });
177
- if (valIndex === vals.length) {
178
- return result;
179
- }
180
- const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes);
181
- return { ...result, ...optionalFields };
177
+ return result;
182
178
  }
183
179
  exports.fromApiVals = fromApiVals;
184
180
  function fromApiArray(vals, types) {
@@ -2,19 +2,20 @@ import { NamedVals, node, Number256, Token } from '../api';
2
2
  import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address } from '../signer';
3
3
  import { SubscribeOptions, Optional } from '../utils';
4
4
  import { EventSubscription } from './events';
5
- export declare type FieldsSig = node.FieldsSig;
6
- export declare type EventSig = node.EventSig;
7
- export declare type FunctionSig = node.FunctionSig;
8
- export declare type Fields = NamedVals;
9
- export declare type Arguments = NamedVals;
10
- export declare type HexString = string;
5
+ export type FieldsSig = node.FieldsSig;
6
+ export type EventSig = node.EventSig;
7
+ export type FunctionSig = node.FunctionSig;
8
+ export type Fields = NamedVals;
9
+ export type Arguments = NamedVals;
10
+ export type HexString = string;
11
+ export declare const StdIdFieldName = "__stdInterfaceId";
11
12
  declare enum SourceKind {
12
13
  Contract = 0,
13
14
  Script = 1,
14
15
  AbstractContract = 2,
15
16
  Interface = 3
16
17
  }
17
- export declare type CompilerOptions = node.CompilerOptions & {
18
+ export type CompilerOptions = node.CompilerOptions & {
18
19
  errorOnWarnings: boolean;
19
20
  };
20
21
  export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
@@ -41,7 +42,7 @@ declare class Compiled<T extends Artifact> {
41
42
  warnings: string[];
42
43
  constructor(sourceInfo: SourceInfo, artifact: T, warnings: string[]);
43
44
  }
44
- declare type CodeInfo = {
45
+ type CodeInfo = {
45
46
  sourceFile: string;
46
47
  sourceCodeHash: string;
47
48
  bytecodeDebugPatch: string;
@@ -105,9 +106,10 @@ export declare class Contract extends Artifact {
105
106
  readonly codeHash: string;
106
107
  readonly fieldsSig: FieldsSig;
107
108
  readonly eventsSig: EventSig[];
109
+ readonly stdInterfaceId?: HexString;
108
110
  readonly bytecodeDebug: string;
109
111
  readonly codeHashDebug: string;
110
- constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
112
+ constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], stdInterfaceId?: HexString);
111
113
  static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
112
114
  static fromCompileResult(result: node.CompileContractResult): Contract;
113
115
  static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
@@ -123,9 +125,9 @@ export declare class Contract extends Artifact {
123
125
  fromApiContractState(state: node.ContractState): ContractState<Fields>;
124
126
  static fromApiContractState(state: node.ContractState): ContractState;
125
127
  static ContractCreatedEventIndex: number;
126
- static ContractCreatedEvent: SystemEventSig;
128
+ static ContractCreatedEvent: EventSig;
127
129
  static ContractDestroyedEventIndex: number;
128
- static ContractDestroyedEvent: SystemEventSig;
130
+ static ContractDestroyedEvent: EventSig;
129
131
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string): ContractEvent;
130
132
  fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
131
133
  txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
@@ -185,7 +187,7 @@ export interface ContractEvent<T extends Fields = Fields> {
185
187
  name: string;
186
188
  fields: T;
187
189
  }
188
- export declare type DebugMessage = node.DebugMessage;
190
+ export type DebugMessage = node.DebugMessage;
189
191
  export interface TestContractResult<R> {
190
192
  contractId: string;
191
193
  contractAddress: string;
@@ -218,7 +220,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
218
220
  gasAmount?: number;
219
221
  gasPrice?: Number256;
220
222
  }
221
- export declare type DeployContractResult<T> = SignDeployContractTxResult & {
223
+ export type DeployContractResult<T> = SignDeployContractTxResult & {
222
224
  instance: T;
223
225
  };
224
226
  export declare abstract class ContractFactory<I, F extends Fields = Fields> {
@@ -260,20 +262,22 @@ export interface CallContractResult<R> {
260
262
  }
261
263
  export declare const CreateContractEventAddress: string;
262
264
  export declare const DestroyContractEventAddress: string;
263
- export interface SystemEventSig extends EventSig {
264
- optionalFieldNames?: string[];
265
- optionalFieldTypes?: string[];
266
- }
267
- export declare type ContractCreatedEvent = ContractEvent<{
265
+ export type ContractCreatedEventFields = {
268
266
  address: Address;
269
267
  parentAddress?: Address;
270
- }>;
271
- export declare type ContractDestroyedEvent = ContractEvent<{
268
+ stdInterfaceIdGuessed?: HexString;
269
+ };
270
+ export type ContractDestroyedEventFields = {
272
271
  address: Address;
273
- }>;
272
+ };
273
+ export type ContractCreatedEvent = ContractEvent<ContractCreatedEventFields>;
274
+ export type ContractDestroyedEvent = ContractEvent<ContractDestroyedEventFields>;
274
275
  export declare function decodeContractCreatedEvent(event: node.ContractEvent): Omit<ContractCreatedEvent, 'contractAddress'>;
275
276
  export declare function decodeContractDestroyedEvent(event: node.ContractEvent): Omit<ContractDestroyedEvent, 'contractAddress'>;
276
277
  export declare function subscribeEventsFromContract<T extends Fields, M extends ContractEvent<T>>(options: SubscribeOptions<M>, address: string, eventIndex: number, decodeFunc: (event: node.ContractEvent) => M, fromCount?: number): EventSubscription;
278
+ export declare function addStdIdToFields<F extends Fields>(contract: Contract, fields: F): F | (F & {
279
+ __stdInterfaceId: HexString;
280
+ });
277
281
  export declare function testMethod<I, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A>, 'testArgs' | 'initialFields'>): Promise<TestContractResult<R>>;
278
282
  export declare abstract class ContractInstance {
279
283
  readonly address: Address;