@aeternity/aepp-sdk 14.1.1 → 15.0.0

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.
Files changed (82) hide show
  1. package/dist/aepp-sdk.browser-script.cjs +1 -1
  2. package/dist/aepp-sdk.browser-script.cjs.map +1 -1
  3. package/dist/aepp-sdk.browser.cjs +1 -1
  4. package/dist/aepp-sdk.browser.cjs.map +1 -1
  5. package/dist/aepp-sdk.cjs +3068 -502
  6. package/dist/aepp-sdk.cjs.map +1 -1
  7. package/es/account/Base.d.ts +6 -1
  8. package/es/account/Base.js.map +1 -1
  9. package/es/account/Generalized.d.ts +1 -1
  10. package/es/account/Generalized.js +7 -1
  11. package/es/account/Generalized.js.map +1 -1
  12. package/es/apis/node/models/index.d.ts +405 -79
  13. package/es/apis/node/models/index.js.map +1 -1
  14. package/es/apis/node/models/mappers.d.ts +54 -4
  15. package/es/apis/node/models/mappers.js +1910 -500
  16. package/es/apis/node/models/mappers.js.map +1 -1
  17. package/es/apis/node/node.d.ts +28 -6
  18. package/es/apis/node/node.js +276 -5
  19. package/es/apis/node/node.js.map +1 -1
  20. package/es/channel/Contract.d.ts +5 -0
  21. package/es/channel/Contract.js +8 -2
  22. package/es/channel/Contract.js.map +1 -1
  23. package/es/channel/handlers.js +3 -3
  24. package/es/channel/handlers.js.map +1 -1
  25. package/es/contract/ga.d.ts +5 -2
  26. package/es/contract/ga.js +53 -21
  27. package/es/contract/ga.js.map +1 -1
  28. package/es/index-browser.d.ts +3 -1
  29. package/es/index-browser.js +2 -1
  30. package/es/index-browser.js.map +1 -1
  31. package/es/tx/builder/constants.d.ts +12 -2
  32. package/es/tx/builder/constants.js +11 -1
  33. package/es/tx/builder/constants.js.map +1 -1
  34. package/es/tx/builder/entry/index.js +6 -0
  35. package/es/tx/builder/entry/index.js.map +1 -1
  36. package/es/tx/builder/entry/schema.d.ts +10 -10
  37. package/es/tx/builder/field-types/ct-version.d.ts +14 -0
  38. package/es/tx/builder/field-types/ct-version.js +14 -0
  39. package/es/tx/builder/field-types/ct-version.js.map +1 -1
  40. package/es/tx/builder/field-types/fee.d.ts +9 -7
  41. package/es/tx/builder/field-types/fee.js +75 -66
  42. package/es/tx/builder/field-types/fee.js.map +1 -1
  43. package/es/tx/builder/field-types/gas-limit.d.ts +5 -3
  44. package/es/tx/builder/field-types/gas-limit.js +25 -14
  45. package/es/tx/builder/field-types/gas-limit.js.map +1 -1
  46. package/es/tx/builder/field-types/gas-price.d.ts +6 -4
  47. package/es/tx/builder/field-types/gas-price.js +87 -21
  48. package/es/tx/builder/field-types/gas-price.js.map +1 -1
  49. package/es/tx/builder/field-types/interface.d.ts +20 -0
  50. package/es/tx/builder/field-types/interface.js +17 -1
  51. package/es/tx/builder/field-types/interface.js.map +1 -1
  52. package/es/tx/builder/field-types/name-fee.d.ts +3 -2
  53. package/es/tx/builder/field-types/name-fee.js +6 -0
  54. package/es/tx/builder/field-types/name-fee.js.map +1 -1
  55. package/es/tx/builder/field-types/pointers.d.ts +2 -1
  56. package/es/tx/builder/field-types/pointers.js +6 -2
  57. package/es/tx/builder/field-types/pointers.js.map +1 -1
  58. package/es/tx/builder/field-types/transaction.d.ts +4 -1
  59. package/es/tx/builder/field-types/transaction.js +18 -3
  60. package/es/tx/builder/field-types/transaction.js.map +1 -1
  61. package/es/tx/builder/field-types/with-formatting.d.ts +1 -1
  62. package/es/tx/builder/field-types/with-formatting.js +1 -1
  63. package/es/tx/builder/field-types/with-formatting.js.map +1 -1
  64. package/es/tx/builder/index.d.ts +13 -0
  65. package/es/tx/builder/index.js +92 -5
  66. package/es/tx/builder/index.js.map +1 -1
  67. package/es/tx/builder/protocol-parameters.d.ts +123 -0
  68. package/es/tx/builder/protocol-parameters.js +519 -0
  69. package/es/tx/builder/protocol-parameters.js.map +1 -0
  70. package/es/tx/builder/schema.d.ts +156 -155
  71. package/es/tx/builder/schema.js +5 -1
  72. package/es/tx/builder/schema.js.map +1 -1
  73. package/es/tx/execution-cost.js +5 -5
  74. package/es/tx/execution-cost.js.map +1 -1
  75. package/es/tx/transaction-signer.js +2 -2
  76. package/es/tx/transaction-signer.js.map +1 -1
  77. package/es/tx/validator.js +4 -4
  78. package/es/tx/validator.js.map +1 -1
  79. package/es/utils/wrap-proxy.d.ts +10 -0
  80. package/es/utils/wrap-proxy.js +18 -0
  81. package/es/utils/wrap-proxy.js.map +1 -1
  82. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Encoding","packRecord","unpackRecord","schemas","EntryTag","encodingTag","CallsMtree","CallStateTree","StateTrees","TreesPoi","Poi","packEntry","params","_encodingTag$find$","encoding","find","tag","Bytearray","unpackEntry","encoded","expectedTag","enc","startsWith"],"sources":["../../../../src/tx/builder/entry/index.ts"],"sourcesContent":["import { Encoded, Encoding } from '../../../utils/encoder.js';\nimport { packRecord, unpackRecord } from '../common.js';\nimport { schemas } from './schema.js';\nimport { EntryTag } from './constants.js';\nimport { EntParams, EntUnpacked } from './schema.generated.js';\n\nconst encodingTag = [\n [EntryTag.CallsMtree, Encoding.CallStateTree],\n [EntryTag.StateTrees, Encoding.StateTrees],\n [EntryTag.TreesPoi, Encoding.Poi],\n] as const;\n\nexport function packEntry(params: EntParams & { tag: EntryTag.CallsMtree }): Encoded.CallStateTree;\nexport function packEntry(params: EntParams & { tag: EntryTag.StateTrees }): Encoded.StateTrees;\nexport function packEntry(params: EntParams & { tag: EntryTag.TreesPoi }): Encoded.Poi;\n/**\n * Pack entry\n * @category entry builder\n * @param params - Params of entry\n * @returns Encoded entry\n */\nexport function packEntry(params: EntParams): Encoded.Any;\nexport function packEntry(params: EntParams): Encoded.Any {\n const encoding = encodingTag.find(([tag]) => tag === params.tag)?.[1] ?? Encoding.Bytearray;\n return packRecord(schemas, EntryTag, params, { packEntry }, encoding);\n}\n\nexport function unpackEntry(\n encoded: Encoded.CallStateTree,\n): EntUnpacked & { tag: EntryTag.CallsMtree };\nexport function unpackEntry(\n encoded: Encoded.StateTrees,\n): EntUnpacked & { tag: EntryTag.StateTrees };\nexport function unpackEntry(encoded: Encoded.Poi): EntUnpacked & { tag: EntryTag.TreesPoi };\n/**\n * Unpack entry\n * @category entry builder\n * @param encoded - Encoded entry\n * @param expectedTag - Expected entry type\n * @returns Params of entry\n */\nexport function unpackEntry<T extends EntryTag>(\n encoded: Encoded.Any,\n expectedTag?: T,\n): EntUnpacked & { tag: T };\nexport function unpackEntry(encoded: Encoded.Any, expectedTag?: EntryTag): EntUnpacked {\n expectedTag ??= encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0];\n return unpackRecord(schemas, EntryTag, encoded, expectedTag, { unpackEntry }) as any;\n}\n"],"mappings":"AAAA,SAAkBA,QAAQ,QAAQ,2BAA2B;AAC7D,SAASC,UAAU,EAAEC,YAAY,QAAQ,cAAc;AACvD,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,QAAQ,QAAQ,gBAAgB;AAGzC,MAAMC,WAAW,GAAG,CAClB,CAACD,QAAQ,CAACE,UAAU,EAAEN,QAAQ,CAACO,aAAa,CAAC,EAC7C,CAACH,QAAQ,CAACI,UAAU,EAAER,QAAQ,CAACQ,UAAU,CAAC,EAC1C,CAACJ,QAAQ,CAACK,QAAQ,EAAET,QAAQ,CAACU,GAAG,CAAC,CACzB;;AAKV;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,SAASA,CAACC,MAAiB,EAAe;EAAA,IAAAC,kBAAA;EACxD,MAAMC,QAAQ,IAAAD,kBAAA,GAAGR,WAAW,CAACU,IAAI,CAAC,CAAC,CAACC,GAAG,CAAC,KAAKA,GAAG,KAAKJ,MAAM,CAACI,GAAG,CAAC,GAAG,CAAC,CAAC,cAAAH,kBAAA,cAAAA,kBAAA,GAAIb,QAAQ,CAACiB,SAAS;EAC3F,OAAOhB,UAAU,CAACE,OAAO,EAAEC,QAAQ,EAAEQ,MAAM,EAAE;IAAED;EAAU,CAAC,EAAEG,QAAQ,CAAC;AACvE;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,SAASI,WAAWA,CAACC,OAAoB,EAAEC,WAAsB,EAAe;EACrFA,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAXA,WAAW,GAAKf,WAAW,CAACU,IAAI,CAAC,CAAC,GAAGM,GAAG,CAAC,KAAKF,OAAO,CAACG,UAAU,CAACD,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;EAC3E,OAAOnB,YAAY,CAACC,OAAO,EAAEC,QAAQ,EAAEe,OAAO,EAAEC,WAAW,EAAE;IAAEF;EAAY,CAAC,CAAC;AAC/E","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Encoding","packRecord","unpackRecord","schemas","EntryTag","checkParametersUsable","encodingTag","CallsMtree","CallStateTree","StateTrees","TreesPoi","Poi","packEntry","params","_encodingTag$find$","protocolParameters","encoding","find","tag","Bytearray","unpackEntry","encoded","expectedTag","enc","startsWith"],"sources":["../../../../src/tx/builder/entry/index.ts"],"sourcesContent":["import { Encoded, Encoding } from '../../../utils/encoder.js';\nimport { packRecord, unpackRecord } from '../common.js';\nimport { schemas } from './schema.js';\nimport { EntryTag } from './constants.js';\nimport { EntParams, EntUnpacked } from './schema.generated.js';\nimport { checkParametersUsable, ProtocolParametersOption } from '../protocol-parameters.js';\n\nconst encodingTag = [\n [EntryTag.CallsMtree, Encoding.CallStateTree],\n [EntryTag.StateTrees, Encoding.StateTrees],\n [EntryTag.TreesPoi, Encoding.Poi],\n] as const;\n\nexport function packEntry(params: EntParams & { tag: EntryTag.CallsMtree }): Encoded.CallStateTree;\nexport function packEntry(params: EntParams & { tag: EntryTag.StateTrees }): Encoded.StateTrees;\nexport function packEntry(params: EntParams & { tag: EntryTag.TreesPoi }): Encoded.Poi;\n/**\n * Pack entry\n * @category entry builder\n * @param params - Params of entry\n * @returns Encoded entry\n */\nexport function packEntry(params: EntParams): Encoded.Any;\nexport function packEntry(params: EntParams): Encoded.Any {\n // `GaMetaTxAuthData` holds a `gasPrice` priced by them, see the note in `buildTx`\n const { protocolParameters } = params as ProtocolParametersOption;\n if (protocolParameters != null) checkParametersUsable(protocolParameters);\n const encoding = encodingTag.find(([tag]) => tag === params.tag)?.[1] ?? Encoding.Bytearray;\n return packRecord(schemas, EntryTag, params, { packEntry }, encoding);\n}\n\nexport function unpackEntry(\n encoded: Encoded.CallStateTree,\n): EntUnpacked & { tag: EntryTag.CallsMtree };\nexport function unpackEntry(\n encoded: Encoded.StateTrees,\n): EntUnpacked & { tag: EntryTag.StateTrees };\nexport function unpackEntry(encoded: Encoded.Poi): EntUnpacked & { tag: EntryTag.TreesPoi };\n/**\n * Unpack entry\n * @category entry builder\n * @param encoded - Encoded entry\n * @param expectedTag - Expected entry type\n * @returns Params of entry\n */\nexport function unpackEntry<T extends EntryTag>(\n encoded: Encoded.Any,\n expectedTag?: T,\n): EntUnpacked & { tag: T };\nexport function unpackEntry(encoded: Encoded.Any, expectedTag?: EntryTag): EntUnpacked {\n expectedTag ??= encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0];\n return unpackRecord(schemas, EntryTag, encoded, expectedTag, { unpackEntry }) as any;\n}\n"],"mappings":"AAAA,SAAkBA,QAAQ,QAAQ,2BAA2B;AAC7D,SAASC,UAAU,EAAEC,YAAY,QAAQ,cAAc;AACvD,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,qBAAqB,QAAkC,2BAA2B;AAE3F,MAAMC,WAAW,GAAG,CAClB,CAACF,QAAQ,CAACG,UAAU,EAAEP,QAAQ,CAACQ,aAAa,CAAC,EAC7C,CAACJ,QAAQ,CAACK,UAAU,EAAET,QAAQ,CAACS,UAAU,CAAC,EAC1C,CAACL,QAAQ,CAACM,QAAQ,EAAEV,QAAQ,CAACW,GAAG,CAAC,CACzB;;AAKV;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,SAASA,CAACC,MAAiB,EAAe;EAAA,IAAAC,kBAAA;EACxD;EACA,MAAM;IAAEC;EAAmB,CAAC,GAAGF,MAAkC;EACjE,IAAIE,kBAAkB,IAAI,IAAI,EAAEV,qBAAqB,CAACU,kBAAkB,CAAC;EACzE,MAAMC,QAAQ,IAAAF,kBAAA,GAAGR,WAAW,CAACW,IAAI,CAAC,CAAC,CAACC,GAAG,CAAC,KAAKA,GAAG,KAAKL,MAAM,CAACK,GAAG,CAAC,GAAG,CAAC,CAAC,cAAAJ,kBAAA,cAAAA,kBAAA,GAAId,QAAQ,CAACmB,SAAS;EAC3F,OAAOlB,UAAU,CAACE,OAAO,EAAEC,QAAQ,EAAES,MAAM,EAAE;IAAED;EAAU,CAAC,EAAEI,QAAQ,CAAC;AACvE;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,SAASI,WAAWA,CAACC,OAAoB,EAAEC,WAAsB,EAAe;EACrFA,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAXA,WAAW,GAAKhB,WAAW,CAACW,IAAI,CAAC,CAAC,GAAGM,GAAG,CAAC,KAAKF,OAAO,CAACG,UAAU,CAACD,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;EAC3E,OAAOrB,YAAY,CAACC,OAAO,EAAEC,QAAQ,EAAEiB,OAAO,EAAEC,WAAW,EAAE;IAAEF;EAAY,CAAC,CAAC;AAC/E","ignoreList":[]}
@@ -158,7 +158,7 @@ export declare const schemas: readonly [{
158
158
  id: Encoded.Generic<import("../field-types/address.js").AddressEncodings | Encoding.Bytearray>;
159
159
  } : import("../../../apis/node/index.js").NamePointer & {
160
160
  id: Encoded.Generic<import("../field-types/address.js").AddressEncodings>;
161
- }>) => Buffer[][];
161
+ }>, params: import("../field-types/interface.js").SerializeAsIsParams) => Buffer[][];
162
162
  deserialize: (pointers: Array<[key: Buffer, id: Buffer]>) => Array<AllowRaw extends true ? import("../../../apis/node/index.js").NamePointer & {
163
163
  id: Encoded.Generic<import("../field-types/address.js").AddressEncodings | Encoding.Bytearray>;
164
164
  } : import("../../../apis/node/index.js").NamePointer & {
@@ -543,26 +543,26 @@ export declare const schemas: readonly [{
543
543
  deserialize(buffer: Buffer): Buffer;
544
544
  };
545
545
  readonly gasPrice: {
546
- prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, }: {
546
+ prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
547
547
  onNode?: import("../../../Node.js").default;
548
548
  denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
549
- }): Promise<import("../constants.js").Int | undefined>;
550
- serializeAettos(value?: string | undefined): string;
549
+ } & import("../protocol-parameters.js").ProtocolParametersOption): Promise<import("../constants.js").Int | undefined>;
550
+ serializeAettos(value: string | undefined, params: import("../field-types/interface.js").SerializeAsIsParams, { protocolParameters }: import("../protocol-parameters.js").ProtocolParametersOption): string;
551
551
  serialize(value: import("../constants.js").Int | undefined, params: {}, { denomination, ...options }: {
552
552
  denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
553
553
  }): Buffer;
554
554
  deserialize(value: Buffer): string;
555
555
  };
556
556
  readonly gasLimit: {
557
- serialize(_value: number | undefined, { tag, rebuildTx, unpackTx, buildTx, _computingGasLimit, }: {
557
+ serialize(_value: number | undefined, params: {
558
558
  tag: import("../constants.js").Tag;
559
559
  rebuildTx: (params: any) => any;
560
560
  unpackTx: typeof import("../index.js").unpackTx;
561
561
  buildTx: typeof import("../index.js").buildTx;
562
562
  _computingGasLimit?: number;
563
- }, { gasMax }: {
563
+ } & import("../field-types/interface.js").SerializeAsIsParams, { gasMax, protocolParameters, }: {
564
564
  gasMax?: number;
565
- }): Buffer;
565
+ } & import("../protocol-parameters.js").ProtocolParametersOption): Buffer;
566
566
  deserialize(value: Buffer): number;
567
567
  };
568
568
  }, {
@@ -1009,11 +1009,11 @@ export declare const schemas: readonly [{
1009
1009
  deserialize(value: Buffer): string;
1010
1010
  };
1011
1011
  readonly gasPrice: {
1012
- prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, }: {
1012
+ prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
1013
1013
  onNode?: import("../../../Node.js").default;
1014
1014
  denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
1015
- }): Promise<import("../constants.js").Int | undefined>;
1016
- serializeAettos(value?: string | undefined): string;
1015
+ } & import("../protocol-parameters.js").ProtocolParametersOption): Promise<import("../constants.js").Int | undefined>;
1016
+ serializeAettos(value: string | undefined, params: import("../field-types/interface.js").SerializeAsIsParams, { protocolParameters }: import("../protocol-parameters.js").ProtocolParametersOption): string;
1017
1017
  serialize(value: import("../constants.js").Int | undefined, params: {}, { denomination, ...options }: {
1018
1018
  denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
1019
1019
  }): Buffer;
@@ -15,6 +15,20 @@ export declare const ProtocolToVmAbi: {
15
15
  readonly abiVersion: readonly [AbiVersion.NoAbi, AbiVersion.Fate];
16
16
  };
17
17
  };
18
+ readonly 7: {
19
+ readonly 'contract-create': {
20
+ readonly vmVersion: readonly [VmVersion.Fate3];
21
+ readonly abiVersion: readonly [AbiVersion.Fate];
22
+ };
23
+ readonly 'contract-call': {
24
+ readonly vmVersion: readonly [];
25
+ readonly abiVersion: readonly [AbiVersion.Fate];
26
+ };
27
+ readonly 'oracle-call': {
28
+ readonly vmVersion: readonly [];
29
+ readonly abiVersion: readonly [AbiVersion.NoAbi, AbiVersion.Fate];
30
+ };
31
+ };
18
32
  };
19
33
  export interface CtVersion {
20
34
  vmVersion: VmVersion;
@@ -18,6 +18,20 @@ export const ProtocolToVmAbi = {
18
18
  vmVersion: [],
19
19
  abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate]
20
20
  }
21
+ },
22
+ [ConsensusProtocolVersion.Arcus]: {
23
+ 'contract-create': {
24
+ vmVersion: [VmVersion.Fate3],
25
+ abiVersion: [AbiVersion.Fate]
26
+ },
27
+ 'contract-call': {
28
+ vmVersion: [],
29
+ abiVersion: [AbiVersion.Fate]
30
+ },
31
+ 'oracle-call': {
32
+ vmVersion: [],
33
+ abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate]
34
+ }
21
35
  }
22
36
  };
23
37
  export function getProtocolDetails(protocolVersion, type) {
@@ -1 +1 @@
1
- {"version":3,"file":"ct-version.js","names":["ConsensusProtocolVersion","VmVersion","AbiVersion","ProtocolToVmAbi","Ceres","vmVersion","Fate3","abiVersion","Fate","NoAbi","getProtocolDetails","protocolVersion","type","_protocol$vmVersion$","protocol","Fate2","serialize","value","params","consensusProtocolVersion","_Buffer","from","prepare","options","undefined","Object","keys","length","onNode","getNodeInfo","deserialize","buffer","vm","abi"],"sources":["../../../../src/tx/builder/field-types/ct-version.ts"],"sourcesContent":["import { ConsensusProtocolVersion, VmVersion, AbiVersion } from '../constants.js';\nimport Node from '../../../Node.js';\n\n/*\n * First abi/vm by default\n * @see {@link https://github.com/aeternity/protocol/blob/71cf111/contracts/contract_vms.md#virtual-machines-on-the-æternity-blockchain}\n */\nexport const ProtocolToVmAbi = {\n [ConsensusProtocolVersion.Ceres]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate3],\n abiVersion: [AbiVersion.Fate],\n },\n 'contract-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.Fate],\n },\n 'oracle-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],\n },\n },\n} as const;\n\nexport interface CtVersion {\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n}\n\nexport function getProtocolDetails(\n protocolVersion: ConsensusProtocolVersion,\n type: 'contract-create' | 'contract-call' | 'oracle-call',\n): CtVersion {\n const protocol = ProtocolToVmAbi[protocolVersion][type];\n return {\n vmVersion: protocol.vmVersion[0] ?? VmVersion.Fate2,\n abiVersion: protocol.abiVersion[0],\n };\n}\n\nexport default {\n serialize(\n value: CtVersion | undefined,\n params: {},\n {\n consensusProtocolVersion = ConsensusProtocolVersion.Ceres,\n }: { consensusProtocolVersion?: ConsensusProtocolVersion },\n ): Buffer {\n value ??= getProtocolDetails(consensusProtocolVersion, 'contract-create');\n\n return Buffer.from([value.vmVersion, 0, value.abiVersion]);\n },\n\n async prepare(\n value: CtVersion | undefined,\n params: {},\n // TODO: { consensusProtocolVersion: ConsensusProtocolVersion } | { onNode: Node } | {}\n options: { consensusProtocolVersion?: ConsensusProtocolVersion; onNode?: Node },\n ): Promise<CtVersion | undefined> {\n if (value != null) return value;\n if (options.consensusProtocolVersion != null) return undefined;\n if (Object.keys(ConsensusProtocolVersion).length === 2) return undefined;\n if (options.onNode != null) {\n return getProtocolDetails(\n (await options.onNode.getNodeInfo()).consensusProtocolVersion,\n 'contract-create',\n );\n }\n return undefined;\n },\n\n deserialize(buffer: Buffer): CtVersion {\n const [vm, , abi] = buffer;\n return { vmVersion: +vm, abiVersion: +abi };\n },\n};\n"],"mappings":";AAAA,SAASA,wBAAwB,EAAEC,SAAS,EAAEC,UAAU,QAAQ,iBAAiB;AAGjF;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACH,wBAAwB,CAACI,KAAK,GAAG;IAChC,iBAAiB,EAAE;MACjBC,SAAS,EAAE,CAACJ,SAAS,CAACK,KAAK,CAAC;MAC5BC,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,eAAe,EAAE;MACfH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,aAAa,EAAE;MACbH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACO,KAAK,EAAEP,UAAU,CAACM,IAAI;IAChD;EACF;AACF,CAAU;AAOV,OAAO,SAASE,kBAAkBA,CAChCC,eAAyC,EACzCC,IAAyD,EAC9C;EAAA,IAAAC,oBAAA;EACX,MAAMC,QAAQ,GAAGX,eAAe,CAACQ,eAAe,CAAC,CAACC,IAAI,CAAC;EACvD,OAAO;IACLP,SAAS,GAAAQ,oBAAA,G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js","names":["ConsensusProtocolVersion","VmVersion","AbiVersion","ProtocolToVmAbi","Ceres","vmVersion","Fate3","abiVersion","Fate","NoAbi","Arcus","getProtocolDetails","protocolVersion","type","_protocol$vmVersion$","protocol","Fate2","serialize","value","params","consensusProtocolVersion","_Buffer","from","prepare","options","undefined","Object","keys","length","onNode","getNodeInfo","deserialize","buffer","vm","abi"],"sources":["../../../../src/tx/builder/field-types/ct-version.ts"],"sourcesContent":["import { ConsensusProtocolVersion, VmVersion, AbiVersion } from '../constants.js';\nimport Node from '../../../Node.js';\n\n/*\n * First abi/vm by default\n * @see {@link https://github.com/aeternity/protocol/blob/71cf111/contracts/contract_vms.md#virtual-machines-on-the-æternity-blockchain}\n */\nexport const ProtocolToVmAbi = {\n [ConsensusProtocolVersion.Ceres]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate3],\n abiVersion: [AbiVersion.Fate],\n },\n 'contract-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.Fate],\n },\n 'oracle-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],\n },\n },\n [ConsensusProtocolVersion.Arcus]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate3],\n abiVersion: [AbiVersion.Fate],\n },\n 'contract-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.Fate],\n },\n 'oracle-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],\n },\n },\n} as const;\n\nexport interface CtVersion {\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n}\n\nexport function getProtocolDetails(\n protocolVersion: ConsensusProtocolVersion,\n type: 'contract-create' | 'contract-call' | 'oracle-call',\n): CtVersion {\n const protocol = ProtocolToVmAbi[protocolVersion][type];\n return {\n vmVersion: protocol.vmVersion[0] ?? VmVersion.Fate2,\n abiVersion: protocol.abiVersion[0],\n };\n}\n\nexport default {\n serialize(\n value: CtVersion | undefined,\n params: {},\n {\n consensusProtocolVersion = ConsensusProtocolVersion.Ceres,\n }: { consensusProtocolVersion?: ConsensusProtocolVersion },\n ): Buffer {\n value ??= getProtocolDetails(consensusProtocolVersion, 'contract-create');\n\n return Buffer.from([value.vmVersion, 0, value.abiVersion]);\n },\n\n async prepare(\n value: CtVersion | undefined,\n params: {},\n // TODO: { consensusProtocolVersion: ConsensusProtocolVersion } | { onNode: Node } | {}\n options: { consensusProtocolVersion?: ConsensusProtocolVersion; onNode?: Node },\n ): Promise<CtVersion | undefined> {\n if (value != null) return value;\n if (options.consensusProtocolVersion != null) return undefined;\n if (Object.keys(ConsensusProtocolVersion).length === 2) return undefined;\n if (options.onNode != null) {\n return getProtocolDetails(\n (await options.onNode.getNodeInfo()).consensusProtocolVersion,\n 'contract-create',\n );\n }\n return undefined;\n },\n\n deserialize(buffer: Buffer): CtVersion {\n const [vm, , abi] = buffer;\n return { vmVersion: +vm, abiVersion: +abi };\n },\n};\n"],"mappings":";AAAA,SAASA,wBAAwB,EAAEC,SAAS,EAAEC,UAAU,QAAQ,iBAAiB;AAGjF;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACH,wBAAwB,CAACI,KAAK,GAAG;IAChC,iBAAiB,EAAE;MACjBC,SAAS,EAAE,CAACJ,SAAS,CAACK,KAAK,CAAC;MAC5BC,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,eAAe,EAAE;MACfH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,aAAa,EAAE;MACbH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACO,KAAK,EAAEP,UAAU,CAACM,IAAI;IAChD;EACF,CAAC;EACD,CAACR,wBAAwB,CAACU,KAAK,GAAG;IAChC,iBAAiB,EAAE;MACjBL,SAAS,EAAE,CAACJ,SAAS,CAACK,KAAK,CAAC;MAC5BC,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CA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OAAO,CAACK,MAAM,IAAI,IAAI,EAAE;MAC1B,OAAOlB,kBAAkB,CACvB,CAAC,MAAMa,OAAO,CAACK,MAAM,CAACC,WAAW,CAAC,CAAC,EAAEV,wBAAwB,EAC7D,iBACF,CAAC;IACH;IACA,OAAOK,SAAS;EAClB,CAAC;EAEDM,WAAWA,CAACC,MAAc,EAAa;IACrC,MAAM,CAACC,EAAE,GAAIC,GAAG,CAAC,GAAGF,MAAM;IAC1B,OAAO;MAAE3B,SAAS,EAAE,CAAC4B,EAAE;MAAE1B,UAAU,EAAE,CAAC2B;IAAI,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
@@ -1,29 +1,31 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { Int } from '../constants.js';
3
+ import { ProtocolParameters, ProtocolParametersOption } from '../protocol-parameters.js';
3
4
  import coinAmount from './coin-amount.js';
5
+ import { SerializeAsIsParams } from './interface.js';
4
6
  import { Encoded } from '../../../utils/encoder.js';
5
7
  import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';
6
8
  import Node from '../../../Node.js';
7
9
  /**
8
10
  * Calculate gas based on tx type and params
9
11
  */
10
- export declare function buildGas(builtTx: Encoded.Transaction, unpackTx: typeof unpackTxType, buildTx: typeof buildTxType): number;
11
- export interface SerializeAettosParams {
12
+ export declare function buildGas(builtTx: Encoded.Transaction, unpackTx: typeof unpackTxType, buildTx: typeof buildTxType, protocolParameters: ProtocolParameters): number;
13
+ export interface SerializeAettosParams extends SerializeAsIsParams {
12
14
  rebuildTx: (params: any) => Encoded.Transaction;
13
15
  unpackTx: typeof unpackTxType;
14
16
  buildTx: typeof buildTxType;
15
17
  _computingMinFee?: BigNumber;
16
18
  }
17
19
  declare const _default: {
18
- prepare(value: Int | undefined, params: {}, { onNode }: {
20
+ prepare(value: Int | undefined, params: {}, { onNode, protocolParameters }: {
19
21
  onNode?: Node;
20
- }): Promise<Int | undefined>;
21
- serializeAettos(_value: string | undefined, { rebuildTx, unpackTx, buildTx, _computingMinFee }: SerializeAettosParams, { _canIncreaseFee }: {
22
+ } & ProtocolParametersOption): Promise<Int | undefined>;
23
+ serializeAettos(_value: string | undefined, params: SerializeAettosParams, { _canIncreaseFee, protocolParameters, }: {
22
24
  _canIncreaseFee?: boolean;
23
- }): string;
25
+ } & ProtocolParametersOption): string;
24
26
  serialize(value: Parameters<typeof coinAmount.serialize>[0], params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams, options: {
25
27
  _canIncreaseFee?: boolean;
26
- } & Parameters<typeof coinAmount.serialize>[2]): Buffer;
28
+ } & ProtocolParametersOption & Parameters<typeof coinAmount.serialize>[2]): Buffer;
27
29
  deserialize(value: Buffer): string;
28
30
  };
29
31
  export default _default;
@@ -1,72 +1,70 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';
3
- import { MIN_GAS_PRICE, Tag } from '../constants.js';
2
+ import { ArgumentError, IllegalArgumentError, InternalError } from '../../../utils/errors.js';
3
+ import { Tag } from '../constants.js';
4
+ import { defaultProtocolParameters, maxOf } from '../protocol-parameters.js';
4
5
  import uInt from './u-int.js';
5
6
  import coinAmount from './coin-amount.js';
6
7
  import { getCachedIncreasedGasPrice } from './gas-price.js';
7
8
  import { isKeyOfObject } from '../../../utils/other.js';
9
+ import { serializeAsIsParam } from './interface.js';
8
10
  import { decode } from '../../../utils/encoder.js';
9
- const BASE_GAS = 15000;
10
- const GAS_PER_BYTE = 20;
11
- const KEY_BLOCK_INTERVAL = 3;
12
-
13
11
  /**
14
- * Calculate the base gas
12
+ * Get the base gas
15
13
  * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
16
- * @param txType - The transaction type
14
+ * @param txObject - The unpacked transaction
15
+ * @param protocolParameters - The protocol parameters
17
16
  * @returns The base gas
18
- * @example
19
- * ```js
20
- * TX_BASE_GAS(Tag.ChannelForceProgressTx) => 30 * 15000
21
- * ```
22
17
  */
23
- const TX_BASE_GAS = txType => {
24
- var _feeFactors;
25
- const feeFactors = {
26
- [Tag.ChannelForceProgressTx]: 30,
27
- [Tag.ChannelOffChainTx]: 0,
28
- [Tag.ContractCreateTx]: 5,
29
- [Tag.ContractCallTx]: 12,
30
- [Tag.GaAttachTx]: 5,
31
- [Tag.GaMetaTx]: 5,
32
- [Tag.PayingForTx]: 1 / 5
33
- };
34
- const factor = (_feeFactors = feeFactors[txType]) !== null && _feeFactors !== void 0 ? _feeFactors : 1;
35
- return factor * BASE_GAS;
36
- };
18
+ function getTxBaseGas(txObject, protocolParameters) {
19
+ const {
20
+ tag
21
+ } = txObject;
22
+ const byAbiVersion = protocolParameters.contractTxBaseGas[tag];
23
+ if (byAbiVersion != null) {
24
+ var _txObject$ctVersion$a;
25
+ const abiVersion = (_txObject$ctVersion$a = txObject.ctVersion?.abiVersion) !== null && _txObject$ctVersion$a !== void 0 ? _txObject$ctVersion$a : txObject.abiVersion;
26
+ // read only what the checks in `protocol-parameters.ts` iterate, so that the two can't
27
+ // disagree about what the parameters hold — anything inherited is not a base gas
28
+ const gas = Object.prototype.hasOwnProperty.call(byAbiVersion, abiVersion) ? byAbiVersion[abiVersion] : undefined;
29
+ if (gas != null) return gas;
30
+ // node charges the maximum base gas for an abi version it doesn't know
31
+ const knownAbiVersions = Object.values(byAbiVersion);
32
+ // the maximum of nothing is `-Infinity`, fall through to `txBaseGas` instead
33
+ if (knownAbiVersions.length !== 0) return maxOf(knownAbiVersions);
34
+ }
35
+ const gas = protocolParameters.txBaseGas[tag];
36
+ if (gas == null) throw new InternalError(`Base gas of ${Tag[tag]} is not known`);
37
+ return gas;
38
+ }
37
39
 
38
40
  /**
39
41
  * Calculate gas for other types of transactions
40
42
  * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
41
43
  * @param txType - The transaction type
42
44
  * @param txSize - The transaction size
43
- * @returns parameters - The transaction parameters
44
- * @returns parameters.relativeTtl - The relative ttl
45
- * @returns parameters.innerTxSize - The size of the inner transaction
45
+ * @param parameters - The transaction parameters
46
+ * @param parameters.relativeTtl - The relative ttl
47
+ * @param parameters.innerTxSize - The size of the inner transaction
48
+ * @param protocolParameters - The protocol parameters
46
49
  * @returns The other gas
47
- * @example
48
- * ```js
49
- * TX_OTHER_GAS(Tag.OracleRespondTx, 10, { relativeTtl: 12, innerTxSize: 0 })
50
- * => 10 * 20 + Math.ceil(32000 * 12 / Math.floor(60 * 24 * 365 / 3))
51
- * ```
52
50
  */
53
- const TX_OTHER_GAS = (txType, txSize, {
51
+ function getTxOtherGas(txType, txSize, {
54
52
  relativeTtl,
55
53
  innerTxSize
56
- }) => {
57
- switch (txType) {
58
- case Tag.OracleRegisterTx:
59
- case Tag.OracleExtendTx:
60
- case Tag.OracleQueryTx:
61
- case Tag.OracleRespondTx:
62
- return txSize * GAS_PER_BYTE + Math.ceil(32000 * relativeTtl / Math.floor(60 * 24 * 365 / KEY_BLOCK_INTERVAL));
63
- case Tag.GaMetaTx:
64
- case Tag.PayingForTx:
65
- return (txSize - innerTxSize) * GAS_PER_BYTE;
66
- default:
67
- return txSize * GAS_PER_BYTE;
68
- }
69
- };
54
+ }, protocolParameters) {
55
+ const {
56
+ gasPerByte
57
+ } = protocolParameters;
58
+ // the inner transaction of a meta transaction pays for its own bytes in its own fee. The
59
+ // deduction is separate from the state gas below: node reporting a state gas fraction for
60
+ // `GaMetaTx`/`PayingForTx` must not cancel it — that would charge the inner transaction twice
61
+ const isMeta = txType === Tag.GaMetaTx || txType === Tag.PayingForTx;
62
+ const sizeGas = (isMeta ? txSize - innerTxSize : txSize) * gasPerByte;
63
+ // oracle transactions pay a state rent for the time their entry occupies the state tree
64
+ const stateGas = protocolParameters.stateGasPerBlock[txType];
65
+ if (stateGas == null) return sizeGas;
66
+ return sizeGas + Math.ceil(stateGas.part * relativeTtl / stateGas.whole);
67
+ }
70
68
  function getOracleRelativeTtl(params) {
71
69
  const ttlKeys = {
72
70
  [Tag.OracleRegisterTx]: 'oracleTtlValue',
@@ -84,19 +82,25 @@ function getOracleRelativeTtl(params) {
84
82
  /**
85
83
  * Calculate gas based on tx type and params
86
84
  */
87
- export function buildGas(builtTx, unpackTx, buildTx) {
85
+ export function buildGas(builtTx, unpackTx, buildTx, protocolParameters) {
88
86
  const {
89
87
  length
90
88
  } = decode(builtTx);
91
89
  const txObject = unpackTx(builtTx);
92
90
  let innerTxSize = 0;
93
91
  if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {
94
- innerTxSize = decode(buildTx(txObject.tx.encodedTx)).length;
92
+ // this rebuild only measures the size of an already signed inner transaction, its values are
93
+ // serialized as they are — see `serializeAsIsParam`
94
+ const innerTx = {
95
+ ...txObject.tx.encodedTx,
96
+ [serializeAsIsParam]: true
97
+ };
98
+ innerTxSize = decode(buildTx(innerTx)).length;
95
99
  }
96
- return TX_BASE_GAS(txObject.tag) + TX_OTHER_GAS(txObject.tag, length, {
100
+ return getTxBaseGas(txObject, protocolParameters) + getTxOtherGas(txObject.tag, length, {
97
101
  relativeTtl: getOracleRelativeTtl(txObject),
98
102
  innerTxSize
99
- });
103
+ }, protocolParameters);
100
104
  }
101
105
 
102
106
  /**
@@ -104,12 +108,13 @@ export function buildGas(builtTx, unpackTx, buildTx) {
104
108
  * @category transaction builder
105
109
  * @param rebuildTx - Callback to get built transaction with specific fee
106
110
  */
107
- function calculateMinFee(rebuildTx, unpackTx, buildTx) {
111
+ function calculateMinFee(rebuildTx, unpackTx, buildTx, protocolParameters) {
112
+ const minGasPrice = new BigNumber(protocolParameters.minGasPrice.toString());
108
113
  let fee = new BigNumber(0);
109
114
  let previousFee;
110
115
  do {
111
116
  previousFee = fee;
112
- fee = new BigNumber(MIN_GAS_PRICE).times(buildGas(rebuildTx(fee), unpackTx, buildTx));
117
+ fee = minGasPrice.times(buildGas(rebuildTx(fee), unpackTx, buildTx, protocolParameters));
113
118
  } while (!fee.eq(previousFee));
114
119
  return fee;
115
120
  }
@@ -121,29 +126,33 @@ const gasPricePrefix = '_gas-price:';
121
126
  export default {
122
127
  ...coinAmount,
123
128
  async prepare(value, params, {
124
- onNode
129
+ onNode,
130
+ protocolParameters
125
131
  }) {
126
132
  if (value != null) return value;
127
133
  if (onNode == null) {
128
134
  throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);
129
135
  }
130
- const gasPrice = await getCachedIncreasedGasPrice(onNode);
136
+ const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);
131
137
  if (gasPrice === 0n) return undefined;
132
138
  return gasPricePrefix + gasPrice;
133
139
  },
134
- serializeAettos(_value, {
135
- rebuildTx,
136
- unpackTx,
137
- buildTx,
138
- _computingMinFee
139
- }, {
140
- _canIncreaseFee
140
+ serializeAettos(_value, params, {
141
+ _canIncreaseFee,
142
+ protocolParameters = defaultProtocolParameters
141
143
  }) {
144
+ const {
145
+ rebuildTx,
146
+ unpackTx,
147
+ buildTx,
148
+ _computingMinFee
149
+ } = params;
142
150
  if (_computingMinFee != null) return _computingMinFee.toFixed();
151
+ if (params[serializeAsIsParam] === true && _value != null) return new BigNumber(_value).toFixed();
143
152
  const minFee = calculateMinFee(fee => rebuildTx({
144
153
  _computingMinFee: fee
145
- }), unpackTx, buildTx);
146
- const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(MIN_GAS_PRICE).times(_value.replace(gasPricePrefix, '')) : new BigNumber(_value !== null && _value !== void 0 ? _value : minFee);
154
+ }), unpackTx, buildTx, protocolParameters);
155
+ const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(protocolParameters.minGasPrice.toString()).times(_value.replace(gasPricePrefix, '')) : new BigNumber(_value !== null && _value !== void 0 ? _value : minFee);
147
156
  if (minFee.gt(value)) {
148
157
  if (_canIncreaseFee === true) return minFee.toFixed();
149
158
  throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);
@@ -1 +1 @@
1
- {"version":3,"file":"fee.js","names":["BigNumber","ArgumentError","IllegalArgumentError","MIN_GAS_PRICE","Tag","uInt","coinAmount","getCachedIncreasedGasPrice","isKeyOfObject","decode","BASE_GAS","GAS_PER_BYTE","KEY_BLOCK_INTERVAL","TX_BASE_GAS","txType","_feeFactors","feeFactors","ChannelForceProgressTx","ChannelOffChainTx","ContractCreateTx","ContractCallTx","GaAttachTx","GaMetaTx","PayingForTx","factor","TX_OTHER_GAS","txSize","relativeTtl","innerTxSize","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleRespondTx","Math","ceil","floor","getOracleRelativeTtl","params","ttlKeys","tag","buildGas","builtTx","unpackTx","buildTx","length","txObject","tx","encodedTx","calculateMinFee","rebuildTx","fee","previousFee","times","eq","gasPricePrefix","prepare","value","onNode","gasPrice","undefined","serializeAettos","_value","_computingMinFee","_canIncreaseFee","toFixed","minFee","startsWith","dividedBy","replace","gt","toString","serialize","options","call"],"sources":["../../../../src/tx/builder/field-types/fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';\nimport { Int, MIN_GAS_PRICE, Tag } from '../constants.js';\nimport uInt from './u-int.js';\nimport coinAmount from './coin-amount.js';\nimport { getCachedIncreasedGasPrice } from './gas-price.js';\nimport { isKeyOfObject } from '../../../utils/other.js';\nimport { decode, Encoded } from '../../../utils/encoder.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\nimport Node from '../../../Node.js';\n\nconst BASE_GAS = 15000;\nconst GAS_PER_BYTE = 20;\nconst KEY_BLOCK_INTERVAL = 3;\n\n/**\n * Calculate the base gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @returns The base gas\n * @example\n * ```js\n * TX_BASE_GAS(Tag.ChannelForceProgressTx) => 30 * 15000\n * ```\n */\nconst TX_BASE_GAS = (txType: Tag): number => {\n const feeFactors = {\n [Tag.ChannelForceProgressTx]: 30,\n [Tag.ChannelOffChainTx]: 0,\n [Tag.ContractCreateTx]: 5,\n [Tag.ContractCallTx]: 12,\n [Tag.GaAttachTx]: 5,\n [Tag.GaMetaTx]: 5,\n [Tag.PayingForTx]: 1 / 5,\n } as const;\n const factor = feeFactors[txType as keyof typeof feeFactors] ?? 1;\n return factor * BASE_GAS;\n};\n\n/**\n * Calculate gas for other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @returns parameters - The transaction parameters\n * @returns parameters.relativeTtl - The relative ttl\n * @returns parameters.innerTxSize - The size of the inner transaction\n * @returns The other gas\n * @example\n * ```js\n * TX_OTHER_GAS(Tag.OracleRespondTx, 10, { relativeTtl: 12, innerTxSize: 0 })\n * => 10 * 20 + Math.ceil(32000 * 12 / Math.floor(60 * 24 * 365 / 3))\n * ```\n */\nconst TX_OTHER_GAS = (\n txType: Tag,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number; innerTxSize: number },\n): number => {\n switch (txType) {\n case Tag.OracleRegisterTx:\n case Tag.OracleExtendTx:\n case Tag.OracleQueryTx:\n case Tag.OracleRespondTx:\n return (\n txSize * GAS_PER_BYTE +\n Math.ceil((32000 * relativeTtl) / Math.floor((60 * 24 * 365) / KEY_BLOCK_INTERVAL))\n );\n case Tag.GaMetaTx:\n case Tag.PayingForTx:\n return (txSize - innerTxSize) * GAS_PER_BYTE;\n default:\n return txSize * GAS_PER_BYTE;\n }\n};\n\nfunction getOracleRelativeTtl(params: any): number {\n const ttlKeys = {\n [Tag.OracleRegisterTx]: 'oracleTtlValue',\n [Tag.OracleExtendTx]: 'oracleTtlValue',\n [Tag.OracleQueryTx]: 'queryTtlValue',\n [Tag.OracleRespondTx]: 'responseTtlValue',\n } as const;\n\n const { tag } = params;\n if (!isKeyOfObject(tag, ttlKeys)) return 1;\n return params[ttlKeys[tag]];\n}\n\n/**\n * Calculate gas based on tx type and params\n */\nexport function buildGas(\n builtTx: Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): number {\n const { length } = decode(builtTx);\n const txObject = unpackTx(builtTx);\n\n let innerTxSize = 0;\n if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {\n innerTxSize = decode(buildTx(txObject.tx.encodedTx)).length;\n }\n\n return (\n TX_BASE_GAS(txObject.tag) +\n TX_OTHER_GAS(txObject.tag, length, {\n relativeTtl: getOracleRelativeTtl(txObject),\n innerTxSize,\n })\n );\n}\n\n/**\n * Calculate min fee\n * @category transaction builder\n * @param rebuildTx - Callback to get built transaction with specific fee\n */\nfunction calculateMinFee(\n rebuildTx: (value: BigNumber) => Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): BigNumber {\n let fee = new BigNumber(0);\n let previousFee;\n do {\n previousFee = fee;\n fee = new BigNumber(MIN_GAS_PRICE).times(buildGas(rebuildTx(fee), unpackTx, buildTx));\n } while (!fee.eq(previousFee));\n return fee;\n}\n\n// TODO: Get rid of this workaround. Transaction builder can't accept/return gas price instead of\n// fee because it may get a decimal gas price. So, it should accept the optional `gasPrice` even\n// if it is not a contract-related transaction. And use this `gasPrice` to calculate `fee`.\nconst gasPricePrefix = '_gas-price:';\n\nexport interface SerializeAettosParams {\n rebuildTx: (params: any) => Encoded.Transaction;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingMinFee?: BigNumber;\n}\n\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n { onNode }: { onNode?: Node },\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode);\n if (gasPrice === 0n) return undefined;\n return gasPricePrefix + gasPrice;\n },\n\n serializeAettos(\n _value: string | undefined,\n { rebuildTx, unpackTx, buildTx, _computingMinFee }: SerializeAettosParams,\n { _canIncreaseFee }: { _canIncreaseFee?: boolean },\n ): string {\n if (_computingMinFee != null) return _computingMinFee.toFixed();\n const minFee = calculateMinFee(\n (fee) => rebuildTx({ _computingMinFee: fee }),\n unpackTx,\n buildTx,\n );\n const value =\n _value?.startsWith(gasPricePrefix) === true\n ? minFee.dividedBy(MIN_GAS_PRICE).times(_value.replace(gasPricePrefix, ''))\n : new BigNumber(_value ?? minFee);\n if (minFee.gt(value)) {\n if (_canIncreaseFee === true) return minFee.toFixed();\n throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);\n }\n return value.toFixed();\n },\n\n serialize(\n value: Parameters<typeof coinAmount.serialize>[0],\n params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams,\n options: { _canIncreaseFee?: boolean } & Parameters<typeof coinAmount.serialize>[2],\n ): Buffer {\n if (typeof value === 'string' && value.startsWith(gasPricePrefix)) {\n return uInt.serialize(this.serializeAettos(value, params, options));\n }\n return coinAmount.serialize.call(this, value, params, options);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,0BAA0B;AAC9E,SAAcC,aAAa,EAAEC,GAAG,QAAQ,iBAAiB;AACzD,OAAOC,IAAI,MAAM,YAAY;AAC7B,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,0BAA0B,QAAQ,gBAAgB;AAC3D,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,MAAM,QAAiB,2BAA2B;AAI3D,MAAMC,QAAQ,GAAG,KAAK;AACtB,MAAMC,YAAY,GAAG,EAAE;AACvB,MAAMC,kBAAkB,GAAG,CAAC;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAIC,MAAW,IAAa;EAAA,IAAAC,WAAA;EAC3C,MAAMC,UAAU,GAAG;IACjB,CAACZ,GAAG,CAACa,sBAAsB,GAAG,EAAE;IAChC,CAACb,GAAG,CAACc,iBAAiB,GAAG,CAAC;IAC1B,CAACd,GAAG,CAACe,gB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M,CAAC;IACrC,IAAIA,MAAM,CAACI,EAAE,CAACb,KAAK,CAAC,EAAE;MACpB,IAAIO,eAAe,KAAK,IAAI,EAAE,OAAOE,MAAM,CAACD,OAAO,CAAC,CAAC;MACrD,MAAM,IAAI9D,oBAAoB,CAAC,OAAOsD,KAAK,CAACc,QAAQ,CAAC,CAAC,wBAAwBL,MAAM,EAAE,CAAC;IACzF;IACA,OAAOT,KAAK,CAACQ,OAAO,CAAC,CAAC;EACxB,CAAC;EAEDO,SAASA,CACPf,KAAiD,EACjDnB,MAA0E,EAC1EmC,OAAmF,EAC3E;IACR,IAAI,OAAOhB,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACU,UAAU,CAACZ,cAAc,CAAC,EAAE;MACjE,OAAOjD,IAAI,CAACkE,SAAS,CAAC,IAAI,CAACX,eAAe,CAACJ,KAAK,EAAEnB,MAAM,EAAEmC,OAAO,CAAC,CAAC;IACrE;IACA,OAAOlE,UAAU,CAACiE,SAAS,CAACE,IAAI,CAAC,IAAI,EAAEjB,KAAK,EAAEnB,MAAM,EAAEmC,OAAO,CAAC;EAChE;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"fee.js","names":["BigNumber","ArgumentError","IllegalArgumentError","InternalError","Tag","defaultProtocolParameters","maxOf","uInt","coinAmount","getCachedIncreasedGasPrice","isKeyOfObject","serializeAsIsParam","decode","getTxBaseGas","txObject","protocolParameters","tag","byAbiVersion","contractTxBaseGas","_txObject$ctVersion$a","abiVersion","ctVersion","gas","Object","prototype","hasOwnProperty","call","undefined","knownAbiVersions","values","length","txBaseGas","getTxOtherGas","txType","txSize","relativeTtl","innerTxSize","gasPerByte","isMeta","GaMetaTx","PayingForTx","sizeGas","stateGas","stateGasPerBlock","Math","ceil","part","whole","getOracleRelativeTtl","params","ttlKeys","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleRespondTx","buildGas","builtTx","unpackTx","buildTx","innerTx","tx","encodedTx","calculateMinFee","rebuildTx","minGasPrice","toString","fee","previousFee","times","eq","gasPricePrefix","prepare","value","onNode","gasPrice","serializeAettos","_value","_canIncreaseFee","_computingMinFee","toFixed","minFee","startsWith","dividedBy","replace","gt","serialize","options"],"sources":["../../../../src/tx/builder/field-types/fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { ArgumentError, IllegalArgumentError, InternalError } from '../../../utils/errors.js';\nimport { Int, Tag } from '../constants.js';\nimport {\n defaultProtocolParameters,\n maxOf,\n ProtocolParameters,\n ProtocolParametersOption,\n} from '../protocol-parameters.js';\nimport uInt from './u-int.js';\nimport coinAmount from './coin-amount.js';\nimport { getCachedIncreasedGasPrice } from './gas-price.js';\nimport { isKeyOfObject } from '../../../utils/other.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport { decode, Encoded } from '../../../utils/encoder.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\nimport Node from '../../../Node.js';\n\n/**\n * Get the base gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txObject - The unpacked transaction\n * @param protocolParameters - The protocol parameters\n * @returns The base gas\n */\nfunction getTxBaseGas(txObject: any, protocolParameters: ProtocolParameters): number {\n const { tag }: { tag: Tag } = txObject;\n const byAbiVersion = protocolParameters.contractTxBaseGas[tag];\n if (byAbiVersion != null) {\n const abiVersion = txObject.ctVersion?.abiVersion ?? txObject.abiVersion;\n // read only what the checks in `protocol-parameters.ts` iterate, so that the two can't\n // disagree about what the parameters hold — anything inherited is not a base gas\n const gas = Object.prototype.hasOwnProperty.call(byAbiVersion, abiVersion)\n ? byAbiVersion[abiVersion as keyof typeof byAbiVersion]\n : undefined;\n if (gas != null) return gas;\n // node charges the maximum base gas for an abi version it doesn't know\n const knownAbiVersions = Object.values(byAbiVersion);\n // the maximum of nothing is `-Infinity`, fall through to `txBaseGas` instead\n if (knownAbiVersions.length !== 0) return maxOf(knownAbiVersions);\n }\n const gas = protocolParameters.txBaseGas[tag];\n if (gas == null) throw new InternalError(`Base gas of ${Tag[tag]} is not known`);\n return gas;\n}\n\n/**\n * Calculate gas for other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @param parameters - The transaction parameters\n * @param parameters.relativeTtl - The relative ttl\n * @param parameters.innerTxSize - The size of the inner transaction\n * @param protocolParameters - The protocol parameters\n * @returns The other gas\n */\nfunction getTxOtherGas(\n txType: Tag,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number; innerTxSize: number },\n protocolParameters: ProtocolParameters,\n): number {\n const { gasPerByte } = protocolParameters;\n // the inner transaction of a meta transaction pays for its own bytes in its own fee. The\n // deduction is separate from the state gas below: node reporting a state gas fraction for\n // `GaMetaTx`/`PayingForTx` must not cancel it — that would charge the inner transaction twice\n const isMeta = txType === Tag.GaMetaTx || txType === Tag.PayingForTx;\n const sizeGas = (isMeta ? txSize - innerTxSize : txSize) * gasPerByte;\n // oracle transactions pay a state rent for the time their entry occupies the state tree\n const stateGas = protocolParameters.stateGasPerBlock[txType];\n if (stateGas == null) return sizeGas;\n return sizeGas + Math.ceil((stateGas.part * relativeTtl) / stateGas.whole);\n}\n\nfunction getOracleRelativeTtl(params: any): number {\n const ttlKeys = {\n [Tag.OracleRegisterTx]: 'oracleTtlValue',\n [Tag.OracleExtendTx]: 'oracleTtlValue',\n [Tag.OracleQueryTx]: 'queryTtlValue',\n [Tag.OracleRespondTx]: 'responseTtlValue',\n } as const;\n\n const { tag } = params;\n if (!isKeyOfObject(tag, ttlKeys)) return 1;\n return params[ttlKeys[tag]];\n}\n\n/**\n * Calculate gas based on tx type and params\n */\nexport function buildGas(\n builtTx: Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): number {\n const { length } = decode(builtTx);\n const txObject = unpackTx(builtTx);\n\n let innerTxSize = 0;\n if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {\n // this rebuild only measures the size of an already signed inner transaction, its values are\n // serialized as they are — see `serializeAsIsParam`\n const innerTx = { ...txObject.tx.encodedTx, [serializeAsIsParam]: true };\n innerTxSize = decode(buildTx(innerTx as Parameters<typeof buildTx>[0])).length;\n }\n\n return (\n getTxBaseGas(txObject, protocolParameters) +\n getTxOtherGas(\n txObject.tag,\n length,\n { relativeTtl: getOracleRelativeTtl(txObject), innerTxSize },\n protocolParameters,\n )\n );\n}\n\n/**\n * Calculate min fee\n * @category transaction builder\n * @param rebuildTx - Callback to get built transaction with specific fee\n */\nfunction calculateMinFee(\n rebuildTx: (value: BigNumber) => Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): BigNumber {\n const minGasPrice = new BigNumber(protocolParameters.minGasPrice.toString());\n let fee = new BigNumber(0);\n let previousFee;\n do {\n previousFee = fee;\n fee = minGasPrice.times(buildGas(rebuildTx(fee), unpackTx, buildTx, protocolParameters));\n } while (!fee.eq(previousFee));\n return fee;\n}\n\n// TODO: Get rid of this workaround. Transaction builder can't accept/return gas price instead of\n// fee because it may get a decimal gas price. So, it should accept the optional `gasPrice` even\n// if it is not a contract-related transaction. And use this `gasPrice` to calculate `fee`.\nconst gasPricePrefix = '_gas-price:';\n\nexport interface SerializeAettosParams extends SerializeAsIsParams {\n rebuildTx: (params: any) => Encoded.Transaction;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingMinFee?: BigNumber;\n}\n\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n { onNode, protocolParameters }: { onNode?: Node } & ProtocolParametersOption,\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);\n if (gasPrice === 0n) return undefined;\n return gasPricePrefix + gasPrice;\n },\n\n serializeAettos(\n _value: string | undefined,\n params: SerializeAettosParams,\n {\n _canIncreaseFee,\n protocolParameters = defaultProtocolParameters,\n }: { _canIncreaseFee?: boolean } & ProtocolParametersOption,\n ): string {\n const { rebuildTx, unpackTx, buildTx, _computingMinFee } = params;\n if (_computingMinFee != null) return _computingMinFee.toFixed();\n if (params[serializeAsIsParam] === true && _value != null)\n return new BigNumber(_value).toFixed();\n const minFee = calculateMinFee(\n (fee) => rebuildTx({ _computingMinFee: fee }),\n unpackTx,\n buildTx,\n protocolParameters,\n );\n const value =\n _value?.startsWith(gasPricePrefix) === true\n ? minFee\n .dividedBy(protocolParameters.minGasPrice.toString())\n .times(_value.replace(gasPricePrefix, ''))\n : new BigNumber(_value ?? minFee);\n if (minFee.gt(value)) {\n if (_canIncreaseFee === true) return minFee.toFixed();\n throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);\n }\n return value.toFixed();\n },\n\n serialize(\n value: Parameters<typeof coinAmount.serialize>[0],\n params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams,\n options: { _canIncreaseFee?: boolean } & ProtocolParametersOption &\n Parameters<typeof coinAmount.serialize>[2],\n ): Buffer {\n if (typeof value === 'string' && value.startsWith(gasPricePrefix)) {\n return uInt.serialize(this.serializeAettos(value, params, options));\n }\n return coinAmount.serialize.call(this, value, params, options);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,aAAa,QAAQ,0BAA0B;AAC7F,SAAcC,GAAG,QAAQ,iBAAiB;AAC1C,SACEC,yBAAyB,EACzBC,KAAK,QAGA,2BAA2B;AAClC,OAAOC,IAAI,MAAM,YAAY;AAC7B,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,0BAA0B,QAAQ,gBAAgB;AAC3D,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,kBAAkB,QAA6B,gBAAgB;AACxE,SAASC,MAAM,QAAiB,2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AAC,EAAE;MACpB,IAAIK,eAAe,KAAK,IAAI,EAAE,OAAOG,MAAM,CAACD,OAAO,CAAC,CAAC;MACrD,MAAM,IAAI7E,oBAAoB,CAAC,OAAOsE,KAAK,CAACP,QAAQ,CAAC,CAAC,wBAAwBe,MAAM,EAAE,CAAC;IACzF;IACA,OAAOR,KAAK,CAACO,OAAO,CAAC,CAAC;EACxB,CAAC;EAEDM,SAASA,CACPb,KAAiD,EACjDvB,MAA0E,EAC1EqC,OAC4C,EACpC;IACR,IAAI,OAAOd,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACS,UAAU,CAACX,cAAc,CAAC,EAAE;MACjE,OAAO/D,IAAI,CAAC8E,SAAS,CAAC,IAAI,CAACV,eAAe,CAACH,KAAK,EAAEvB,MAAM,EAAEqC,OAAO,CAAC,CAAC;IACrE;IACA,OAAO9E,UAAU,CAAC6E,SAAS,CAAC3D,IAAI,CAAC,IAAI,EAAE8C,KAAK,EAAEvB,MAAM,EAAEqC,OAAO,CAAC;EAChE;AACF,CAAC","ignoreList":[]}
@@ -1,15 +1,17 @@
1
1
  import { Tag } from '../constants.js';
2
+ import { ProtocolParametersOption } from '../protocol-parameters.js';
3
+ import { SerializeAsIsParams } from './interface.js';
2
4
  import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';
3
5
  declare const _default: {
4
- serialize(_value: number | undefined, { tag, rebuildTx, unpackTx, buildTx, _computingGasLimit, }: {
6
+ serialize(_value: number | undefined, params: {
5
7
  tag: Tag;
6
8
  rebuildTx: (params: any) => any;
7
9
  unpackTx: typeof unpackTxType;
8
10
  buildTx: typeof buildTxType;
9
11
  _computingGasLimit?: number;
10
- }, { gasMax }: {
12
+ } & SerializeAsIsParams, { gasMax, protocolParameters, }: {
11
13
  gasMax?: number;
12
- }): Buffer;
14
+ } & ProtocolParametersOption): Buffer;
13
15
  deserialize(value: Buffer): number;
14
16
  };
15
17
  export default _default;
@@ -1,27 +1,38 @@
1
1
  import { IllegalArgumentError } from '../../../utils/errors.js';
2
- import { Tag, MAX_AUTH_FUN_GAS } from '../constants.js';
2
+ import { Tag } from '../constants.js';
3
+ import { defaultProtocolParameters, getGasLimitDivisor } from '../protocol-parameters.js';
3
4
  import shortUInt from './short-u-int.js';
4
5
  import { buildGas } from './fee.js';
5
- function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx) {
6
- return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx);
6
+ import { serializeAsIsParam } from './interface.js';
7
+ function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx, protocolParameters) {
8
+ return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx, protocolParameters);
7
9
  }
8
10
  export default {
9
11
  ...shortUInt,
10
- serialize(_value, {
11
- tag,
12
- rebuildTx,
13
- unpackTx,
14
- buildTx,
15
- _computingGasLimit
16
- }, {
17
- gasMax = 6e6
12
+ serialize(_value, params, {
13
+ gasMax,
14
+ protocolParameters = defaultProtocolParameters
18
15
  }) {
16
+ const {
17
+ tag,
18
+ rebuildTx,
19
+ unpackTx,
20
+ buildTx,
21
+ _computingGasLimit
22
+ } = params;
19
23
  if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);
20
- const gasLimitMax = tag === Tag.GaMetaTx ? MAX_AUTH_FUN_GAS : calculateGasLimitMax(gasMax, gasLimit => rebuildTx({
24
+ if (params[serializeAsIsParam] === true && _value != null) return shortUInt.serialize(_value);
25
+ const gasLimitMax = tag === Tag.GaMetaTx ? protocolParameters.maxAuthFunGas : calculateGasLimitMax(gasMax !== null && gasMax !== void 0 ? gasMax : protocolParameters.blockGasLimit, gasLimit => rebuildTx({
21
26
  _computingGasLimit: gasLimit,
22
27
  _canIncreaseFee: true
23
- }), unpackTx, buildTx);
24
- const value = _value !== null && _value !== void 0 ? _value : gasLimitMax;
28
+ }), unpackTx, buildTx, protocolParameters);
29
+ // node raises the ceiling above through the parameter this tag reads, so the value defaulted
30
+ // here is lowered by that raise — see `getGasLimitDivisor`. Only the default: a caller passing
31
+ // `gasLimit`, or capping it with `gasMax`, chose it itself — except on `GaMetaTx`, whose
32
+ // ceiling is `maxAuthFunGas` and never reads `gasMax`
33
+ const capped = gasMax != null && tag !== Tag.GaMetaTx;
34
+ const raise = capped ? 1 : getGasLimitDivisor(protocolParameters, tag);
35
+ const value = _value !== null && _value !== void 0 ? _value : raise > 1 ? Math.floor(gasLimitMax / raise) : gasLimitMax;
25
36
  if (value > gasLimitMax) {
26
37
  throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);
27
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gas-limit.js","names":["IllegalArgumentError","Tag","MAX_AUTH_FUN_GAS","shortUInt","buildGas","calculateGasLimitMax","gasMax","rebuildTx","unpackTx","buildTx","serialize","_value","tag","_computingGasLimit","gasLimitMax","GaMetaTx","gasLimit","_canIncreaseFee","value"],"sources":["../../../../src/tx/builder/field-types/gas-limit.ts"],"sourcesContent":["import { IllegalArgumentError } from '../../../utils/errors.js';\nimport { Tag, MAX_AUTH_FUN_GAS } from '../constants.js';\nimport shortUInt from './short-u-int.js';\nimport { buildGas } from './fee.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nfunction calculateGasLimitMax(\n gasMax: number,\n rebuildTx: (value: number) => any,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): number {\n return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx);\n}\n\nexport default {\n ...shortUInt,\n\n serialize(\n _value: number | undefined,\n {\n tag,\n rebuildTx,\n unpackTx,\n buildTx,\n _computingGasLimit,\n }: {\n tag: Tag;\n rebuildTx: (params: any) => any;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingGasLimit?: number;\n },\n { gasMax = 6e6 }: { gasMax?: number },\n ): Buffer {\n if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);\n\n const gasLimitMax =\n tag === Tag.GaMetaTx\n ? MAX_AUTH_FUN_GAS\n : calculateGasLimitMax(\n gasMax,\n (gasLimit) => rebuildTx({ _computingGasLimit: gasLimit, _canIncreaseFee: true }),\n unpackTx,\n buildTx,\n );\n const value = _value ?? gasLimitMax;\n if (value > gasLimitMax) {\n throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);\n }\n return shortUInt.serialize(value);\n },\n};\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,0BAA0B;AAC/D,SAASC,GAAG,EAAEC,gBAAgB,QAAQ,iBAAiB;AACvD,OAAOC,SAAS,MAAM,kBAAkB;AACxC,SAASC,QAAQ,QAAQ,UAAU;AAGnC,SAASC,oBAAoBA,CAC3BC,MAAc,EACdC,SAAiC,EACjCC,QAA6B,EAC7BC,OAA2B,EACnB;EACR,OAAOH,MAAM,GAAG,CAACF,QAAQ,CAACG,SAAS,CAACD,MAAM,CAAC,EAAEE,QAAQ,EAAEC,OAAO,CAAC;AACjE;AAEA,eAAe;EACb,GAAGN,SAAS;EAEZO,SAASA,CACPC,MAA0B,EAC1B;IACEC,GAAG;IACHL,SAAS;IACTC,QAAQ;IACRC,OAAO;IACPI;EAOF,CAAC,EACD;IAAEP,MAAM,GAAG;EAAyB,CAAC,EAC7B;IACR,IAAIO,kBAAkB,IAAI,IAAI,EAAE,OAAOV,SAAS,CAACO,SAAS,CAACG,kBAAkB,CAAC;IAE9E,MAAMC,WAAW,GACfF,GAAG,KAAKX,GAAG,CAACc,QAAQ,GAChBb,gBAAgB,GAChBG,oBAAoB,CAClBC,MAAM,EACLU,QAAQ,IAAKT,SAAS,CAAC;MAAEM,kBAAkB,EAAEG,QAAQ;MAAEC,eAAe,EAAE;IAAK,CAAC,CAAC,EAChFT,QAAQ,EACRC,OACF,CAAC;IACP,MAAMS,KAAK,GAAGP,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIG,WAAW;IACnC,IAAII,KAAK,GAAGJ,WAAW,EAAE;MACvB,MAAM,IAAId,oBAAoB,CAAC,aAAakB,KAAK,6BAA6BJ,WAAW,EAAE,CAAC;IAC9F;IACA,OAAOX,SAAS,CAACO,SAAS,CAACQ,KAAK,CAAC;EACnC;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"gas-limit.js","names":["IllegalArgumentError","Tag","defaultProtocolParameters","getGasLimitDivisor","shortUInt","buildGas","serializeAsIsParam","calculateGasLimitMax","gasMax","rebuildTx","unpackTx","buildTx","protocolParameters","serialize","_value","params","tag","_computingGasLimit","gasLimitMax","GaMetaTx","maxAuthFunGas","blockGasLimit","gasLimit","_canIncreaseFee","capped","raise","value","Math","floor"],"sources":["../../../../src/tx/builder/field-types/gas-limit.ts"],"sourcesContent":["import { IllegalArgumentError } from '../../../utils/errors.js';\nimport { Tag } from '../constants.js';\nimport {\n defaultProtocolParameters,\n getGasLimitDivisor,\n ProtocolParameters,\n ProtocolParametersOption,\n} from '../protocol-parameters.js';\nimport shortUInt from './short-u-int.js';\nimport { buildGas } from './fee.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nfunction calculateGasLimitMax(\n gasMax: number,\n rebuildTx: (value: number) => any,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): number {\n return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx, protocolParameters);\n}\n\nexport default {\n ...shortUInt,\n\n serialize(\n _value: number | undefined,\n params: {\n tag: Tag;\n rebuildTx: (params: any) => any;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingGasLimit?: number;\n } & SerializeAsIsParams,\n {\n gasMax,\n protocolParameters = defaultProtocolParameters,\n }: { gasMax?: number } & ProtocolParametersOption,\n ): Buffer {\n const { tag, rebuildTx, unpackTx, buildTx, _computingGasLimit } = params;\n if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);\n if (params[serializeAsIsParam] === true && _value != null) return shortUInt.serialize(_value);\n\n const gasLimitMax =\n tag === Tag.GaMetaTx\n ? protocolParameters.maxAuthFunGas\n : calculateGasLimitMax(\n gasMax ?? protocolParameters.blockGasLimit,\n (gasLimit) => rebuildTx({ _computingGasLimit: gasLimit, _canIncreaseFee: true }),\n unpackTx,\n buildTx,\n protocolParameters,\n );\n // node raises the ceiling above through the parameter this tag reads, so the value defaulted\n // here is lowered by that raise — see `getGasLimitDivisor`. Only the default: a caller passing\n // `gasLimit`, or capping it with `gasMax`, chose it itself — except on `GaMetaTx`, whose\n // ceiling is `maxAuthFunGas` and never reads `gasMax`\n const capped = gasMax != null && tag !== Tag.GaMetaTx;\n const raise = capped ? 1 : getGasLimitDivisor(protocolParameters, tag);\n const value = _value ?? (raise > 1 ? Math.floor(gasLimitMax / raise) : gasLimitMax);\n if (value > gasLimitMax) {\n throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);\n }\n return shortUInt.serialize(value);\n },\n};\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,0BAA0B;AAC/D,SAASC,GAAG,QAAQ,iBAAiB;AACrC,SACEC,yBAAyB,EACzBC,kBAAkB,QAGb,2BAA2B;AAClC,OAAOC,SAAS,MAAM,kBAAkB;AACxC,SAASC,QAAQ,QAAQ,UAAU;AACnC,SAASC,kBAAkB,QAA6B,gBAAgB;AAGxE,SAASC,oBAAoBA,CAC3BC,MAAc,EACdC,SAAiC,EACjCC,QAA6B,EAC7BC,OAA2B,EAC3BC,kBAAsC,EAC9B;EACR,OAAOJ,MAAM,GAAG,CAACH,QAAQ,CAACI,SAAS,CAACD,MAAM,CAAC,EAAEE,QAAQ,EAAEC,OAAO,EAAEC,kBAAkB,CAAC;AACrF;AAEA,eAAe;EACb,GAAGR,SAAS;EAEZS,SAASA,CACPC,MAA0B,EAC1BC,MAMuB,EACvB;IACEP,MAAM;IACNI,kBAAkB,GAAGV;EACyB,CAAC,EACzC;IACR,MAAM;MAAEc,GAAG;MAAEP,SAAS;MAAEC,QAAQ;MAAEC,OAAO;MAAEM;IAAmB,CAAC,GAAGF,MAAM;IACxE,IAAIE,kBAAkB,IAAI,IAAI,EAAE,OAAOb,SAAS,CAACS,SAAS,CAACI,kBAAkB,CAAC;IAC9E,IAAIF,MAAM,CAACT,kBAAkB,CAAC,KAAK,IAAI,IAAIQ,MAAM,IAAI,IAAI,EAAE,OAAOV,SAAS,CAACS,SAAS,CAACC,MAAM,CAAC;IAE7F,MAAMI,WAAW,GACfF,GAAG,KAAKf,GAAG,CAACkB,QAAQ,GAChBP,kBAAkB,CAACQ,aAAa,GAChCb,oBAAoB,CAClBC,MAAM,aAANA,MAAM,cAANA,MAAM,GAAII,kBAAkB,CAACS,aAAa,EACzCC,QAAQ,IAAKb,SAAS,CAAC;MAAEQ,kBAAkB,EAAEK,QAAQ;MAAEC,eAAe,EAAE;IAAK,CAAC,CAAC,EAChFb,QAAQ,EACRC,OAAO,EACPC,kBACF,CAAC;IACP;IACA;IACA;IACA;IACA,MAAMY,MAAM,GAAGhB,MAAM,IAAI,IAAI,IAAIQ,GAAG,KAAKf,GAAG,CAACkB,QAAQ;IACrD,MAAMM,KAAK,GAAGD,MAAM,GAAG,CAAC,GAAGrB,kBAAkB,CAACS,kBAAkB,EAAEI,GAAG,CAAC;IACtE,MAAMU,KAAK,GAAGZ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAKW,KAAK,GAAG,CAAC,GAAGE,IAAI,CAACC,KAAK,CAACV,WAAW,GAAGO,KAAK,CAAC,GAAGP,WAAY;IACnF,IAAIQ,KAAK,GAAGR,WAAW,EAAE;MACvB,MAAM,IAAIlB,oBAAoB,CAAC,aAAa0B,KAAK,6BAA6BR,WAAW,EAAE,CAAC;IAC9F;IACA,OAAOd,SAAS,CAACS,SAAS,CAACa,KAAK,CAAC;EACnC;AACF,CAAC","ignoreList":[]}
@@ -1,16 +1,18 @@
1
1
  import { Int } from '../constants.js';
2
+ import { ProtocolParameters, ProtocolParametersOption } from '../protocol-parameters.js';
3
+ import { SerializeAsIsParams } from './interface.js';
2
4
  import Node from '../../../Node.js';
3
5
  import { AE_AMOUNT_FORMATS } from '../../../utils/amount-formatter.js';
4
- export declare function getCachedIncreasedGasPrice(node: Node): Promise<bigint>;
6
+ export declare function getCachedIncreasedGasPrice(nodeOrProxy: Node, parameters?: ProtocolParameters): Promise<bigint>;
5
7
  declare const _default: {
6
- prepare(value: Int | undefined, params: {}, { onNode, denomination, }: {
8
+ prepare(value: Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
7
9
  onNode?: Node;
8
10
  /**
9
11
  * @deprecated no replacement implemented yet
10
12
  */
11
13
  denomination?: AE_AMOUNT_FORMATS;
12
- }): Promise<Int | undefined>;
13
- serializeAettos(value?: string | undefined): string;
14
+ } & ProtocolParametersOption): Promise<Int | undefined>;
15
+ serializeAettos(value: string | undefined, params: SerializeAsIsParams, { protocolParameters }: ProtocolParametersOption): string;
14
16
  serialize(value: Int | undefined, params: {}, { denomination, ...options }: {
15
17
  denomination?: AE_AMOUNT_FORMATS;
16
18
  }): Buffer;