@leofcoin/lib 1.3.7 → 1.3.9

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.
@@ -24,9 +24,45 @@ export declare const contractFactoryMessage: string;
24
24
  export declare const nativeTokenMessage: string;
25
25
  export declare const nameServiceMessage: string;
26
26
  export declare const validatorsMessage: string;
27
+ export declare const TRANSACTION_FEE_BYTES = 1024n;
28
+ export declare const TRANSACTION_FEE_UNIT = 10n;
29
+ export declare const MAX_TRANSACTION_BYTES: number;
30
+ export declare const MAX_BLOCK_TRANSACTION_BYTES: number;
31
+ export declare const MAX_BLOCK_TRANSACTIONS = 256;
32
+ export declare const MAX_TRANSACTION_FEE: bigint;
33
+ export declare const FEE_BASIS_POINTS = 10000n;
34
+ export declare const FEE_PROTOCOL_VERSION = "1.10.9";
35
+ export declare const MONETARY_POLICY_PROTOCOL_VERSION = "1.10.10";
36
+ export declare const BLOCKS_PER_YEAR = 5256000n;
37
+ export declare const ANNUAL_ISSUANCE_BASIS_POINTS = 200n;
38
+ export declare const SUPPLY_FLOOR_BASIS_POINTS = 9500n;
39
+ export declare const MONETARY_FEE_BURN_BASIS_POINTS = 1000n;
40
+ export declare const supportsTransactionFees: (version: string) => boolean;
41
+ export declare const supportsMonetaryPolicy: (version: string) => boolean;
42
+ export declare const calculateMonetaryPolicy: (totalSupply: bigint, targetSupply: bigint) => {
43
+ subsidy: bigint;
44
+ burnBasisPoints: bigint;
45
+ floorSupply: bigint;
46
+ };
47
+ export declare const distributeAmount: (amount: bigint, addresses: string[], rotation?: number) => Map<string, bigint>;
48
+ export type FeePayment = {
49
+ to: string;
50
+ amount: bigint;
51
+ };
52
+ export declare const distributeTransactionFee: (fee: bigint, transactionHash: string, validatorAddresses: string[], burnBasisPoints?: bigint) => {
53
+ burned: bigint;
54
+ validatorFees: Map<string, bigint>;
55
+ payments: FeePayment[];
56
+ };
57
+ export declare const aggregateValidatorFees: (fees: Array<{
58
+ fee: bigint;
59
+ transactionHash: string;
60
+ }>, validatorAddresses: string[], burnBasisPoints?: bigint) => Map<string, bigint>;
27
61
  export declare const createContractMessage: (creator: any, contract: any, constructorParameters?: never[]) => Promise<ContractMessage>;
28
- export declare const calculateFee: (transaction: any, format?: boolean) => Promise<string | bigint | 0>;
29
- export declare const calculateTransactionFee: (transaction: any) => Promise<string | bigint | 0>;
62
+ export declare const calculateFee: (transaction: any, format?: boolean) => Promise<string | bigint>;
63
+ export declare const validateTransactionResourceLimits: (transaction: any) => Promise<number>;
64
+ export declare const validateBlockResourceLimits: (transactions: any) => Promise<number>;
65
+ export declare const calculateTransactionFee: (transaction: any) => Promise<string | bigint>;
30
66
  export declare const calculateReward: (validators: any, fees: any) => [];
31
67
  export declare const createTransactionHash: (transaction: rawTransaction | TransactionMessage | RawTransactionMessage) => Promise<Uint8Array>;
32
68
  export declare const signTransaction: (transaction: rawTransaction, wallet: signable) => Promise<signedTransaction>;
package/exports/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { TransactionMessage, ContractMessage, RawTransactionMessage } from '@leofcoin/messages';
2
- import { validators as validators$1, contractFactory as contractFactory$1 } from '@leofcoin/addresses';
2
+ import { contractFactory as contractFactory$1 } from '@leofcoin/addresses';
3
3
  export { default as nodeConfig } from './node-config.js';
4
- import { toBigInt, formatUnits } from '@leofcoin/utils';
4
+ import { formatUnits } from '@leofcoin/utils';
5
5
  import { toBase58 } from '@vandeurenglenn/typed-array-utils';
6
6
 
7
7
  var contractFactory = "237,198,141,3,53,89,84,113,119,81,55,65,87,55,69,83,77,66,56,106,115,74,80,84,88,116,97,99,84,89,122,75,84,74,51,51,122,120,118,77,69,65,115,78,103,77,97,66,99,98,55,53,52,122,122,49,99,65,230,50,99,108,97,115,115,32,77,101,116,97,123,35,99,114,101,97,116,111,114,59,35,99,114,101,97,116,101,100,65,116,61,66,105,103,73,110,116,40,68,97,116,101,46,110,111,119,40,41,41,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,63,40,116,104,105,115,46,35,99,114,101,97,116,111,114,61,115,116,97,116,101,46,99,114,101,97,116,111,114,44,116,104,105,115,46,35,99,114,101,97,116,101,100,65,116,61,115,116,97,116,101,46,99,114,101,97,116,101,100,65,116,41,58,40,116,104,105,115,46,35,99,114,101,97,116,111,114,61,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,99,114,101,97,116,101,100,65,116,61,66,105,103,73,110,116,40,68,97,116,101,46,110,111,119,40,41,41,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,99,114,101,97,116,111,114,58,116,104,105,115,46,35,99,114,101,97,116,111,114,44,99,114,101,97,116,101,100,65,116,58,116,104,105,115,46,35,99,114,101,97,116,101,100,65,116,125,125,103,101,116,32,99,114,101,97,116,111,114,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,114,101,97,116,111,114,125,103,101,116,32,99,114,101,97,116,101,100,65,116,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,114,101,97,116,101,100,65,116,125,125,99,108,97,115,115,32,80,117,98,108,105,99,86,111,116,105,110,103,32,101,120,116,101,110,100,115,32,77,101,116,97,123,35,118,111,116,101,115,59,35,118,111,116,105,110,103,68,105,115,97,98,108,101,100,59,35,118,111,116,105,110,103,68,117,114,97,116,105,111,110,61,49,55,50,56,101,53,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,117,112,101,114,40,115,116,97,116,101,41,44,115,116,97,116,101,38,38,40,116,104,105,115,46,35,118,111,116,101,115,61,115,116,97,116,101,46,118,111,116,101,115,44,116,104,105,115,46,35,118,111,116,105,110,103,68,105,115,97,98,108,101,100,61,115,116,97,116,101,46,118,111,116,105,110,103,68,105,115,97,98,108,101,100,41,125,103,101,116,32,118,111,116,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,118,111,116,101,115,125,125,103,101,116,32,118,111,116,105,110,103,68,117,114,97,116,105,111,110,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,118,111,116,105,110,103,68,117,114,97,116,105,111,110,125,103,101,116,32,118,111,116,105,110,103,68,105,115,97,98,108,101,100,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,118,111,116,105,110,103,68,105,115,97,98,108,101,100,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,118,111,116,101,115,58,116,104,105,115,46,35,118,111,116,101,115,44,118,111,116,105,110,103,68,105,115,97,98,108,101,100,58,116,104,105,115,46,35,118,111,116,105,110,103,68,105,115,97,98,108,101,100,44,118,111,116,105,110,103,68,117,114,97,116,105,111,110,58,116,104,105,115,46,35,118,111,116,105,110,103,68,117,114,97,116,105,111,110,125,125,103,101,116,32,105,110,80,114,111,103,114,101,115,115,40,41,123,114,101,116,117,114,110,32,79,98,106,101,99,116,46,101,110,116,114,105,101,115,40,116,104,105,115,46,35,118,111,116,101,115,41,46,102,105,108,116,101,114,40,40,91,105,100,44,118,111,116,101,93,41,61,62,33,118,111,116,101,46,102,105,110,105,115,104,101,100,41,46,109,97,112,40,40,91,105,100,44,118,111,116,101,93,41,61,62,40,123,46,46,46,118,111,116,101,44,105,100,58,105,100,125,41,41,125,99,114,101,97,116,101,86,111,116,101,40,116,105,116,108,101,44,100,101,115,99,114,105,112,116,105,111,110,44,101,110,100,84,105,109,101,44,109,101,116,104,111,100,44,97,114,103,115,61,91,93,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,32,116,111,32,99,114,101,97,116,101,32,97,32,118,111,116,101,34,41,59,99,111,110,115,116,32,105,100,61,99,114,121,112,116,111,46,114,97,110,100,111,109,85,85,73,68,40,41,59,116,104,105,115,46,35,118,111,116,101,115,91,105,100,93,61,123,116,105,116,108,101,58,116,105,116,108,101,44,100,101,115,99,114,105,112,116,105,111,110,58,100,101,115,99,114,105,112,116,105,111,110,44,109,101,116,104,111,100,58,109,101,116,104,111,100,44,101,110,100,84,105,109,101,58,101,110,100,84,105,109,101,44,97,114,103,115,58,97,114,103,115,125,125,35,99,97,110,86,111,116,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,95,99,97,110,86,111,116,101,63,46,40,41,125,35,98,101,102,111,114,101,86,111,116,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,95,98,101,102,111,114,101,86,111,116,101,63,46,40,41,125,35,101,110,100,86,111,116,105,110,103,40,118,111,116,101,73,100,41,123,108,101,116,32,97,103,114,101,101,61,79,98,106,101,99,116,46,118,97,108,117,101,115,40,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,114,101,115,117,108,116,115,41,46,102,105,108,116,101,114,40,114,101,115,117,108,116,61,62,49,61,61,61,114,101,115,117,108,116,41,44,100,105,115,97,103,114,101,101,61,79,98,106,101,99,116,46,118,97,108,117,101,115,40,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,114,101,115,117,108,116,115,41,46,102,105,108,116,101,114,40,114,101,115,117,108,116,61,62,48,61,61,61,114,101,115,117,108,116,41,59,97,103,114,101,101,46,108,101,110,103,116,104,62,100,105,115,97,103,114,101,101,46,108,101,110,103,116,104,38,38,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,101,110,111,117,103,104,86,111,116,101,115,38,38,116,104,105,115,91,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,109,101,116,104,111,100,93,40,46,46,46,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,97,114,103,115,41,44,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,102,105,110,105,115,104,101,100,61,33,48,125,97,115,121,110,99,32,118,111,116,101,40,118,111,116,101,73,100,44,118,111,116,101,41,123,105,102,40,48,33,61,61,40,118,111,116,101,61,78,117,109,98,101,114,40,118,111,116,101,41,41,38,38,46,53,33,61,61,118,111,116,101,38,38,49,33,61,61,118,111,116,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,105,110,118,97,108,105,100,32,118,111,116,101,32,118,97,108,117,101,32,36,123,118,111,116,101,125,96,41,59,105,102,40,33,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,78,111,116,104,105,110,103,32,102,111,117,110,100,32,102,111,114,32,36,123,118,111,116,101,73,100,125,96,41,59,99,111,110,115,116,32,101,110,100,101,100,61,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,62,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,101,110,100,84,105,109,101,59,105,102,40,101,110,100,101,100,38,38,33,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,46,102,105,110,105,115,104,101,100,38,38,116,104,105,115,46,35,101,110,100,86,111,116,105,110,103,40,118,111,116,101,73,100,41,44,101,110,100,101,100,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,118,111,116,105,110,103,32,97,108,114,101,97,100,121,32,101,110,100,101,100,34,41,59,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,32,116,111,32,118,111,116,101,34,41,59,97,119,97,105,116,32,116,104,105,115,46,35,98,101,102,111,114,101,86,111,116,101,40,41,44,116,104,105,115,46,35,118,111,116,101,115,91,118,111,116,101,73,100,93,91,109,115,103,46,115,101,110,100,101,114,93,61,118,111,116,101,125,35,100,105,115,97,98,108,101,86,111,116,105,110,103,40,41,123,116,104,105,115,46,35,118,111,116,105,110,103,68,105,115,97,98,108,101,100,61,33,48,125,100,105,115,97,98,108,101,86,111,116,105,110,103,40,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,99,114,101,97,116,101,86,111,116,101,40,34,100,105,115,97,98,108,101,32,118,111,116,105,110,103,34,44,34,87,97,114,110,105,110,103,32,116,104,105,115,32,100,105,115,97,98,108,101,115,32,97,108,108,32,118,111,116,105,110,103,32,102,101,97,116,117,114,101,115,32,102,111,114,101,118,101,114,34,44,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,43,116,104,105,115,46,35,118,111,116,105,110,103,68,117,114,97,116,105,111,110,44,34,35,100,105,115,97,98,108,101,86,111,116,105,110,103,34,44,91,93,41,125,95,115,121,110,99,40,41,123,102,111,114,40,99,111,110,115,116,32,118,111,116,101,32,111,102,32,116,104,105,115,46,105,110,80,114,111,103,114,101,115,115,41,118,111,116,101,46,101,110,100,84,105,109,101,60,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,38,38,116,104,105,115,46,35,101,110,100,86,111,116,105,110,103,40,118,111,116,101,46,105,100,41,125,125,99,108,97,115,115,32,84,111,107,101,110,82,101,99,101,105,118,101,114,32,101,120,116,101,110,100,115,32,80,117,98,108,105,99,86,111,116,105,110,103,123,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,59,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,59,35,116,111,107,101,110,82,101,99,101,105,118,101,114,59,35,118,111,116,101,84,121,112,101,61,34,116,114,97,110,115,102,101,114,34,59,99,111,110,115,116,114,117,99,116,111,114,40,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,44,98,117,114,110,115,44,115,116,97,116,101,41,123,115,117,112,101,114,40,115,116,97,116,101,41,44,115,116,97,116,101,63,40,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,61,115,116,97,116,101,46,116,111,107,101,110,82,101,99,101,105,118,101,114,44,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,61,115,116,97,116,101,46,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,61,66,105,103,73,110,116,40,115,116,97,116,101,46,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,41,44,116,104,105,115,46,35,118,111,116,101,84,121,112,101,61,115,116,97,116,101,46,118,111,116,101,84,121,112,101,41,58,40,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,61,109,115,103,46,99,111,110,116,114,97,99,116,44,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,61,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,61,66,105,103,73,110,116,40,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,41,44,98,117,114,110,115,38,38,40,116,104,105,115,46,35,118,111,116,101,84,121,112,101,61,34,98,117,114,110,34,41,41,125,103,101,116,32,116,111,107,101,110,84,111,82,101,99,101,105,118,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,125,103,101,116,32,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,125,103,101,116,32,116,111,107,101,110,82,101,99,101,105,118,101,114,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,116,111,107,101,110,82,101,99,101,105,118,101,114,58,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,44,116,111,107,101,110,84,111,82,101,99,101,105,118,101,58,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,58,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,44,118,111,116,101,84,121,112,101,58,116,104,105,115,46,35,118,111,116,101,84,121,112,101,125,125,97,115,121,110,99,35,99,97,110,86,111,116,101,40,41,123,114,101,116,117,114,110,32,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,98,97,108,97,110,99,101,79,102,34,44,91,109,115,103,46,115,101,110,100,101,114,93,41,62,61,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,125,97,115,121,110,99,32,95,99,97,110,86,111,116,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,125,97,115,121,110,99,35,98,101,102,111,114,101,86,111,116,101,40,41,123,114,101,116,117,114,110,34,98,117,114,110,34,61,61,61,116,104,105,115,46,35,118,111,116,101,84,121,112,101,63,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,98,117,114,110,34,44,91,116,104,105,115,46,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,93,41,58,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,116,114,97,110,115,102,101,114,34,44,91,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,116,111,107,101,110,82,101,99,101,105,118,101,114,44,116,104,105,115,46,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,93,41,125,97,115,121,110,99,32,95,98,101,102,111,114,101,86,111,116,101,40,41,123,97,119,97,105,116,32,116,104,105,115,46,35,98,101,102,111,114,101,86,111,116,101,40,41,125,97,115,121,110,99,32,95,112,97,121,84,111,107,101,110,84,111,82,101,99,101,105,118,101,40,41,123,114,101,116,117,114,110,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,116,114,97,110,115,102,101,114,34,44,91,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,44,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,93,41,125,97,115,121,110,99,32,95,98,117,114,110,84,111,107,101,110,84,111,82,101,99,101,105,118,101,40,41,123,114,101,116,117,114,110,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,98,117,114,110,34,44,91,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,93,41,125,35,99,104,97,110,103,101,84,111,107,101,110,84,111,82,101,99,101,105,118,101,40,97,100,100,114,101,115,115,41,123,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,61,97,100,100,114,101,115,115,125,35,99,104,97,110,103,101,84,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,40,97,109,111,117,110,116,41,123,116,104,105,115,46,35,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,61,97,109,111,117,110,116,125,35,99,104,97,110,103,101,86,111,116,101,84,121,112,101,40,116,121,112,101,41,123,116,104,105,115,46,35,118,111,116,101,84,121,112,101,61,116,121,112,101,125,35,103,101,116,84,111,107,101,110,115,79,117,116,40,97,109,111,117,110,116,44,114,101,99,101,105,118,101,114,41,123,114,101,116,117,114,110,32,109,115,103,46,99,97,108,108,40,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,44,34,116,114,97,110,115,102,101,114,34,44,91,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,44,114,101,99,101,105,118,101,114,44,97,109,111,117,110,116,93,41,125,97,115,121,110,99,32,99,104,97,110,103,101,86,111,116,101,84,121,112,101,40,116,121,112,101,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,97,108,108,111,119,101,100,34,41,59,105,102,40,34,116,114,97,110,115,102,101,114,34,61,61,61,116,104,105,115,46,35,118,111,116,101,84,121,112,101,38,38,97,119,97,105,116,32,116,104,105,115,46,35,98,97,108,97,110,99,101,40,41,62,48,110,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,103,101,116,32,116,111,107,101,110,115,32,111,117,116,32,102,105,114,115,116,32,111,114,32,116,104,101,121,32,98,101,32,108,111,115,116,32,102,111,114,101,118,101,114,34,41,59,116,104,105,115,46,99,114,101,97,116,101,86,111,116,101,40,34,99,104,97,110,103,101,32,116,104,101,32,116,111,107,101,110,32,97,109,111,117,110,116,32,116,111,32,114,101,99,101,105,118,101,34,44,34,115,101,116,32,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,34,44,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,43,116,104,105,115,46,118,111,116,105,110,103,68,117,114,97,116,105,111,110,44,34,35,99,104,97,110,103,101,86,111,116,101,84,121,112,101,34,44,91,116,121,112,101,93,41,125,103,101,116,84,111,107,101,110,115,79,117,116,40,97,109,111,117,110,116,44,114,101,99,101,105,118,101,114,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,99,114,101,97,116,101,86,111,116,101,40,34,119,105,116,104,100,114,97,119,32,97,108,108,32,116,111,107,101,110,115,34,44,96,119,105,116,104,100,114,97,119,32,97,108,108,32,116,111,107,101,110,115,32,116,111,32,36,123,114,101,99,101,105,118,101,114,125,96,44,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,43,116,104,105,115,46,118,111,116,105,110,103,68,117,114,97,116,105,111,110,44,34,35,103,101,116,84,111,107,101,110,115,79,117,116,34,44,91,97,109,111,117,110,116,44,114,101,99,101,105,118,101,114,93,41,125,99,104,97,110,103,101,84,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,40,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,99,114,101,97,116,101,86,111,116,101,40,34,99,104,97,110,103,101,32,116,104,101,32,116,111,107,101,110,32,97,109,111,117,110,116,32,116,111,32,114,101,99,101,105,118,101,34,44,34,115,101,116,32,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,34,44,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,43,116,104,105,115,46,118,111,116,105,110,103,68,117,114,97,116,105,111,110,44,34,35,99,104,97,110,103,101,84,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,34,44,91,93,41,125,35,98,97,108,97,110,99,101,40,41,123,114,101,116,117,114,110,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,116,104,105,115,46,35,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,34,98,97,108,97,110,99,101,79,102,34,44,91,116,104,105,115,46,35,116,111,107,101,110,82,101,99,101,105,118,101,114,93,41,125,97,115,121,110,99,32,99,104,97,110,103,101,84,111,107,101,110,84,111,82,101,99,101,105,118,101,40,41,123,105,102,40,33,116,104,105,115,46,35,99,97,110,86,111,116,101,40,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,32,97,108,108,111,119,101,100,34,41,59,105,102,40,48,110,33,61,61,97,119,97,105,116,32,116,104,105,115,46,35,98,97,108,97,110,99,101,40,41,38,38,34,116,114,97,110,115,102,101,114,34,61,61,61,116,104,105,115,46,35,118,111,116,101,84,121,112,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,103,101,116,32,116,111,107,101,110,115,32,111,117,116,32,102,105,114,115,116,32,111,114,32,116,104,101,121,32,98,101,32,108,111,115,116,32,102,111,114,101,118,101,114,34,41,59,116,104,105,115,46,99,114,101,97,116,101,86,111,116,101,40,34,99,104,97,110,103,101,32,116,104,101,32,116,111,107,101,110,32,116,111,32,114,101,99,101,105,118,101,34,44,34,115,101,116,32,116,111,107,101,110,84,111,82,101,99,101,105,118,101,32,116,111,32,97,32,110,101,119,32,97,100,100,114,101,115,115,34,44,40,110,101,119,32,68,97,116,101,41,46,103,101,116,84,105,109,101,40,41,43,116,104,105,115,46,118,111,116,105,110,103,68,117,114,97,116,105,111,110,44,34,35,99,104,97,110,103,101,84,111,107,101,110,84,111,82,101,99,101,105,118,101,34,44,91,93,41,125,125,99,108,97,115,115,32,70,97,99,116,111,114,121,32,101,120,116,101,110,100,115,32,84,111,107,101,110,82,101,99,101,105,118,101,114,123,35,110,97,109,101,61,34,76,101,111,102,99,111,105,110,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,66,105,103,73,110,116,40,48,41,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,44,115,116,97,116,101,41,123,115,117,112,101,114,40,116,111,107,101,110,84,111,82,101,99,101,105,118,101,44,116,111,107,101,110,65,109,111,117,110,116,84,111,82,101,99,101,105,118,101,44,33,48,44,115,116,97,116,101,41,44,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,105,115,82,101,103,105,115,116,101,114,101,100,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,35,105,115,67,114,101,97,116,111,114,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,99,114,101,97,116,111,114,34,44,91,109,115,103,46,115,101,110,100,101,114,93,41,125,105,115,67,114,101,97,116,111,114,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,105,115,67,114,101,97,116,111,114,40,97,100,100,114,101,115,115,41,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,33,97,119,97,105,116,32,116,104,105,115,46,105,115,67,114,101,97,116,111,114,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,89,111,117,32,100,111,110,39,116,32,111,119,110,32,116,104,97,116,32,99,111,110,116,114,97,99,116,34,41,59,105,102,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,97,119,97,105,116,32,116,104,105,115,46,95,112,97,121,84,111,107,101,110,84,111,82,101,99,101,105,118,101,40,41,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,110,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,88,91,34,73,72,78,89,50,71,81,71,71,75,83,50,86,68,72,86,80,72,84,53,86,66,55,83,71,68,76,77,80,82,67,90,51,89,54,69,71,66,52,50,66,76,84,55,51,87,53,72,67,78,84,65,72,51,87,78,88,66,89,34,44,34,49,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,34,93";
@@ -19,6 +19,113 @@ const contractFactoryMessage = bytecodes.contractFactory;
19
19
  const nativeTokenMessage = bytecodes.nativeToken;
20
20
  const nameServiceMessage = bytecodes.nameService;
21
21
  const validatorsMessage = bytecodes.validators;
22
+ const TRANSACTION_FEE_BYTES = 1024n;
23
+ const TRANSACTION_FEE_UNIT = 10n;
24
+ const MAX_TRANSACTION_BYTES = 32 * 1024;
25
+ const MAX_BLOCK_TRANSACTION_BYTES = 128 * 1024;
26
+ const MAX_BLOCK_TRANSACTIONS = 256;
27
+ const MAX_TRANSACTION_FEE = (BigInt(MAX_TRANSACTION_BYTES) / TRANSACTION_FEE_BYTES) * TRANSACTION_FEE_UNIT;
28
+ const FEE_BASIS_POINTS = 10000n;
29
+ const FEE_PROTOCOL_VERSION = '1.10.9';
30
+ const MONETARY_POLICY_PROTOCOL_VERSION = '1.10.10';
31
+ const BLOCKS_PER_YEAR = 5256000n;
32
+ const ANNUAL_ISSUANCE_BASIS_POINTS = 200n;
33
+ const SUPPLY_FLOOR_BASIS_POINTS = 9500n;
34
+ const MONETARY_FEE_BURN_BASIS_POINTS = 1000n;
35
+ const parseProtocolVersion = (version) => {
36
+ const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
37
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : undefined;
38
+ };
39
+ const supportsTransactionFees = (version) => {
40
+ const actual = parseProtocolVersion(version);
41
+ const required = parseProtocolVersion(FEE_PROTOCOL_VERSION);
42
+ if (!actual)
43
+ return false;
44
+ for (let index = 0; index < required.length; index += 1) {
45
+ if (actual[index] !== required[index])
46
+ return actual[index] > required[index];
47
+ }
48
+ return true;
49
+ };
50
+ const supportsMonetaryPolicy = (version) => {
51
+ const actual = parseProtocolVersion(version);
52
+ const required = parseProtocolVersion(MONETARY_POLICY_PROTOCOL_VERSION);
53
+ if (!actual)
54
+ return false;
55
+ for (let index = 0; index < required.length; index += 1) {
56
+ if (actual[index] !== required[index])
57
+ return actual[index] > required[index];
58
+ }
59
+ return true;
60
+ };
61
+ const calculateMonetaryPolicy = (totalSupply, targetSupply) => {
62
+ if (totalSupply < 0n || targetSupply <= 0n)
63
+ throw new Error('invalid monetary policy supply');
64
+ const floorSupply = (targetSupply * SUPPLY_FLOOR_BASIS_POINTS) / FEE_BASIS_POINTS;
65
+ if (totalSupply < floorSupply) {
66
+ const annualIssuance = (targetSupply * ANNUAL_ISSUANCE_BASIS_POINTS) / FEE_BASIS_POINTS;
67
+ const scheduled = annualIssuance / BLOCKS_PER_YEAR || 1n;
68
+ return { subsidy: scheduled < floorSupply - totalSupply ? scheduled : floorSupply - totalSupply, burnBasisPoints: 0n, floorSupply };
69
+ }
70
+ return {
71
+ subsidy: 0n,
72
+ burnBasisPoints: totalSupply >= targetSupply ? MONETARY_FEE_BURN_BASIS_POINTS : 0n,
73
+ floorSupply
74
+ };
75
+ };
76
+ const distributeAmount = (amount, addresses, rotation = 0) => {
77
+ const canonical = [...new Set(addresses)].sort();
78
+ if (canonical.length === 0)
79
+ throw new Error('cannot distribute without validators');
80
+ const count = BigInt(canonical.length);
81
+ const base = amount / count;
82
+ const remainder = Number(amount % count);
83
+ const result = new Map(canonical.map((address) => [address, base]));
84
+ for (let index = 0; index < remainder; index += 1) {
85
+ const address = canonical[(rotation + index) % canonical.length];
86
+ result.set(address, result.get(address) + 1n);
87
+ }
88
+ return result;
89
+ };
90
+ const feeRotationIndex = (transactionHash, validatorCount) => {
91
+ let value = 0n;
92
+ for (const character of transactionHash)
93
+ value = (value * 31n + BigInt(character.charCodeAt(0))) % 4294967291n;
94
+ return Number(value % BigInt(validatorCount));
95
+ };
96
+ const distributeTransactionFee = (fee, transactionHash, validatorAddresses, burnBasisPoints = 1000n) => {
97
+ const canonicalValidators = [...new Set(validatorAddresses)].sort();
98
+ if (canonicalValidators.length === 0)
99
+ throw new Error('cannot distribute transaction fee without validators');
100
+ if (fee < 0n)
101
+ throw new Error('transaction fee cannot be negative');
102
+ if (burnBasisPoints < 0n || burnBasisPoints > FEE_BASIS_POINTS)
103
+ throw new Error('invalid fee burn rate');
104
+ const burned = (fee * burnBasisPoints) / FEE_BASIS_POINTS;
105
+ const validatorPool = fee - burned;
106
+ const count = BigInt(canonicalValidators.length);
107
+ const base = validatorPool / count;
108
+ const remainder = Number(validatorPool % count);
109
+ const start = feeRotationIndex(transactionHash, canonicalValidators.length);
110
+ const validatorFees = new Map(canonicalValidators.map((validator) => [validator, base]));
111
+ for (let index = 0; index < remainder; index += 1) {
112
+ const validator = canonicalValidators[(start + index) % canonicalValidators.length];
113
+ validatorFees.set(validator, validatorFees.get(validator) + 1n);
114
+ }
115
+ const payments = [...validatorFees.entries()]
116
+ .filter(([, amount]) => amount > 0n)
117
+ .map(([to, amount]) => ({ to, amount }));
118
+ return { burned, validatorFees, payments };
119
+ };
120
+ const aggregateValidatorFees = (fees, validatorAddresses, burnBasisPoints = 1000n) => {
121
+ const totals = new Map([...new Set(validatorAddresses)].sort().map((validator) => [validator, 0n]));
122
+ for (const entry of fees) {
123
+ const { validatorFees } = distributeTransactionFee(entry.fee, entry.transactionHash, validatorAddresses, burnBasisPoints);
124
+ for (const [validator, amount] of validatorFees)
125
+ totals.set(validator, totals.get(validator) + amount);
126
+ }
127
+ return totals;
128
+ };
22
129
  const createContractMessage = async (creator, contract, constructorParameters = []) => {
23
130
  return new ContractMessage({
24
131
  creator,
@@ -27,16 +134,32 @@ const createContractMessage = async (creator, contract, constructorParameters =
27
134
  });
28
135
  };
29
136
  const calculateFee = async (transaction, format = false) => {
30
- // excluded from fees
31
- if (transaction.to === validators$1)
32
- return 0;
33
137
  transaction = await new TransactionMessage(transaction);
34
- let fee = toBigInt(String(transaction.encoded.length));
35
- // fee per gb
36
- fee /= 1073741824n;
37
- // fee = fee.div(1000000)
138
+ const encodedBytes = BigInt(transaction.encoded.length);
139
+ const units = (encodedBytes + TRANSACTION_FEE_BYTES - 1n) / TRANSACTION_FEE_BYTES;
140
+ const fee = units * TRANSACTION_FEE_UNIT;
38
141
  return format ? formatUnits(fee.toString()) : fee;
39
142
  };
143
+ const validateTransactionResourceLimits = async (transaction) => {
144
+ const message = await new TransactionMessage(transaction);
145
+ const size = message.encoded.length;
146
+ if (size > MAX_TRANSACTION_BYTES) {
147
+ throw new Error(`transaction exceeds ${MAX_TRANSACTION_BYTES} byte protocol limit: ${size}`);
148
+ }
149
+ return size;
150
+ };
151
+ const validateBlockResourceLimits = async (transactions) => {
152
+ if (transactions.length > MAX_BLOCK_TRANSACTIONS) {
153
+ throw new Error(`block exceeds ${MAX_BLOCK_TRANSACTIONS} transaction protocol limit`);
154
+ }
155
+ let size = 0;
156
+ for (const transaction of transactions)
157
+ size += await validateTransactionResourceLimits(transaction);
158
+ if (size > MAX_BLOCK_TRANSACTION_BYTES) {
159
+ throw new Error(`block transactions exceed ${MAX_BLOCK_TRANSACTION_BYTES} byte protocol limit: ${size}`);
160
+ }
161
+ return size;
162
+ };
40
163
  const calculateTransactionFee = (transaction) => {
41
164
  transaction = new TransactionMessage(transaction);
42
165
  return calculateFee(transaction);
@@ -91,4 +214,4 @@ const prepareContractTransactionAndSign = async (owner, contract, constructorPar
91
214
  return signTransaction(transaction, wallet);
92
215
  };
93
216
 
94
- export { calculateFee, calculateReward, calculateTransactionFee, contractFactoryMessage, createContractMessage, createTransactionHash, nameServiceMessage, nativeTokenMessage, prepareContractTransaction, prepareContractTransactionAndSign, signTransaction, validatorsMessage };
217
+ export { ANNUAL_ISSUANCE_BASIS_POINTS, BLOCKS_PER_YEAR, FEE_BASIS_POINTS, FEE_PROTOCOL_VERSION, MAX_BLOCK_TRANSACTIONS, MAX_BLOCK_TRANSACTION_BYTES, MAX_TRANSACTION_BYTES, MAX_TRANSACTION_FEE, MONETARY_FEE_BURN_BASIS_POINTS, MONETARY_POLICY_PROTOCOL_VERSION, SUPPLY_FLOOR_BASIS_POINTS, TRANSACTION_FEE_BYTES, TRANSACTION_FEE_UNIT, aggregateValidatorFees, calculateFee, calculateMonetaryPolicy, calculateReward, calculateTransactionFee, contractFactoryMessage, createContractMessage, createTransactionHash, distributeAmount, distributeTransactionFee, nameServiceMessage, nativeTokenMessage, prepareContractTransaction, prepareContractTransactionAndSign, signTransaction, supportsMonetaryPolicy, supportsTransactionFees, validateBlockResourceLimits, validateTransactionResourceLimits, validatorsMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/lib",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typings": "./exports/typings/index.d.ts",