@apibara/starknet 2.0.0-beta.9 → 2.1.0-beta.2

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.
package/dist/index.mjs CHANGED
@@ -2,6 +2,8 @@ import { StreamConfig } from '@apibara/protocol';
2
2
  import { Schema } from '@effect/schema';
3
3
  import Long from 'long';
4
4
  import _m0 from 'protobufjs/minimal.js';
5
+ import { keccak } from '@scure/starknet';
6
+ import { parseBool, parseFelt252, parseU8, parseU16, parseU32, parseU64, parseU128, parseU256, parseContractAddress, ParseError, parseStruct, parseArray, parseSpan, parseOption, parseEmpty } from './parser.mjs';
5
7
 
6
8
  const _FieldElement = Schema.TemplateLiteral(
7
9
  Schema.Literal("0x"),
@@ -3265,13 +3267,14 @@ const DeployAccountTransactionReceipt$1 = {
3265
3267
  function createBaseEvent() {
3266
3268
  return {
3267
3269
  filterIds: [],
3268
- fromAddress: void 0,
3270
+ address: void 0,
3269
3271
  keys: [],
3270
3272
  data: [],
3271
3273
  eventIndex: 0,
3272
3274
  transactionIndex: 0,
3273
3275
  transactionHash: void 0,
3274
- transactionStatus: 0
3276
+ transactionStatus: 0,
3277
+ eventIndexInTransaction: 0
3275
3278
  };
3276
3279
  }
3277
3280
  const Event$1 = {
@@ -3283,8 +3286,8 @@ const Event$1 = {
3283
3286
  }
3284
3287
  writer.ldelim();
3285
3288
  }
3286
- if (message.fromAddress !== void 0) {
3287
- FieldElement.encode(message.fromAddress, writer.uint32(18).fork()).ldelim();
3289
+ if (message.address !== void 0) {
3290
+ FieldElement.encode(message.address, writer.uint32(18).fork()).ldelim();
3288
3291
  }
3289
3292
  if (message.keys !== void 0 && message.keys.length !== 0) {
3290
3293
  for (const v of message.keys) {
@@ -3308,6 +3311,9 @@ const Event$1 = {
3308
3311
  if (message.transactionStatus !== void 0 && message.transactionStatus !== 0) {
3309
3312
  writer.uint32(64).int32(message.transactionStatus);
3310
3313
  }
3314
+ if (message.eventIndexInTransaction !== void 0 && message.eventIndexInTransaction !== 0) {
3315
+ writer.uint32(72).uint32(message.eventIndexInTransaction);
3316
+ }
3311
3317
  return writer;
3312
3318
  },
3313
3319
  decode(input, length) {
@@ -3334,7 +3340,7 @@ const Event$1 = {
3334
3340
  if (tag !== 18) {
3335
3341
  break;
3336
3342
  }
3337
- message.fromAddress = FieldElement.decode(reader, reader.uint32());
3343
+ message.address = FieldElement.decode(reader, reader.uint32());
3338
3344
  continue;
3339
3345
  case 3:
3340
3346
  if (tag !== 26) {
@@ -3372,6 +3378,12 @@ const Event$1 = {
3372
3378
  }
3373
3379
  message.transactionStatus = reader.int32();
3374
3380
  continue;
3381
+ case 9:
3382
+ if (tag !== 72) {
3383
+ break;
3384
+ }
3385
+ message.eventIndexInTransaction = reader.uint32();
3386
+ continue;
3375
3387
  }
3376
3388
  if ((tag & 7) === 4 || tag === 0) {
3377
3389
  break;
@@ -3383,13 +3395,14 @@ const Event$1 = {
3383
3395
  fromJSON(object) {
3384
3396
  return {
3385
3397
  filterIds: globalThis.Array.isArray(object?.filterIds) ? object.filterIds.map((e) => globalThis.Number(e)) : [],
3386
- fromAddress: isSet$1(object.fromAddress) ? FieldElement.fromJSON(object.fromAddress) : void 0,
3398
+ address: isSet$1(object.address) ? FieldElement.fromJSON(object.address) : void 0,
3387
3399
  keys: globalThis.Array.isArray(object?.keys) ? object.keys.map((e) => FieldElement.fromJSON(e)) : [],
3388
3400
  data: globalThis.Array.isArray(object?.data) ? object.data.map((e) => FieldElement.fromJSON(e)) : [],
3389
3401
  eventIndex: isSet$1(object.eventIndex) ? globalThis.Number(object.eventIndex) : 0,
3390
3402
  transactionIndex: isSet$1(object.transactionIndex) ? globalThis.Number(object.transactionIndex) : 0,
3391
3403
  transactionHash: isSet$1(object.transactionHash) ? FieldElement.fromJSON(object.transactionHash) : void 0,
3392
- transactionStatus: isSet$1(object.transactionStatus) ? transactionStatusFromJSON(object.transactionStatus) : 0
3404
+ transactionStatus: isSet$1(object.transactionStatus) ? transactionStatusFromJSON(object.transactionStatus) : 0,
3405
+ eventIndexInTransaction: isSet$1(object.eventIndexInTransaction) ? globalThis.Number(object.eventIndexInTransaction) : 0
3393
3406
  };
3394
3407
  },
3395
3408
  toJSON(message) {
@@ -3397,8 +3410,8 @@ const Event$1 = {
3397
3410
  if (message.filterIds?.length) {
3398
3411
  obj.filterIds = message.filterIds.map((e) => Math.round(e));
3399
3412
  }
3400
- if (message.fromAddress !== void 0) {
3401
- obj.fromAddress = FieldElement.toJSON(message.fromAddress);
3413
+ if (message.address !== void 0) {
3414
+ obj.address = FieldElement.toJSON(message.address);
3402
3415
  }
3403
3416
  if (message.keys?.length) {
3404
3417
  obj.keys = message.keys.map((e) => FieldElement.toJSON(e));
@@ -3418,6 +3431,9 @@ const Event$1 = {
3418
3431
  if (message.transactionStatus !== void 0 && message.transactionStatus !== 0) {
3419
3432
  obj.transactionStatus = transactionStatusToJSON(message.transactionStatus);
3420
3433
  }
3434
+ if (message.eventIndexInTransaction !== void 0 && message.eventIndexInTransaction !== 0) {
3435
+ obj.eventIndexInTransaction = Math.round(message.eventIndexInTransaction);
3436
+ }
3421
3437
  return obj;
3422
3438
  },
3423
3439
  create(base) {
@@ -3426,13 +3442,14 @@ const Event$1 = {
3426
3442
  fromPartial(object) {
3427
3443
  const message = createBaseEvent();
3428
3444
  message.filterIds = object.filterIds?.map((e) => e) || [];
3429
- message.fromAddress = object.fromAddress !== void 0 && object.fromAddress !== null ? FieldElement.fromPartial(object.fromAddress) : void 0;
3445
+ message.address = object.address !== void 0 && object.address !== null ? FieldElement.fromPartial(object.address) : void 0;
3430
3446
  message.keys = object.keys?.map((e) => FieldElement.fromPartial(e)) || [];
3431
3447
  message.data = object.data?.map((e) => FieldElement.fromPartial(e)) || [];
3432
3448
  message.eventIndex = object.eventIndex ?? 0;
3433
3449
  message.transactionIndex = object.transactionIndex ?? 0;
3434
3450
  message.transactionHash = object.transactionHash !== void 0 && object.transactionHash !== null ? FieldElement.fromPartial(object.transactionHash) : void 0;
3435
3451
  message.transactionStatus = object.transactionStatus ?? 0;
3452
+ message.eventIndexInTransaction = object.eventIndexInTransaction ?? 0;
3436
3453
  return message;
3437
3454
  }
3438
3455
  };
@@ -3445,7 +3462,8 @@ function createBaseMessageToL1() {
3445
3462
  messageIndex: 0,
3446
3463
  transactionIndex: 0,
3447
3464
  transactionHash: void 0,
3448
- transactionStatus: 0
3465
+ transactionStatus: 0,
3466
+ messageIndexInTransaction: 0
3449
3467
  };
3450
3468
  }
3451
3469
  const MessageToL1$1 = {
@@ -3480,6 +3498,9 @@ const MessageToL1$1 = {
3480
3498
  if (message.transactionStatus !== void 0 && message.transactionStatus !== 0) {
3481
3499
  writer.uint32(64).int32(message.transactionStatus);
3482
3500
  }
3501
+ if (message.messageIndexInTransaction !== void 0 && message.messageIndexInTransaction !== 0) {
3502
+ writer.uint32(72).uint32(message.messageIndexInTransaction);
3503
+ }
3483
3504
  return writer;
3484
3505
  },
3485
3506
  decode(input, length) {
@@ -3544,6 +3565,12 @@ const MessageToL1$1 = {
3544
3565
  }
3545
3566
  message.transactionStatus = reader.int32();
3546
3567
  continue;
3568
+ case 9:
3569
+ if (tag !== 72) {
3570
+ break;
3571
+ }
3572
+ message.messageIndexInTransaction = reader.uint32();
3573
+ continue;
3547
3574
  }
3548
3575
  if ((tag & 7) === 4 || tag === 0) {
3549
3576
  break;
@@ -3561,7 +3588,8 @@ const MessageToL1$1 = {
3561
3588
  messageIndex: isSet$1(object.messageIndex) ? globalThis.Number(object.messageIndex) : 0,
3562
3589
  transactionIndex: isSet$1(object.transactionIndex) ? globalThis.Number(object.transactionIndex) : 0,
3563
3590
  transactionHash: isSet$1(object.transactionHash) ? FieldElement.fromJSON(object.transactionHash) : void 0,
3564
- transactionStatus: isSet$1(object.transactionStatus) ? transactionStatusFromJSON(object.transactionStatus) : 0
3591
+ transactionStatus: isSet$1(object.transactionStatus) ? transactionStatusFromJSON(object.transactionStatus) : 0,
3592
+ messageIndexInTransaction: isSet$1(object.messageIndexInTransaction) ? globalThis.Number(object.messageIndexInTransaction) : 0
3565
3593
  };
3566
3594
  },
3567
3595
  toJSON(message) {
@@ -3590,6 +3618,9 @@ const MessageToL1$1 = {
3590
3618
  if (message.transactionStatus !== void 0 && message.transactionStatus !== 0) {
3591
3619
  obj.transactionStatus = transactionStatusToJSON(message.transactionStatus);
3592
3620
  }
3621
+ if (message.messageIndexInTransaction !== void 0 && message.messageIndexInTransaction !== 0) {
3622
+ obj.messageIndexInTransaction = Math.round(message.messageIndexInTransaction);
3623
+ }
3593
3624
  return obj;
3594
3625
  },
3595
3626
  create(base) {
@@ -3605,6 +3636,7 @@ const MessageToL1$1 = {
3605
3636
  message.transactionIndex = object.transactionIndex ?? 0;
3606
3637
  message.transactionHash = object.transactionHash !== void 0 && object.transactionHash !== null ? FieldElement.fromPartial(object.transactionHash) : void 0;
3607
3638
  message.transactionStatus = object.transactionStatus ?? 0;
3639
+ message.messageIndexInTransaction = object.messageIndexInTransaction ?? 0;
3608
3640
  return message;
3609
3641
  }
3610
3642
  };
@@ -6772,12 +6804,12 @@ const U128 = Schema.transform(
6772
6804
  }
6773
6805
  );
6774
6806
  const ResourceBounds = Schema.Struct({
6775
- maxAmount: Schema.optional(Schema.BigIntFromSelf),
6776
- maxPricePerUnit: Schema.optional(U128)
6807
+ maxAmount: Schema.BigIntFromSelf,
6808
+ maxPricePerUnit: U128
6777
6809
  });
6778
6810
  const ResourceBoundsMapping = Schema.Struct({
6779
- l1Gas: Schema.optional(ResourceBounds),
6780
- l2Gas: Schema.optional(ResourceBounds)
6811
+ l1Gas: ResourceBounds,
6812
+ l2Gas: ResourceBounds
6781
6813
  });
6782
6814
  const DataAvailabilityMode = Schema.transform(
6783
6815
  Schema.Enums(DataAvailabilityMode$1),
@@ -6799,162 +6831,160 @@ const DataAvailabilityMode = Schema.transform(
6799
6831
  );
6800
6832
  const BlockHeader = Schema.Struct({
6801
6833
  blockHash: Schema.optional(FieldElement$1),
6802
- parentBlockHash: Schema.optional(FieldElement$1),
6834
+ parentBlockHash: FieldElement$1,
6803
6835
  blockNumber: Schema.BigIntFromSelf,
6804
- sequencerAddress: Schema.optional(FieldElement$1),
6836
+ sequencerAddress: FieldElement$1,
6805
6837
  newRoot: Schema.optional(FieldElement$1),
6806
- timestamp: Schema.optional(Schema.DateFromSelf),
6807
- starknetVersion: Schema.optional(Schema.String),
6808
- l1GasPrice: Schema.optional(ResourcePrice),
6809
- l1DataGasPrice: Schema.optional(ResourcePrice),
6810
- l1DataAvailabilityMode: Schema.optional(L1DataAvailabilityMode)
6838
+ timestamp: Schema.DateFromSelf,
6839
+ starknetVersion: Schema.String,
6840
+ l1GasPrice: ResourcePrice,
6841
+ l1DataGasPrice: ResourcePrice,
6842
+ l1DataAvailabilityMode: L1DataAvailabilityMode
6811
6843
  });
6812
6844
  const TransactionMeta = Schema.Struct({
6813
- transactionIndex: Schema.optional(Schema.Number),
6814
- transactionHash: Schema.optional(FieldElement$1),
6815
- transactionStatus: Schema.optional(TransactionStatus)
6845
+ transactionIndex: Schema.Number,
6846
+ transactionHash: FieldElement$1,
6847
+ transactionStatus: TransactionStatus
6816
6848
  });
6817
6849
  const InvokeTransactionV0 = Schema.Struct({
6818
6850
  _tag: tag("invokeV0"),
6819
6851
  invokeV0: Schema.Struct({
6820
- maxFee: Schema.optional(FieldElement$1),
6821
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6822
- contractAddress: Schema.optional(FieldElement$1),
6823
- entryPointSelector: Schema.optional(FieldElement$1),
6824
- calldata: Schema.optional(Schema.Array(FieldElement$1))
6852
+ maxFee: FieldElement$1,
6853
+ signature: Schema.Array(FieldElement$1),
6854
+ contractAddress: FieldElement$1,
6855
+ entryPointSelector: FieldElement$1,
6856
+ calldata: Schema.Array(FieldElement$1)
6825
6857
  })
6826
6858
  });
6827
6859
  const InvokeTransactionV1 = Schema.Struct({
6828
6860
  _tag: tag("invokeV1"),
6829
6861
  invokeV1: Schema.Struct({
6830
- senderAddress: Schema.optional(FieldElement$1),
6831
- calldata: Schema.optional(Schema.Array(FieldElement$1)),
6832
- maxFee: Schema.optional(FieldElement$1),
6833
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6834
- nonce: Schema.optional(FieldElement$1)
6862
+ senderAddress: FieldElement$1,
6863
+ calldata: Schema.Array(FieldElement$1),
6864
+ maxFee: FieldElement$1,
6865
+ signature: Schema.Array(FieldElement$1),
6866
+ nonce: FieldElement$1
6835
6867
  })
6836
6868
  });
6837
6869
  const InvokeTransactionV3 = Schema.Struct({
6838
6870
  _tag: tag("invokeV3"),
6839
6871
  invokeV3: Schema.Struct({
6840
- senderAddress: Schema.optional(FieldElement$1),
6841
- calldata: Schema.optional(Schema.Array(FieldElement$1)),
6842
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6843
- nonce: Schema.optional(FieldElement$1),
6844
- resourceBounds: Schema.optional(ResourceBoundsMapping),
6845
- tip: Schema.optional(Schema.BigIntFromSelf),
6846
- paymasterData: Schema.optional(Schema.Array(FieldElement$1)),
6847
- accountDeploymentData: Schema.optional(Schema.Array(FieldElement$1)),
6848
- nonceDataAvailabilityMode: Schema.optional(DataAvailabilityMode),
6849
- feeDataAvailabilityMode: Schema.optional(DataAvailabilityMode)
6872
+ senderAddress: FieldElement$1,
6873
+ calldata: Schema.Array(FieldElement$1),
6874
+ signature: Schema.Array(FieldElement$1),
6875
+ nonce: FieldElement$1,
6876
+ resourceBounds: ResourceBoundsMapping,
6877
+ tip: Schema.BigIntFromSelf,
6878
+ paymasterData: Schema.Array(FieldElement$1),
6879
+ accountDeploymentData: Schema.Array(FieldElement$1),
6880
+ nonceDataAvailabilityMode: DataAvailabilityMode,
6881
+ feeDataAvailabilityMode: DataAvailabilityMode
6850
6882
  })
6851
6883
  });
6852
6884
  const L1HandlerTransaction = Schema.Struct({
6853
6885
  _tag: tag("l1Handler"),
6854
6886
  l1Handler: Schema.Struct({
6855
- nonce: Schema.optional(Schema.BigIntFromSelf),
6856
- contractAddress: Schema.optional(FieldElement$1),
6857
- entryPointSelector: Schema.optional(FieldElement$1),
6858
- calldata: Schema.optional(Schema.Array(FieldElement$1))
6887
+ nonce: Schema.BigIntFromSelf,
6888
+ contractAddress: FieldElement$1,
6889
+ entryPointSelector: FieldElement$1,
6890
+ calldata: Schema.Array(FieldElement$1)
6859
6891
  })
6860
6892
  });
6861
6893
  const DeployTransaction = Schema.Struct({
6862
6894
  _tag: tag("deploy"),
6863
6895
  deploy: Schema.Struct({
6864
- contractAddressSalt: Schema.optional(FieldElement$1),
6865
- constructorCalldata: Schema.optional(Schema.Array(FieldElement$1)),
6866
- classHash: Schema.optional(FieldElement$1)
6896
+ contractAddressSalt: FieldElement$1,
6897
+ constructorCalldata: Schema.Array(FieldElement$1),
6898
+ classHash: FieldElement$1
6867
6899
  })
6868
6900
  });
6869
6901
  const DeclareTransactionV0 = Schema.Struct({
6870
6902
  _tag: tag("declareV0"),
6871
6903
  declareV0: Schema.Struct({
6872
- senderAddress: Schema.optional(FieldElement$1),
6873
- maxFee: Schema.optional(FieldElement$1),
6874
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6875
- classHash: Schema.optional(FieldElement$1)
6904
+ senderAddress: FieldElement$1,
6905
+ maxFee: FieldElement$1,
6906
+ signature: Schema.Array(FieldElement$1),
6907
+ classHash: FieldElement$1
6876
6908
  })
6877
6909
  });
6878
6910
  const DeclareTransactionV1 = Schema.Struct({
6879
6911
  _tag: tag("declareV1"),
6880
6912
  declareV1: Schema.Struct({
6881
- senderAddress: Schema.optional(FieldElement$1),
6882
- maxFee: Schema.optional(FieldElement$1),
6883
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6884
- nonce: Schema.optional(FieldElement$1),
6885
- classHash: Schema.optional(FieldElement$1)
6913
+ senderAddress: FieldElement$1,
6914
+ maxFee: FieldElement$1,
6915
+ signature: Schema.Array(FieldElement$1),
6916
+ nonce: FieldElement$1,
6917
+ classHash: FieldElement$1
6886
6918
  })
6887
6919
  });
6888
6920
  const DeclareTransactionV2 = Schema.Struct({
6889
6921
  _tag: tag("declareV2"),
6890
6922
  declareV2: Schema.Struct({
6891
- senderAddress: Schema.optional(FieldElement$1),
6892
- compiledClassHash: Schema.optional(FieldElement$1),
6893
- maxFee: Schema.optional(FieldElement$1),
6894
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6895
- nonce: Schema.optional(FieldElement$1),
6896
- classHash: Schema.optional(FieldElement$1)
6923
+ senderAddress: FieldElement$1,
6924
+ compiledClassHash: FieldElement$1,
6925
+ maxFee: FieldElement$1,
6926
+ signature: Schema.Array(FieldElement$1),
6927
+ nonce: FieldElement$1,
6928
+ classHash: FieldElement$1
6897
6929
  })
6898
6930
  });
6899
6931
  const DeclareTransactionV3 = Schema.Struct({
6900
6932
  _tag: tag("declareV3"),
6901
6933
  declareV3: Schema.Struct({
6902
- senderAddress: Schema.optional(FieldElement$1),
6903
- compiledClassHash: Schema.optional(FieldElement$1),
6904
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6905
- nonce: Schema.optional(FieldElement$1),
6906
- classHash: Schema.optional(FieldElement$1),
6907
- resourceBounds: Schema.optional(ResourceBoundsMapping),
6908
- tip: Schema.optional(Schema.BigIntFromSelf),
6909
- paymasterData: Schema.optional(Schema.Array(FieldElement$1)),
6910
- accountDeploymentData: Schema.optional(Schema.Array(FieldElement$1)),
6911
- nonceDataAvailabilityMode: Schema.optional(DataAvailabilityMode),
6912
- feeDataAvailabilityMode: Schema.optional(DataAvailabilityMode)
6934
+ senderAddress: FieldElement$1,
6935
+ compiledClassHash: FieldElement$1,
6936
+ signature: Schema.Array(FieldElement$1),
6937
+ nonce: FieldElement$1,
6938
+ classHash: FieldElement$1,
6939
+ resourceBounds: ResourceBoundsMapping,
6940
+ tip: Schema.BigIntFromSelf,
6941
+ paymasterData: Schema.Array(FieldElement$1),
6942
+ accountDeploymentData: Schema.Array(FieldElement$1),
6943
+ nonceDataAvailabilityMode: DataAvailabilityMode,
6944
+ feeDataAvailabilityMode: DataAvailabilityMode
6913
6945
  })
6914
6946
  });
6915
6947
  const DeployAccountTransactionV1 = Schema.Struct({
6916
6948
  _tag: tag("deployAccountV1"),
6917
6949
  deployAccountV1: Schema.Struct({
6918
- maxFee: Schema.optional(FieldElement$1),
6919
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6920
- nonce: Schema.optional(FieldElement$1),
6921
- contractAddressSalt: Schema.optional(FieldElement$1),
6922
- constructorCalldata: Schema.optional(Schema.Array(FieldElement$1)),
6923
- classHash: Schema.optional(FieldElement$1)
6950
+ maxFee: FieldElement$1,
6951
+ signature: Schema.Array(FieldElement$1),
6952
+ nonce: FieldElement$1,
6953
+ contractAddressSalt: FieldElement$1,
6954
+ constructorCalldata: Schema.Array(FieldElement$1),
6955
+ classHash: FieldElement$1
6924
6956
  })
6925
6957
  });
6926
6958
  const DeployAccountTransactionV3 = Schema.Struct({
6927
6959
  _tag: tag("deployAccountV3"),
6928
6960
  deployAccountV3: Schema.Struct({
6929
- signature: Schema.optional(Schema.Array(FieldElement$1)),
6930
- nonce: Schema.optional(FieldElement$1),
6931
- contractAddressSalt: Schema.optional(FieldElement$1),
6932
- constructorCalldata: Schema.optional(Schema.Array(FieldElement$1)),
6933
- classHash: Schema.optional(FieldElement$1),
6934
- resourceBounds: Schema.optional(ResourceBoundsMapping),
6935
- tip: Schema.optional(Schema.BigIntFromSelf),
6936
- paymasterData: Schema.optional(Schema.Array(FieldElement$1)),
6937
- nonceDataAvailabilityMode: Schema.optional(DataAvailabilityMode),
6938
- feeDataAvailabilityMode: Schema.optional(DataAvailabilityMode)
6961
+ signature: Schema.Array(FieldElement$1),
6962
+ nonce: FieldElement$1,
6963
+ contractAddressSalt: FieldElement$1,
6964
+ constructorCalldata: Schema.Array(FieldElement$1),
6965
+ classHash: FieldElement$1,
6966
+ resourceBounds: ResourceBoundsMapping,
6967
+ tip: Schema.BigIntFromSelf,
6968
+ paymasterData: Schema.Array(FieldElement$1),
6969
+ nonceDataAvailabilityMode: DataAvailabilityMode,
6970
+ feeDataAvailabilityMode: DataAvailabilityMode
6939
6971
  })
6940
6972
  });
6941
6973
  const Transaction = Schema.Struct({
6942
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
6943
- meta: Schema.optional(TransactionMeta),
6944
- transaction: Schema.optional(
6945
- Schema.Union(
6946
- InvokeTransactionV0,
6947
- InvokeTransactionV1,
6948
- InvokeTransactionV3,
6949
- L1HandlerTransaction,
6950
- DeployTransaction,
6951
- DeclareTransactionV0,
6952
- DeclareTransactionV1,
6953
- DeclareTransactionV2,
6954
- DeclareTransactionV3,
6955
- DeployAccountTransactionV1,
6956
- DeployAccountTransactionV3
6957
- )
6974
+ filterIds: Schema.Array(Schema.Number),
6975
+ meta: TransactionMeta,
6976
+ transaction: Schema.Union(
6977
+ InvokeTransactionV0,
6978
+ InvokeTransactionV1,
6979
+ InvokeTransactionV3,
6980
+ L1HandlerTransaction,
6981
+ DeployTransaction,
6982
+ DeclareTransactionV0,
6983
+ DeclareTransactionV1,
6984
+ DeclareTransactionV2,
6985
+ DeclareTransactionV3,
6986
+ DeployAccountTransactionV1,
6987
+ DeployAccountTransactionV3
6958
6988
  )
6959
6989
  });
6960
6990
  const PriceUnit = Schema.transform(
@@ -6976,11 +7006,11 @@ const PriceUnit = Schema.transform(
6976
7006
  }
6977
7007
  );
6978
7008
  const FeePayment = Schema.Struct({
6979
- amount: Schema.optional(FieldElement$1),
6980
- unit: Schema.optional(PriceUnit)
7009
+ amount: FieldElement$1,
7010
+ unit: PriceUnit
6981
7011
  });
6982
7012
  const ComputationResources = Schema.Struct({
6983
- steps: Schema.optional(Schema.BigIntFromSelf),
7013
+ steps: Schema.BigIntFromSelf,
6984
7014
  memoryHoles: Schema.optional(Schema.BigIntFromSelf),
6985
7015
  rangeCheckBuiltinApplications: Schema.optional(Schema.BigIntFromSelf),
6986
7016
  pedersenBuiltinApplications: Schema.optional(Schema.BigIntFromSelf),
@@ -6992,12 +7022,12 @@ const ComputationResources = Schema.Struct({
6992
7022
  segmentArenaBuiltin: Schema.optional(Schema.BigIntFromSelf)
6993
7023
  });
6994
7024
  const DataAvailabilityResources = Schema.Struct({
6995
- l1Gas: Schema.optional(Schema.BigIntFromSelf),
6996
- l1DataGas: Schema.optional(Schema.BigIntFromSelf)
7025
+ l1Gas: Schema.BigIntFromSelf,
7026
+ l1DataGas: Schema.BigIntFromSelf
6997
7027
  });
6998
7028
  const ExecutionResources = Schema.Struct({
6999
- computation: Schema.optional(ComputationResources),
7000
- dataAvailability: Schema.optional(DataAvailabilityResources)
7029
+ computation: ComputationResources,
7030
+ dataAvailability: DataAvailabilityResources
7001
7031
  });
7002
7032
  const ExecutionSucceeded = Schema.Struct({
7003
7033
  _tag: tag("succeeded"),
@@ -7010,13 +7040,11 @@ const ExecutionReverted = Schema.Struct({
7010
7040
  })
7011
7041
  });
7012
7042
  const TransactionReceiptMeta = Schema.Struct({
7013
- transactionIndex: Schema.optional(Schema.Number),
7014
- transactionHash: Schema.optional(FieldElement$1),
7015
- actualFee: Schema.optional(FeePayment),
7016
- executionResources: Schema.optional(ExecutionResources),
7017
- executionResult: Schema.optional(
7018
- Schema.Union(ExecutionSucceeded, ExecutionReverted)
7019
- )
7043
+ transactionIndex: Schema.Number,
7044
+ transactionHash: FieldElement$1,
7045
+ actualFee: FeePayment,
7046
+ executionResources: ExecutionResources,
7047
+ executionResult: Schema.Union(ExecutionSucceeded, ExecutionReverted)
7020
7048
  });
7021
7049
  const InvokeTransactionReceipt = Schema.Struct({
7022
7050
  _tag: tag("invoke"),
@@ -7025,7 +7053,7 @@ const InvokeTransactionReceipt = Schema.Struct({
7025
7053
  const L1HandlerTransactionReceipt = Schema.Struct({
7026
7054
  _tag: tag("l1Handler"),
7027
7055
  l1Handler: Schema.Struct({
7028
- messageHash: Schema.optional(Schema.Uint8ArrayFromSelf)
7056
+ messageHash: Schema.Uint8ArrayFromSelf
7029
7057
  })
7030
7058
  });
7031
7059
  const DeclareTransactionReceipt = Schema.Struct({
@@ -7035,56 +7063,56 @@ const DeclareTransactionReceipt = Schema.Struct({
7035
7063
  const DeployTransactionReceipt = Schema.Struct({
7036
7064
  _tag: tag("deploy"),
7037
7065
  deploy: Schema.Struct({
7038
- contractAddress: Schema.optional(FieldElement$1)
7066
+ contractAddress: FieldElement$1
7039
7067
  })
7040
7068
  });
7041
7069
  const DeployAccountTransactionReceipt = Schema.Struct({
7042
7070
  _tag: tag("deployAccount"),
7043
7071
  deployAccount: Schema.Struct({
7044
- contractAddress: Schema.optional(FieldElement$1)
7072
+ contractAddress: FieldElement$1
7045
7073
  })
7046
7074
  });
7047
7075
  const TransactionReceipt = Schema.Struct({
7048
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7049
- meta: Schema.optional(TransactionReceiptMeta),
7050
- receipt: Schema.optional(
7051
- Schema.Union(
7052
- InvokeTransactionReceipt,
7053
- L1HandlerTransactionReceipt,
7054
- DeclareTransactionReceipt,
7055
- DeployTransactionReceipt,
7056
- DeployAccountTransactionReceipt
7057
- )
7076
+ filterIds: Schema.Array(Schema.Number),
7077
+ meta: TransactionReceiptMeta,
7078
+ receipt: Schema.Union(
7079
+ InvokeTransactionReceipt,
7080
+ L1HandlerTransactionReceipt,
7081
+ DeclareTransactionReceipt,
7082
+ DeployTransactionReceipt,
7083
+ DeployAccountTransactionReceipt
7058
7084
  )
7059
7085
  });
7060
7086
  const Event = Schema.Struct({
7061
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7062
- address: Schema.optional(FieldElement$1),
7063
- keys: Schema.optional(Schema.Array(FieldElement$1)),
7064
- data: Schema.optional(Schema.Array(FieldElement$1)),
7065
- eventIndex: Schema.optional(Schema.Number),
7066
- transactionIndex: Schema.optional(Schema.Number),
7067
- transactionHash: Schema.optional(FieldElement$1),
7068
- transactionStatus: Schema.optional(TransactionStatus)
7087
+ filterIds: Schema.Array(Schema.Number),
7088
+ address: FieldElement$1,
7089
+ keys: Schema.Array(FieldElement$1),
7090
+ data: Schema.Array(FieldElement$1),
7091
+ eventIndex: Schema.Number,
7092
+ transactionIndex: Schema.Number,
7093
+ transactionHash: FieldElement$1,
7094
+ transactionStatus: TransactionStatus,
7095
+ eventIndexInTransaction: Schema.Number
7069
7096
  });
7070
7097
  const MessageToL1 = Schema.Struct({
7071
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7072
- fromAddress: Schema.optional(FieldElement$1),
7073
- toAddress: Schema.optional(FieldElement$1),
7074
- payload: Schema.optional(Schema.Array(FieldElement$1)),
7075
- messageIndex: Schema.optional(Schema.Number),
7076
- transactionIndex: Schema.optional(Schema.Number),
7077
- transactionHash: Schema.optional(FieldElement$1),
7078
- transactionStatus: Schema.optional(TransactionStatus)
7098
+ filterIds: Schema.Array(Schema.Number),
7099
+ fromAddress: FieldElement$1,
7100
+ toAddress: FieldElement$1,
7101
+ payload: Schema.Array(FieldElement$1),
7102
+ messageIndex: Schema.Number,
7103
+ transactionIndex: Schema.Number,
7104
+ transactionHash: FieldElement$1,
7105
+ transactionStatus: TransactionStatus,
7106
+ messageIndexInTransaction: Schema.Number
7079
7107
  });
7080
7108
  const StorageEntry = Schema.Struct({
7081
- key: Schema.optional(FieldElement$1),
7082
- value: Schema.optional(FieldElement$1)
7109
+ key: FieldElement$1,
7110
+ value: FieldElement$1
7083
7111
  });
7084
7112
  const StorageDiff = Schema.Struct({
7085
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7086
- contractAddress: Schema.optional(FieldElement$1),
7087
- storageEntries: Schema.optional(Schema.Array(StorageEntry))
7113
+ filterIds: Schema.Array(Schema.Number),
7114
+ contractAddress: FieldElement$1,
7115
+ storageEntries: Schema.Array(StorageEntry)
7088
7116
  });
7089
7117
  const DeclaredClass = Schema.Struct({
7090
7118
  _tag: tag("declaredClass"),
@@ -7108,18 +7136,16 @@ const DeployedContract = Schema.Struct({
7108
7136
  })
7109
7137
  });
7110
7138
  const ContractChange = Schema.Struct({
7111
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7112
- change: Schema.optional(
7113
- Schema.Union(DeclaredClass, ReplacedClass, DeployedContract)
7114
- )
7139
+ filterIds: Schema.Array(Schema.Number),
7140
+ change: Schema.Union(DeclaredClass, ReplacedClass, DeployedContract)
7115
7141
  });
7116
7142
  const NonceUpdate = Schema.Struct({
7117
- filterIds: Schema.optional(Schema.Array(Schema.Number)),
7118
- contractAddress: Schema.optional(FieldElement$1),
7119
- nonce: Schema.optional(FieldElement$1)
7143
+ filterIds: Schema.Array(Schema.Number),
7144
+ contractAddress: FieldElement$1,
7145
+ nonce: FieldElement$1
7120
7146
  });
7121
7147
  const Block = Schema.Struct({
7122
- header: Schema.optional(BlockHeader),
7148
+ header: BlockHeader,
7123
7149
  transactions: Schema.Array(Transaction),
7124
7150
  receipts: Schema.Array(TransactionReceipt),
7125
7151
  events: Schema.Array(Event),
@@ -7396,14 +7422,16 @@ function mergeHeaderFilter(a, b) {
7396
7422
  return "on_data";
7397
7423
  }
7398
7424
 
7399
- function getReceipt(transactionIndex, receipts) {
7425
+ function getReceipt(transactionIndex, params) {
7426
+ const receipts = "receipts" in params ? params.receipts : params;
7400
7427
  return binarySearch(
7401
7428
  transactionIndex,
7402
7429
  receipts,
7403
7430
  (receipt) => receipt.meta?.transactionIndex ?? 0
7404
7431
  );
7405
7432
  }
7406
- function getTransaction(transactionIndex, transactions) {
7433
+ function getTransaction(transactionIndex, params) {
7434
+ const transactions = "transactions" in params ? params.transactions : params;
7407
7435
  return binarySearch(
7408
7436
  transactionIndex,
7409
7437
  transactions,
@@ -7428,10 +7456,161 @@ function binarySearch(index, arr, getIndex) {
7428
7456
  }
7429
7457
  }
7430
7458
 
7459
+ function getBigIntSelector(name) {
7460
+ const asBytes = new TextEncoder().encode(name);
7461
+ return keccak(asBytes);
7462
+ }
7463
+ function getSelector(name) {
7464
+ const bn = getBigIntSelector(name);
7465
+ return `0x${bn.toString(16).padStart(64, "0")}`;
7466
+ }
7467
+ function getEventSelector(name) {
7468
+ const parts = name.split("::");
7469
+ return getSelector(parts[parts.length - 1]);
7470
+ }
7471
+ const PrimitiveTypeParsers = {
7472
+ "core::bool": parseBool,
7473
+ "core::felt252": parseFelt252,
7474
+ "core::integer::u8": parseU8,
7475
+ "core::integer::u16": parseU16,
7476
+ "core::integer::u32": parseU32,
7477
+ "core::integer::u64": parseU64,
7478
+ "core::integer::u128": parseU128,
7479
+ "core::integer::u256": parseU256,
7480
+ "core::starknet::contract_address::ContractAddress": parseContractAddress
7481
+ };
7482
+ function isPrimitiveType(type) {
7483
+ return type in PrimitiveTypeParsers;
7484
+ }
7485
+ function isArrayType(type) {
7486
+ return type.startsWith("core::array::Array::<") && type.endsWith(">");
7487
+ }
7488
+ function getArrayElementType(type) {
7489
+ return type.slice("core::array::Array::<".length, -1);
7490
+ }
7491
+ function isSpanType(type) {
7492
+ return type.startsWith("core::array::Span::<") && type.endsWith(">");
7493
+ }
7494
+ function getSpanType(type) {
7495
+ return type.slice("core::array::Span::<".length, -1);
7496
+ }
7497
+ function isOptionType(type) {
7498
+ return type.startsWith("core::option::Option::<") && type.endsWith(">");
7499
+ }
7500
+ function getOptionType(type) {
7501
+ return type.slice("core::option::Option::<".length, -1);
7502
+ }
7503
+ function isEmptyType(type) {
7504
+ return type === "()";
7505
+ }
7506
+
7507
+ class DecodeEventError extends Error {
7508
+ constructor(message) {
7509
+ super(message);
7510
+ this.name = "DecodeEventError";
7511
+ }
7512
+ }
7513
+ function decodeEvent(args) {
7514
+ const { abi, event, eventName, strict = true } = args;
7515
+ const eventAbi = abi.find(
7516
+ (item) => item.name === eventName && item.type === "event"
7517
+ );
7518
+ if (!eventAbi || eventAbi.type !== "event") {
7519
+ if (strict) {
7520
+ throw new DecodeEventError(`Event ${eventName} not found in ABI`);
7521
+ }
7522
+ return null;
7523
+ }
7524
+ if (eventAbi.kind === "enum") {
7525
+ throw new DecodeEventError("enum: not implemented");
7526
+ }
7527
+ const selector = BigInt(getEventSelector(eventName));
7528
+ if (event.keys && selector !== BigInt(event.keys[0]) || !event.keys) {
7529
+ if (strict) {
7530
+ throw new DecodeEventError(
7531
+ `Selector mismatch. Expected ${selector}, got ${event.keys?.[0]}`
7532
+ );
7533
+ }
7534
+ return null;
7535
+ }
7536
+ const keysAbi = eventAbi.members.filter((m) => m.kind === "key");
7537
+ const dataAbi = eventAbi.members.filter((m) => m.kind === "data");
7538
+ try {
7539
+ const keysParser = compileEventMembers(abi, keysAbi);
7540
+ const dataParser = compileEventMembers(abi, dataAbi);
7541
+ const keysWithoutSelector = event.keys?.slice(1) ?? [];
7542
+ const { out: decodedKeys } = keysParser(keysWithoutSelector, 0);
7543
+ const { out: decodedData } = dataParser(event.data ?? [], 0);
7544
+ const decoded = {
7545
+ ...decodedKeys,
7546
+ ...decodedData
7547
+ };
7548
+ return {
7549
+ ...event,
7550
+ eventName,
7551
+ args: decoded
7552
+ };
7553
+ } catch (error) {
7554
+ if (error instanceof DecodeEventError && !strict) {
7555
+ return null;
7556
+ }
7557
+ if (error instanceof ParseError && !strict) {
7558
+ return null;
7559
+ }
7560
+ throw error;
7561
+ }
7562
+ }
7563
+ function compileEventMembers(abi, members) {
7564
+ return compileStructParser(abi, members);
7565
+ }
7566
+ function compileTypeParser(abi, type) {
7567
+ if (isPrimitiveType(type)) {
7568
+ return PrimitiveTypeParsers[type];
7569
+ }
7570
+ if (isArrayType(type)) {
7571
+ const elementType = getArrayElementType(type);
7572
+ return parseArray(compileTypeParser(abi, elementType));
7573
+ }
7574
+ if (isSpanType(type)) {
7575
+ const elementType = getSpanType(type);
7576
+ return parseSpan(compileTypeParser(abi, elementType));
7577
+ }
7578
+ if (isOptionType(type)) {
7579
+ const elementType = getOptionType(type);
7580
+ return parseOption(compileTypeParser(abi, elementType));
7581
+ }
7582
+ if (isEmptyType(type)) {
7583
+ return parseEmpty;
7584
+ }
7585
+ const typeAbi = abi.find((item) => item.name === type);
7586
+ if (!typeAbi) {
7587
+ throw new DecodeEventError(`Type ${type} not found in ABI`);
7588
+ }
7589
+ switch (typeAbi.type) {
7590
+ case "struct": {
7591
+ return compileStructParser(abi, typeAbi.members);
7592
+ }
7593
+ case "enum":
7594
+ throw new DecodeEventError("enum: not implemented");
7595
+ default:
7596
+ throw new DecodeEventError(`Invalid type ${typeAbi.type}`);
7597
+ }
7598
+ }
7599
+ function compileStructParser(abi, members) {
7600
+ const parsers = {};
7601
+ for (const [index, member] of members.entries()) {
7602
+ parsers[member.name] = {
7603
+ index,
7604
+ parser: compileTypeParser(abi, member.type)
7605
+ };
7606
+ }
7607
+ return parseStruct(parsers);
7608
+ }
7609
+
7431
7610
  const StarknetStream = new StreamConfig(
7432
7611
  FilterFromBytes,
7433
7612
  BlockFromBytes,
7434
7613
  mergeFilter
7435
7614
  );
7436
7615
 
7437
- export { Block, BlockFromBytes, BlockHeader, ComputationResources, ContractChange, ContractChangeFilter, DataAvailabilityMode, DataAvailabilityResources, DeclareTransactionReceipt, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeclareTransactionV3, DeclareV0TransactionFilter, DeclareV1TransactionFilter, DeclareV2TransactionFilter, DeclareV3TransactionFilter, DeclaredClass, DeclaredClassFilter, DeployAccountTransactionReceipt, DeployAccountTransactionV1, DeployAccountTransactionV3, DeployAccountV1TransactionFilter, DeployAccountV3TransactionFilter, DeployTransaction, DeployTransactionFilter, DeployTransactionReceipt, DeployedContract, DeployedContractFilter, Event, EventFilter, ExecutionResources, ExecutionReverted, ExecutionSucceeded, FeePayment, FieldElement$1 as FieldElement, FieldElementProto, Filter, FilterFromBytes, HeaderFilter, InvokeTransactionReceipt, InvokeTransactionV0, InvokeTransactionV0Filter, InvokeTransactionV1, InvokeTransactionV1Filter, InvokeTransactionV3, InvokeTransactionV3Filter, Key, L1DataAvailabilityMode, L1HandlerTransaction, L1HandlerTransactionFilter, L1HandlerTransactionReceipt, MessageToL1, MessageToL1Filter, NonceUpdate, NonceUpdateFilter, PriceUnit, ReplacedClass, ReplacedClassFilter, ResourceBounds, ResourceBoundsMapping, ResourcePrice, StarknetStream, StorageDiff, StorageDiffFilter, StorageEntry, Transaction, TransactionFilter, TransactionMeta, TransactionReceipt, TransactionReceiptMeta, TransactionStatus, TransactionStatusFilter, U128, feltFromProto, feltToProto, filterFromBytes, filterFromProto, filterToBytes, filterToProto, getReceipt, getTransaction, mergeFilter, index as proto };
7616
+ export { Block, BlockFromBytes, BlockHeader, ComputationResources, ContractChange, ContractChangeFilter, DataAvailabilityMode, DataAvailabilityResources, DeclareTransactionReceipt, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeclareTransactionV3, DeclareV0TransactionFilter, DeclareV1TransactionFilter, DeclareV2TransactionFilter, DeclareV3TransactionFilter, DeclaredClass, DeclaredClassFilter, DecodeEventError, DeployAccountTransactionReceipt, DeployAccountTransactionV1, DeployAccountTransactionV3, DeployAccountV1TransactionFilter, DeployAccountV3TransactionFilter, DeployTransaction, DeployTransactionFilter, DeployTransactionReceipt, DeployedContract, DeployedContractFilter, Event, EventFilter, ExecutionResources, ExecutionReverted, ExecutionSucceeded, FeePayment, FieldElement$1 as FieldElement, FieldElementProto, Filter, FilterFromBytes, HeaderFilter, InvokeTransactionReceipt, InvokeTransactionV0, InvokeTransactionV0Filter, InvokeTransactionV1, InvokeTransactionV1Filter, InvokeTransactionV3, InvokeTransactionV3Filter, Key, L1DataAvailabilityMode, L1HandlerTransaction, L1HandlerTransactionFilter, L1HandlerTransactionReceipt, MessageToL1, MessageToL1Filter, NonceUpdate, NonceUpdateFilter, PriceUnit, ReplacedClass, ReplacedClassFilter, ResourceBounds, ResourceBoundsMapping, ResourcePrice, StarknetStream, StorageDiff, StorageDiffFilter, StorageEntry, Transaction, TransactionFilter, TransactionMeta, TransactionReceipt, TransactionReceiptMeta, TransactionStatus, TransactionStatusFilter, U128, decodeEvent, feltFromProto, feltToProto, filterFromBytes, filterFromProto, filterToBytes, filterToProto, getBigIntSelector, getEventSelector, getReceipt, getSelector, getTransaction, mergeFilter, index as proto };