kalvora.js 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +162 -0
- package/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +391 -0
- package/dist/LICENSE +202 -0
- package/dist/README.md +391 -0
- package/dist/index.cjs +78254 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +125 -0
- package/dist/proto/generated/google/protobuf/empty_pb.d.ts +63 -0
- package/dist/proto/generated/google/protobuf/empty_pb.js +49 -0
- package/dist/proto/generated/google/protobuf/timestamp_pb.d.ts +163 -0
- package/dist/proto/generated/google/protobuf/timestamp_pb.js +49 -0
- package/dist/proto/generated/guardian_pb.d.ts +1229 -0
- package/dist/proto/generated/guardian_pb.js +255 -0
- package/dist/proto/generated/kal_api_pb.d.ts +1350 -0
- package/dist/proto/generated/kal_api_pb.js +324 -0
- package/dist/proto/generated/txn_pb.d.ts +3653 -0
- package/dist/proto/generated/txn_pb.js +622 -0
- package/dist/proto/generated/validator_pb.d.ts +2385 -0
- package/dist/proto/generated/validator_pb.js +528 -0
- package/dist/proto/guardian.proto +266 -0
- package/dist/proto/kal_api.proto +289 -0
- package/dist/proto/txn.proto +718 -0
- package/dist/proto/validator.proto +469 -0
- package/dist/src/adapter/constants.d.ts +80 -0
- package/dist/src/adapter/constants.d.ts.map +1 -0
- package/dist/src/adapter/constants.js +89 -0
- package/dist/src/adapter/constants.js.map +1 -0
- package/dist/src/adapter/index.d.ts +45 -0
- package/dist/src/adapter/index.d.ts.map +1 -0
- package/dist/src/adapter/index.js +71 -0
- package/dist/src/adapter/index.js.map +1 -0
- package/dist/src/adapter/serialization.d.ts +94 -0
- package/dist/src/adapter/serialization.d.ts.map +1 -0
- package/dist/src/adapter/serialization.js +175 -0
- package/dist/src/adapter/serialization.js.map +1 -0
- package/dist/src/adapter/wallet-adapter.d.ts +230 -0
- package/dist/src/adapter/wallet-adapter.d.ts.map +1 -0
- package/dist/src/adapter/wallet-adapter.js +792 -0
- package/dist/src/adapter/wallet-adapter.js.map +1 -0
- package/dist/src/adapter/wallet-signer.d.ts +115 -0
- package/dist/src/adapter/wallet-signer.d.ts.map +1 -0
- package/dist/src/adapter/wallet-signer.js +357 -0
- package/dist/src/adapter/wallet-signer.js.map +1 -0
- package/dist/src/adapter/walletconnect.d.ts +148 -0
- package/dist/src/adapter/walletconnect.d.ts.map +1 -0
- package/dist/src/adapter/walletconnect.js +188 -0
- package/dist/src/adapter/walletconnect.js.map +1 -0
- package/dist/src/allowance/index.d.ts +2 -0
- package/dist/src/allowance/index.d.ts.map +1 -0
- package/dist/src/allowance/index.js +2 -0
- package/dist/src/allowance/index.js.map +1 -0
- package/dist/src/allowance/transaction.d.ts +227 -0
- package/dist/src/allowance/transaction.d.ts.map +1 -0
- package/dist/src/allowance/transaction.js +296 -0
- package/dist/src/allowance/transaction.js.map +1 -0
- package/dist/src/api/handler/fee-info/service.d.ts +126 -0
- package/dist/src/api/handler/fee-info/service.d.ts.map +1 -0
- package/dist/src/api/handler/fee-info/service.js +255 -0
- package/dist/src/api/handler/fee-info/service.js.map +1 -0
- package/dist/src/api/handler/index.d.ts +10 -0
- package/dist/src/api/handler/index.d.ts.map +1 -0
- package/dist/src/api/handler/index.js +14 -0
- package/dist/src/api/handler/index.js.map +1 -0
- package/dist/src/api/handler/nonce/service.d.ts +37 -0
- package/dist/src/api/handler/nonce/service.d.ts.map +1 -0
- package/dist/src/api/handler/nonce/service.js +64 -0
- package/dist/src/api/handler/nonce/service.js.map +1 -0
- package/dist/src/api/handler/token-info/service.d.ts +123 -0
- package/dist/src/api/handler/token-info/service.d.ts.map +1 -0
- package/dist/src/api/handler/token-info/service.js +218 -0
- package/dist/src/api/handler/token-info/service.js.map +1 -0
- package/dist/src/api/shared/indexer-utils.d.ts +14 -0
- package/dist/src/api/shared/indexer-utils.d.ts.map +1 -0
- package/dist/src/api/shared/indexer-utils.js +19 -0
- package/dist/src/api/shared/indexer-utils.js.map +1 -0
- package/dist/src/api/validator/balance/index.d.ts +8 -0
- package/dist/src/api/validator/balance/index.d.ts.map +1 -0
- package/dist/src/api/validator/balance/index.js +7 -0
- package/dist/src/api/validator/balance/index.js.map +1 -0
- package/dist/src/api/validator/balance/service.d.ts +42 -0
- package/dist/src/api/validator/balance/service.d.ts.map +1 -0
- package/dist/src/api/validator/balance/service.js +93 -0
- package/dist/src/api/validator/balance/service.js.map +1 -0
- package/dist/src/api/validator/base-fee/index.d.ts +8 -0
- package/dist/src/api/validator/base-fee/index.d.ts.map +1 -0
- package/dist/src/api/validator/base-fee/index.js +7 -0
- package/dist/src/api/validator/base-fee/index.js.map +1 -0
- package/dist/src/api/validator/base-fee/service.d.ts +39 -0
- package/dist/src/api/validator/base-fee/service.d.ts.map +1 -0
- package/dist/src/api/validator/base-fee/service.js +45 -0
- package/dist/src/api/validator/base-fee/service.js.map +1 -0
- package/dist/src/api/validator/fee-info/index.d.ts +7 -0
- package/dist/src/api/validator/fee-info/index.d.ts.map +1 -0
- package/dist/src/api/validator/fee-info/index.js +7 -0
- package/dist/src/api/validator/fee-info/index.js.map +1 -0
- package/dist/src/api/validator/fee-info/request.d.ts +25 -0
- package/dist/src/api/validator/fee-info/request.d.ts.map +1 -0
- package/dist/src/api/validator/fee-info/request.js +92 -0
- package/dist/src/api/validator/fee-info/request.js.map +1 -0
- package/dist/src/api/validator/nonce/index.d.ts +7 -0
- package/dist/src/api/validator/nonce/index.d.ts.map +1 -0
- package/dist/src/api/validator/nonce/index.js +7 -0
- package/dist/src/api/validator/nonce/index.js.map +1 -0
- package/dist/src/api/validator/nonce/service.d.ts +18 -0
- package/dist/src/api/validator/nonce/service.d.ts.map +1 -0
- package/dist/src/api/validator/nonce/service.js +51 -0
- package/dist/src/api/validator/nonce/service.js.map +1 -0
- package/dist/src/client/index.d.ts +8 -0
- package/dist/src/client/index.d.ts.map +1 -0
- package/dist/src/client/index.js +8 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/kalvora-client.d.ts +117 -0
- package/dist/src/client/kalvora-client.d.ts.map +1 -0
- package/dist/src/client/kalvora-client.js +112 -0
- package/dist/src/client/kalvora-client.js.map +1 -0
- package/dist/src/client/networks.d.ts +48 -0
- package/dist/src/client/networks.d.ts.map +1 -0
- package/dist/src/client/networks.js +41 -0
- package/dist/src/client/networks.js.map +1 -0
- package/dist/src/coin-txn/index.d.ts +9 -0
- package/dist/src/coin-txn/index.d.ts.map +1 -0
- package/dist/src/coin-txn/index.js +9 -0
- package/dist/src/coin-txn/index.js.map +1 -0
- package/dist/src/coin-txn/transaction.d.ts +94 -0
- package/dist/src/coin-txn/transaction.d.ts.map +1 -0
- package/dist/src/coin-txn/transaction.js +341 -0
- package/dist/src/coin-txn/transaction.js.map +1 -0
- package/dist/src/compliance/index.d.ts +2 -0
- package/dist/src/compliance/index.d.ts.map +1 -0
- package/dist/src/compliance/index.js +2 -0
- package/dist/src/compliance/index.js.map +1 -0
- package/dist/src/compliance/transaction.d.ts +150 -0
- package/dist/src/compliance/transaction.d.ts.map +1 -0
- package/dist/src/compliance/transaction.js +183 -0
- package/dist/src/compliance/transaction.js.map +1 -0
- package/dist/src/contract/create/index.d.ts +8 -0
- package/dist/src/contract/create/index.d.ts.map +1 -0
- package/dist/src/contract/create/index.js +7 -0
- package/dist/src/contract/create/index.js.map +1 -0
- package/dist/src/contract/create/transaction.d.ts +47 -0
- package/dist/src/contract/create/transaction.d.ts.map +1 -0
- package/dist/src/contract/create/transaction.js +137 -0
- package/dist/src/contract/create/transaction.js.map +1 -0
- package/dist/src/contract/index.d.ts +34 -0
- package/dist/src/contract/index.d.ts.map +1 -0
- package/dist/src/contract/index.js +34 -0
- package/dist/src/contract/index.js.map +1 -0
- package/dist/src/contract/shared/index.d.ts +6 -0
- package/dist/src/contract/shared/index.d.ts.map +1 -0
- package/dist/src/contract/shared/index.js +6 -0
- package/dist/src/contract/shared/index.js.map +1 -0
- package/dist/src/contract/shared/types.d.ts +114 -0
- package/dist/src/contract/shared/types.d.ts.map +1 -0
- package/dist/src/contract/shared/types.js +5 -0
- package/dist/src/contract/shared/types.js.map +1 -0
- package/dist/src/contract/shared/utils.d.ts +111 -0
- package/dist/src/contract/shared/utils.d.ts.map +1 -0
- package/dist/src/contract/shared/utils.js +182 -0
- package/dist/src/contract/shared/utils.js.map +1 -0
- package/dist/src/contract/update/index.d.ts +8 -0
- package/dist/src/contract/update/index.d.ts.map +1 -0
- package/dist/src/contract/update/index.js +7 -0
- package/dist/src/contract/update/index.js.map +1 -0
- package/dist/src/contract/update/transaction.d.ts +45 -0
- package/dist/src/contract/update/transaction.d.ts.map +1 -0
- package/dist/src/contract/update/transaction.js +123 -0
- package/dist/src/contract/update/transaction.js.map +1 -0
- package/dist/src/delegated-voting/index.d.ts +2 -0
- package/dist/src/delegated-voting/index.d.ts.map +1 -0
- package/dist/src/delegated-voting/index.js +2 -0
- package/dist/src/delegated-voting/index.js.map +1 -0
- package/dist/src/delegated-voting/transaction.d.ts +127 -0
- package/dist/src/delegated-voting/transaction.d.ts.map +1 -0
- package/dist/src/delegated-voting/transaction.js +195 -0
- package/dist/src/delegated-voting/transaction.js.map +1 -0
- package/dist/src/expense-ratio/index.d.ts +2 -0
- package/dist/src/expense-ratio/index.d.ts.map +1 -0
- package/dist/src/expense-ratio/index.js +2 -0
- package/dist/src/expense-ratio/index.js.map +1 -0
- package/dist/src/expense-ratio/transaction.d.ts +94 -0
- package/dist/src/expense-ratio/transaction.d.ts.map +1 -0
- package/dist/src/expense-ratio/transaction.js +122 -0
- package/dist/src/expense-ratio/transaction.js.map +1 -0
- package/dist/src/grpc/api/validator-api-client.d.ts +32 -0
- package/dist/src/grpc/api/validator-api-client.d.ts.map +1 -0
- package/dist/src/grpc/api/validator-api-client.js +61 -0
- package/dist/src/grpc/api/validator-api-client.js.map +1 -0
- package/dist/src/grpc/client-factory.d.ts +12 -0
- package/dist/src/grpc/client-factory.d.ts.map +1 -0
- package/dist/src/grpc/client-factory.js +248 -0
- package/dist/src/grpc/client-factory.js.map +1 -0
- package/dist/src/grpc/errors.d.ts +79 -0
- package/dist/src/grpc/errors.d.ts.map +1 -0
- package/dist/src/grpc/errors.js +108 -0
- package/dist/src/grpc/errors.js.map +1 -0
- package/dist/src/grpc/index.d.ts +21 -0
- package/dist/src/grpc/index.d.ts.map +1 -0
- package/dist/src/grpc/index.js +20 -0
- package/dist/src/grpc/index.js.map +1 -0
- package/dist/src/grpc/transaction/transaction-client.d.ts +97 -0
- package/dist/src/grpc/transaction/transaction-client.d.ts.map +1 -0
- package/dist/src/grpc/transaction/transaction-client.js +142 -0
- package/dist/src/grpc/transaction/transaction-client.js.map +1 -0
- package/dist/src/grpc/utils/grpc-web-fetch-wrapper.d.ts +2 -0
- package/dist/src/grpc/utils/grpc-web-fetch-wrapper.d.ts.map +1 -0
- package/dist/src/grpc/utils/grpc-web-fetch-wrapper.js +213 -0
- package/dist/src/grpc/utils/grpc-web-fetch-wrapper.js.map +1 -0
- package/dist/src/items/index.d.ts +7 -0
- package/dist/src/items/index.d.ts.map +1 -0
- package/dist/src/items/index.js +7 -0
- package/dist/src/items/index.js.map +1 -0
- package/dist/src/items/transaction.d.ts +132 -0
- package/dist/src/items/transaction.d.ts.map +1 -0
- package/dist/src/items/transaction.js +276 -0
- package/dist/src/items/transaction.js.map +1 -0
- package/dist/src/mint/index.d.ts +2 -0
- package/dist/src/mint/index.d.ts.map +1 -0
- package/dist/src/mint/index.js +2 -0
- package/dist/src/mint/index.js.map +1 -0
- package/dist/src/mint/transaction.d.ts +128 -0
- package/dist/src/mint/transaction.d.ts.map +1 -0
- package/dist/src/mint/transaction.js +118 -0
- package/dist/src/mint/transaction.js.map +1 -0
- package/dist/src/proposal/index.d.ts +3 -0
- package/dist/src/proposal/index.d.ts.map +1 -0
- package/dist/src/proposal/index.js +3 -0
- package/dist/src/proposal/index.js.map +1 -0
- package/dist/src/proposal/transaction.d.ts +95 -0
- package/dist/src/proposal/transaction.d.ts.map +1 -0
- package/dist/src/proposal/transaction.js +321 -0
- package/dist/src/proposal/transaction.js.map +1 -0
- package/dist/src/proposal-cancel/index.d.ts +2 -0
- package/dist/src/proposal-cancel/index.d.ts.map +1 -0
- package/dist/src/proposal-cancel/index.js +2 -0
- package/dist/src/proposal-cancel/index.js.map +1 -0
- package/dist/src/proposal-cancel/transaction.d.ts +31 -0
- package/dist/src/proposal-cancel/transaction.d.ts.map +1 -0
- package/dist/src/proposal-cancel/transaction.js +98 -0
- package/dist/src/proposal-cancel/transaction.js.map +1 -0
- package/dist/src/protocol/guardian-names.d.ts +35 -0
- package/dist/src/protocol/guardian-names.d.ts.map +1 -0
- package/dist/src/protocol/guardian-names.js +25 -0
- package/dist/src/protocol/guardian-names.js.map +1 -0
- package/dist/src/protocol/index.d.ts +36 -0
- package/dist/src/protocol/index.d.ts.map +1 -0
- package/dist/src/protocol/index.js +36 -0
- package/dist/src/protocol/index.js.map +1 -0
- package/dist/src/quash/index.d.ts +2 -0
- package/dist/src/quash/index.d.ts.map +1 -0
- package/dist/src/quash/index.js +2 -0
- package/dist/src/quash/index.js.map +1 -0
- package/dist/src/quash/transaction.d.ts +124 -0
- package/dist/src/quash/transaction.d.ts.map +1 -0
- package/dist/src/quash/transaction.js +118 -0
- package/dist/src/quash/transaction.js.map +1 -0
- package/dist/src/query/api-client.d.ts +368 -0
- package/dist/src/query/api-client.d.ts.map +1 -0
- package/dist/src/query/api-client.js +497 -0
- package/dist/src/query/api-client.js.map +1 -0
- package/dist/src/query/decoders.d.ts +184 -0
- package/dist/src/query/decoders.d.ts.map +1 -0
- package/dist/src/query/decoders.js +257 -0
- package/dist/src/query/decoders.js.map +1 -0
- package/dist/src/query/guardian-client.d.ts +73 -0
- package/dist/src/query/guardian-client.d.ts.map +1 -0
- package/dist/src/query/guardian-client.js +90 -0
- package/dist/src/query/guardian-client.js.map +1 -0
- package/dist/src/query/index.d.ts +16 -0
- package/dist/src/query/index.d.ts.map +1 -0
- package/dist/src/query/index.js +16 -0
- package/dist/src/query/index.js.map +1 -0
- package/dist/src/query/validator-client.d.ts +95 -0
- package/dist/src/query/validator-client.d.ts.map +1 -0
- package/dist/src/query/validator-client.js +116 -0
- package/dist/src/query/validator-client.js.map +1 -0
- package/dist/src/revoke/index.d.ts +2 -0
- package/dist/src/revoke/index.d.ts.map +1 -0
- package/dist/src/revoke/index.js +2 -0
- package/dist/src/revoke/index.js.map +1 -0
- package/dist/src/revoke/transaction.d.ts +123 -0
- package/dist/src/revoke/transaction.d.ts.map +1 -0
- package/dist/src/revoke/transaction.js +125 -0
- package/dist/src/revoke/transaction.js.map +1 -0
- package/dist/src/shared/crypto/address-utils.d.ts +71 -0
- package/dist/src/shared/crypto/address-utils.d.ts.map +1 -0
- package/dist/src/shared/crypto/address-utils.js +305 -0
- package/dist/src/shared/crypto/address-utils.js.map +1 -0
- package/dist/src/shared/crypto/constants.d.ts +29 -0
- package/dist/src/shared/crypto/constants.d.ts.map +1 -0
- package/dist/src/shared/crypto/constants.js +53 -0
- package/dist/src/shared/crypto/constants.js.map +1 -0
- package/dist/src/shared/crypto/signature-utils.d.ts +14 -0
- package/dist/src/shared/crypto/signature-utils.d.ts.map +1 -0
- package/dist/src/shared/crypto/signature-utils.js +40 -0
- package/dist/src/shared/crypto/signature-utils.js.map +1 -0
- package/dist/src/shared/fee-calculators/base-fee-constants.d.ts +33 -0
- package/dist/src/shared/fee-calculators/base-fee-constants.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/base-fee-constants.js +45 -0
- package/dist/src/shared/fee-calculators/base-fee-constants.js.map +1 -0
- package/dist/src/shared/fee-calculators/contract-fee-constants.d.ts +53 -0
- package/dist/src/shared/fee-calculators/contract-fee-constants.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/contract-fee-constants.js +73 -0
- package/dist/src/shared/fee-calculators/contract-fee-constants.js.map +1 -0
- package/dist/src/shared/fee-calculators/contract-fee-service.d.ts +60 -0
- package/dist/src/shared/fee-calculators/contract-fee-service.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/contract-fee-service.js +171 -0
- package/dist/src/shared/fee-calculators/contract-fee-service.js.map +1 -0
- package/dist/src/shared/fee-calculators/denomination-fallback.d.ts +41 -0
- package/dist/src/shared/fee-calculators/denomination-fallback.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/denomination-fallback.js +83 -0
- package/dist/src/shared/fee-calculators/denomination-fallback.js.map +1 -0
- package/dist/src/shared/fee-calculators/exchange-rate-service.d.ts +26 -0
- package/dist/src/shared/fee-calculators/exchange-rate-service.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/exchange-rate-service.js +62 -0
- package/dist/src/shared/fee-calculators/exchange-rate-service.js.map +1 -0
- package/dist/src/shared/fee-calculators/types.d.ts +81 -0
- package/dist/src/shared/fee-calculators/types.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/types.js +7 -0
- package/dist/src/shared/fee-calculators/types.js.map +1 -0
- package/dist/src/shared/fee-calculators/universal-fee-calculator.d.ts +144 -0
- package/dist/src/shared/fee-calculators/universal-fee-calculator.d.ts.map +1 -0
- package/dist/src/shared/fee-calculators/universal-fee-calculator.js +900 -0
- package/dist/src/shared/fee-calculators/universal-fee-calculator.js.map +1 -0
- package/dist/src/shared/monitoring/health-check.d.ts +37 -0
- package/dist/src/shared/monitoring/health-check.d.ts.map +1 -0
- package/dist/src/shared/monitoring/health-check.js +152 -0
- package/dist/src/shared/monitoring/health-check.js.map +1 -0
- package/dist/src/shared/monitoring/index.d.ts +9 -0
- package/dist/src/shared/monitoring/index.d.ts.map +1 -0
- package/dist/src/shared/monitoring/index.js +9 -0
- package/dist/src/shared/monitoring/index.js.map +1 -0
- package/dist/src/shared/monitoring/logger.d.ts +42 -0
- package/dist/src/shared/monitoring/logger.d.ts.map +1 -0
- package/dist/src/shared/monitoring/logger.js +185 -0
- package/dist/src/shared/monitoring/logger.js.map +1 -0
- package/dist/src/shared/monitoring/metrics.d.ts +33 -0
- package/dist/src/shared/monitoring/metrics.d.ts.map +1 -0
- package/dist/src/shared/monitoring/metrics.js +105 -0
- package/dist/src/shared/monitoring/metrics.js.map +1 -0
- package/dist/src/shared/network/constants.d.ts +34 -0
- package/dist/src/shared/network/constants.d.ts.map +1 -0
- package/dist/src/shared/network/constants.js +46 -0
- package/dist/src/shared/network/constants.js.map +1 -0
- package/dist/src/shared/protobuf/index.d.ts +18 -0
- package/dist/src/shared/protobuf/index.d.ts.map +1 -0
- package/dist/src/shared/protobuf/index.js +10 -0
- package/dist/src/shared/protobuf/index.js.map +1 -0
- package/dist/src/shared/tx/base.d.ts +24 -0
- package/dist/src/shared/tx/base.d.ts.map +1 -0
- package/dist/src/shared/tx/base.js +57 -0
- package/dist/src/shared/tx/base.js.map +1 -0
- package/dist/src/shared/tx/standard.d.ts +198 -0
- package/dist/src/shared/tx/standard.d.ts.map +1 -0
- package/dist/src/shared/tx/standard.js +283 -0
- package/dist/src/shared/tx/standard.js.map +1 -0
- package/dist/src/shared/utils/amount-utils.d.ts +110 -0
- package/dist/src/shared/utils/amount-utils.d.ts.map +1 -0
- package/dist/src/shared/utils/amount-utils.js +237 -0
- package/dist/src/shared/utils/amount-utils.js.map +1 -0
- package/dist/src/shared/utils/byte-utils.d.ts +127 -0
- package/dist/src/shared/utils/byte-utils.d.ts.map +1 -0
- package/dist/src/shared/utils/byte-utils.js +220 -0
- package/dist/src/shared/utils/byte-utils.js.map +1 -0
- package/dist/src/shared/utils/error-handler.d.ts +65 -0
- package/dist/src/shared/utils/error-handler.d.ts.map +1 -0
- package/dist/src/shared/utils/error-handler.js +157 -0
- package/dist/src/shared/utils/error-handler.js.map +1 -0
- package/dist/src/shared/utils/formatting.d.ts +133 -0
- package/dist/src/shared/utils/formatting.d.ts.map +1 -0
- package/dist/src/shared/utils/formatting.js +190 -0
- package/dist/src/shared/utils/formatting.js.map +1 -0
- package/dist/src/shared/utils/grpc-config-utils.d.ts +8 -0
- package/dist/src/shared/utils/grpc-config-utils.d.ts.map +1 -0
- package/dist/src/shared/utils/grpc-config-utils.js +11 -0
- package/dist/src/shared/utils/grpc-config-utils.js.map +1 -0
- package/dist/src/shared/utils/performance-benchmark.d.ts +136 -0
- package/dist/src/shared/utils/performance-benchmark.d.ts.map +1 -0
- package/dist/src/shared/utils/performance-benchmark.js +274 -0
- package/dist/src/shared/utils/performance-benchmark.js.map +1 -0
- package/dist/src/shared/utils/protobuf-utils.d.ts +39 -0
- package/dist/src/shared/utils/protobuf-utils.d.ts.map +1 -0
- package/dist/src/shared/utils/protobuf-utils.js +103 -0
- package/dist/src/shared/utils/protobuf-utils.js.map +1 -0
- package/dist/src/shared/utils/testing-defaults/grpc-config.d.ts +12 -0
- package/dist/src/shared/utils/testing-defaults/grpc-config.d.ts.map +1 -0
- package/dist/src/shared/utils/testing-defaults/grpc-config.js +16 -0
- package/dist/src/shared/utils/testing-defaults/grpc-config.js.map +1 -0
- package/dist/src/shared/utils/testing-defaults/index.d.ts +8 -0
- package/dist/src/shared/utils/testing-defaults/index.d.ts.map +1 -0
- package/dist/src/shared/utils/testing-defaults/index.js +8 -0
- package/dist/src/shared/utils/testing-defaults/index.js.map +1 -0
- package/dist/src/shared/utils/token-config.d.ts +31 -0
- package/dist/src/shared/utils/token-config.d.ts.map +1 -0
- package/dist/src/shared/utils/token-config.js +56 -0
- package/dist/src/shared/utils/token-config.js.map +1 -0
- package/dist/src/shared/utils/token-info.d.ts +101 -0
- package/dist/src/shared/utils/token-info.d.ts.map +1 -0
- package/dist/src/shared/utils/token-info.js +203 -0
- package/dist/src/shared/utils/token-info.js.map +1 -0
- package/dist/src/shared/utils/transaction-utils.d.ts +200 -0
- package/dist/src/shared/utils/transaction-utils.d.ts.map +1 -0
- package/dist/src/shared/utils/transaction-utils.js +293 -0
- package/dist/src/shared/utils/transaction-utils.js.map +1 -0
- package/dist/src/shared/utils/unified-amount-conversion.d.ts +65 -0
- package/dist/src/shared/utils/unified-amount-conversion.d.ts.map +1 -0
- package/dist/src/shared/utils/unified-amount-conversion.js +146 -0
- package/dist/src/shared/utils/unified-amount-conversion.js.map +1 -0
- package/dist/src/shared/utils/validation.d.ts +119 -0
- package/dist/src/shared/utils/validation.d.ts.map +1 -0
- package/dist/src/shared/utils/validation.js +540 -0
- package/dist/src/shared/utils/validation.js.map +1 -0
- package/dist/src/sign/finalize.d.ts +82 -0
- package/dist/src/sign/finalize.d.ts.map +1 -0
- package/dist/src/sign/finalize.js +216 -0
- package/dist/src/sign/finalize.js.map +1 -0
- package/dist/src/sign/index.d.ts +19 -0
- package/dist/src/sign/index.d.ts.map +1 -0
- package/dist/src/sign/index.js +21 -0
- package/dist/src/sign/index.js.map +1 -0
- package/dist/src/sign/signer.d.ts +71 -0
- package/dist/src/sign/signer.d.ts.map +1 -0
- package/dist/src/sign/signer.js +65 -0
- package/dist/src/sign/signer.js.map +1 -0
- package/dist/src/smart-contracts/deploy/index.d.ts +5 -0
- package/dist/src/smart-contracts/deploy/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/deploy/index.js +5 -0
- package/dist/src/smart-contracts/deploy/index.js.map +1 -0
- package/dist/src/smart-contracts/deploy/transaction.d.ts +54 -0
- package/dist/src/smart-contracts/deploy/transaction.d.ts.map +1 -0
- package/dist/src/smart-contracts/deploy/transaction.js +116 -0
- package/dist/src/smart-contracts/deploy/transaction.js.map +1 -0
- package/dist/src/smart-contracts/execute/index.d.ts +5 -0
- package/dist/src/smart-contracts/execute/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/execute/index.js +5 -0
- package/dist/src/smart-contracts/execute/index.js.map +1 -0
- package/dist/src/smart-contracts/execute/transaction.d.ts +60 -0
- package/dist/src/smart-contracts/execute/transaction.d.ts.map +1 -0
- package/dist/src/smart-contracts/execute/transaction.js +88 -0
- package/dist/src/smart-contracts/execute/transaction.js.map +1 -0
- package/dist/src/smart-contracts/instantiate/index.d.ts +6 -0
- package/dist/src/smart-contracts/instantiate/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/instantiate/index.js +6 -0
- package/dist/src/smart-contracts/instantiate/index.js.map +1 -0
- package/dist/src/smart-contracts/instantiate/transaction.d.ts +43 -0
- package/dist/src/smart-contracts/instantiate/transaction.d.ts.map +1 -0
- package/dist/src/smart-contracts/instantiate/transaction.js +72 -0
- package/dist/src/smart-contracts/instantiate/transaction.js.map +1 -0
- package/dist/src/smart-contracts/shared/base.d.ts +29 -0
- package/dist/src/smart-contracts/shared/base.d.ts.map +1 -0
- package/dist/src/smart-contracts/shared/base.js +70 -0
- package/dist/src/smart-contracts/shared/base.js.map +1 -0
- package/dist/src/smart-contracts/shared/parameters.d.ts +26 -0
- package/dist/src/smart-contracts/shared/parameters.d.ts.map +1 -0
- package/dist/src/smart-contracts/shared/parameters.js +32 -0
- package/dist/src/smart-contracts/shared/parameters.js.map +1 -0
- package/dist/src/smart-contracts/shared/validation.d.ts +6 -0
- package/dist/src/smart-contracts/shared/validation.d.ts.map +1 -0
- package/dist/src/smart-contracts/shared/validation.js +13 -0
- package/dist/src/smart-contracts/shared/validation.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/index.d.ts +25 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/index.js +30 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/index.d.ts +7 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/index.js +7 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/process-rewards.d.ts +23 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/process-rewards.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/process-rewards.js +39 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/process-rewards.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/stake.d.ts +27 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/stake.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/stake.js +51 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/stake.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/update-wallet.d.ts +22 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/update-wallet.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/update-wallet.js +43 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/transactions/update-wallet.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/types.d.ts +60 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/types.js +8 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/types.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/utils.d.ts +131 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/utils.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/utils.js +87 -0
- package/dist/src/smart-contracts/use-cases/bootstrapping/utils.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/index.d.ts +49 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/index.js +59 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/vaa.d.ts +150 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/vaa.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/vaa.js +505 -0
- package/dist/src/smart-contracts/use-cases/bridge/guardian/vaa.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/index.d.ts +68 -0
- package/dist/src/smart-contracts/use-cases/bridge/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/index.js +83 -0
- package/dist/src/smart-contracts/use-cases/bridge/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/index.d.ts +36 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/index.js +53 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/index.d.ts +10 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/index.js +17 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/lock.d.ts +65 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/lock.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/lock.js +130 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/lock.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/release.d.ts +81 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/release.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/release.js +187 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/transactions/release.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/types.d.ts +82 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/types.js +7 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/types.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/utils.d.ts +49 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/utils.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/utils.js +80 -0
- package/dist/src/smart-contracts/use-cases/bridge/kalvora/utils.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/constants.d.ts +84 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/constants.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/constants.js +82 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/constants.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/index.d.ts +58 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/index.js +90 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/burn.d.ts +26 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/burn.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/burn.js +59 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/burn.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/helpers.d.ts +29 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/helpers.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/helpers.js +50 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/helpers.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/index.d.ts +14 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/index.js +31 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/lock.d.ts +70 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/lock.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/lock.js +212 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/lock.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/mint.d.ts +60 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/mint.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/mint.js +288 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/mint.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/registration.d.ts +54 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/registration.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/registration.js +186 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/registration.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/release.d.ts +96 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/release.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/release.js +406 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/release.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/token-type.d.ts +34 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/token-type.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/token-type.js +55 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/transactions/token-type.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/types.d.ts +377 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/types.js +9 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/types.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/utils.d.ts +121 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/utils.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/utils.js +219 -0
- package/dist/src/smart-contracts/use-cases/bridge/solana/utils.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/index.d.ts +58 -0
- package/dist/src/smart-contracts/use-cases/dex/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/index.js +73 -0
- package/dist/src/smart-contracts/use-cases/dex/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/add-liquidity.d.ts +34 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/add-liquidity.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/add-liquidity.js +68 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/add-liquidity.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/create-pool.d.ts +35 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/create-pool.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/create-pool.js +69 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/create-pool.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/index.d.ts +11 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/index.js +11 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/remove-liquidity.d.ts +40 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/remove-liquidity.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/remove-liquidity.js +76 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/remove-liquidity.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/swap.d.ts +38 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/swap.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/swap.js +70 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/swap.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/unlock-liquidity.d.ts +37 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/unlock-liquidity.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/unlock-liquidity.js +60 -0
- package/dist/src/smart-contracts/use-cases/dex/transactions/unlock-liquidity.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/types.d.ts +130 -0
- package/dist/src/smart-contracts/use-cases/dex/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/types.js +11 -0
- package/dist/src/smart-contracts/use-cases/dex/types.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/utils.d.ts +52 -0
- package/dist/src/smart-contracts/use-cases/dex/utils.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/dex/utils.js +79 -0
- package/dist/src/smart-contracts/use-cases/dex/utils.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/index.d.ts +35 -0
- package/dist/src/smart-contracts/use-cases/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/index.js +35 -0
- package/dist/src/smart-contracts/use-cases/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/index.d.ts +67 -0
- package/dist/src/smart-contracts/use-cases/staking/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/index.js +84 -0
- package/dist/src/smart-contracts/use-cases/staking/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/index.d.ts +12 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/index.js +12 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/instant-stake.d.ts +36 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/instant-stake.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/instant-stake.js +57 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/instant-stake.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-instant.d.ts +33 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-instant.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-instant.js +49 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-instant.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-liquid-stake.d.ts +33 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-liquid-stake.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-liquid-stake.js +49 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/release-liquid-stake.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/stake.d.ts +36 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/stake.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/stake.js +59 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/stake.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-instant-wallet.d.ts +36 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-instant-wallet.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-instant-wallet.js +57 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-instant-wallet.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-wallet.d.ts +36 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-wallet.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-wallet.js +57 -0
- package/dist/src/smart-contracts/use-cases/staking/transactions/update-wallet.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/types.d.ts +76 -0
- package/dist/src/smart-contracts/use-cases/staking/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/types.js +10 -0
- package/dist/src/smart-contracts/use-cases/staking/types.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/utils.d.ts +27 -0
- package/dist/src/smart-contracts/use-cases/staking/utils.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/staking/utils.js +44 -0
- package/dist/src/smart-contracts/use-cases/staking/utils.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/index.d.ts +26 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/index.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/index.js +107 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/index.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/resolve-indexer.d.ts +18 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/resolve-indexer.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/resolve-indexer.js +37 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/resolve-indexer.js.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/types.d.ts +126 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/types.d.ts.map +1 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/types.js +10 -0
- package/dist/src/smart-contracts/use-cases/third-party/vision-dynamics/smart-swap/types.js.map +1 -0
- package/dist/src/types/index.d.ts +240 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +110 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/validator-ops/index.d.ts +2 -0
- package/dist/src/validator-ops/index.d.ts.map +1 -0
- package/dist/src/validator-ops/index.js +2 -0
- package/dist/src/validator-ops/index.js.map +1 -0
- package/dist/src/validator-ops/transaction.d.ts +312 -0
- package/dist/src/validator-ops/transaction.d.ts.map +1 -0
- package/dist/src/validator-ops/transaction.js +416 -0
- package/dist/src/validator-ops/transaction.js.map +1 -0
- package/dist/src/vote/index.d.ts +5 -0
- package/dist/src/vote/index.d.ts.map +1 -0
- package/dist/src/vote/index.js +5 -0
- package/dist/src/vote/index.js.map +1 -0
- package/dist/src/vote/transaction.d.ts +70 -0
- package/dist/src/vote/transaction.d.ts.map +1 -0
- package/dist/src/vote/transaction.js +140 -0
- package/dist/src/vote/transaction.js.map +1 -0
- package/dist/src/wallet-creation/constants.d.ts +58 -0
- package/dist/src/wallet-creation/constants.d.ts.map +1 -0
- package/dist/src/wallet-creation/constants.js +113 -0
- package/dist/src/wallet-creation/constants.js.map +1 -0
- package/dist/src/wallet-creation/crypto-core.d.ts +178 -0
- package/dist/src/wallet-creation/crypto-core.d.ts.map +1 -0
- package/dist/src/wallet-creation/crypto-core.js +516 -0
- package/dist/src/wallet-creation/crypto-core.js.map +1 -0
- package/dist/src/wallet-creation/errors.d.ts +58 -0
- package/dist/src/wallet-creation/errors.d.ts.map +1 -0
- package/dist/src/wallet-creation/errors.js +89 -0
- package/dist/src/wallet-creation/errors.js.map +1 -0
- package/dist/src/wallet-creation/hash-utils.d.ts +38 -0
- package/dist/src/wallet-creation/hash-utils.d.ts.map +1 -0
- package/dist/src/wallet-creation/hash-utils.js +147 -0
- package/dist/src/wallet-creation/hash-utils.js.map +1 -0
- package/dist/src/wallet-creation/hd-utils.d.ts +45 -0
- package/dist/src/wallet-creation/hd-utils.d.ts.map +1 -0
- package/dist/src/wallet-creation/hd-utils.js +110 -0
- package/dist/src/wallet-creation/hd-utils.js.map +1 -0
- package/dist/src/wallet-creation/index.d.ts +11 -0
- package/dist/src/wallet-creation/index.d.ts.map +1 -0
- package/dist/src/wallet-creation/index.js +21 -0
- package/dist/src/wallet-creation/index.js.map +1 -0
- package/dist/src/wallet-creation/shared.d.ts +60 -0
- package/dist/src/wallet-creation/shared.d.ts.map +1 -0
- package/dist/src/wallet-creation/shared.js +127 -0
- package/dist/src/wallet-creation/shared.js.map +1 -0
- package/dist/src/wallet-creation/wallet-factory.d.ts +107 -0
- package/dist/src/wallet-creation/wallet-factory.d.ts.map +1 -0
- package/dist/src/wallet-creation/wallet-factory.js +298 -0
- package/dist/src/wallet-creation/wallet-factory.js.map +1 -0
- package/dist/wallet.d.ts +17 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +17 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +129 -0
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Fee Calculator for Kalvora JS SDK
|
|
3
|
+
* Handles network fees (base fees), contract-specific fees, and interface fees with automatic or manual specification
|
|
4
|
+
*/
|
|
5
|
+
import { toBinary } from '@bufbuild/protobuf';
|
|
6
|
+
import bs58 from 'bs58';
|
|
7
|
+
import { CONTRACT_FEE_TYPE } from '../../../proto/generated/txn_pb.js';
|
|
8
|
+
import { getSchemaForTypeName } from '../../adapter/serialization.js';
|
|
9
|
+
import { getTokenFeeInfo } from '../../api/handler/token-info/service.js';
|
|
10
|
+
import { getBalance } from '../../api/validator/balance/service.js';
|
|
11
|
+
import { getBaseFee } from '../../api/validator/base-fee/service.js';
|
|
12
|
+
import { getKeyTypeFromPublicKey, getPublicKeyIdentifierFromBytes, sanitizeAndDecodeAddress } from '../crypto/address-utils.js';
|
|
13
|
+
import { KEY_TYPE } from '../crypto/constants.js';
|
|
14
|
+
import { logger } from '../monitoring/index.js';
|
|
15
|
+
import { KALVORA_NATIVE_TOKEN } from '../network/constants.js';
|
|
16
|
+
import { TRANSACTION_TYPE } from '../protobuf/index.js';
|
|
17
|
+
import { toDecimal, Decimal } from '../utils/amount-utils.js';
|
|
18
|
+
import { normalizeContractId } from '../utils/token-info.js';
|
|
19
|
+
import { toSmallestUnits } from '../utils/unified-amount-conversion.js';
|
|
20
|
+
import { HASH_SIZE, PROTOBUF_HASH_OVERHEAD, PROTOBUF_BASE_SIGNATURE_OVERHEAD, PROTOBUF_AUTH_SIGNATURE_OVERHEAD, getSignatureSize } from './base-fee-constants.js';
|
|
21
|
+
import { getDenominationFallback, getDecimalPlacesFromDenomination } from './denomination-fallback.js';
|
|
22
|
+
import { ExchangeRateService } from './exchange-rate-service.js';
|
|
23
|
+
/**
|
|
24
|
+
* Type guard to check if an object is a CoinTXN
|
|
25
|
+
*/
|
|
26
|
+
function isCoinTXN(obj) {
|
|
27
|
+
return !!(obj && typeof obj === 'object' && '$typeName' in obj && obj.$typeName === 'kal_txn.CoinTXN');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if an object has auth property (CoinTXN)
|
|
31
|
+
*/
|
|
32
|
+
function hasAuthProperty(obj) {
|
|
33
|
+
return !!(obj && typeof obj === 'object' && 'auth' in obj);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Type guard to check if an object has base property
|
|
37
|
+
*/
|
|
38
|
+
function hasBaseProperty(obj) {
|
|
39
|
+
return !!(obj && typeof obj === 'object' && 'base' in obj);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extract transaction type from a protobuf object
|
|
43
|
+
*/
|
|
44
|
+
function extractTransactionTypeFromProtoObject(protoObject) {
|
|
45
|
+
try {
|
|
46
|
+
const typeName = protoObject.$typeName;
|
|
47
|
+
if (typeName === 'kal_txn.CoinTXN')
|
|
48
|
+
return TRANSACTION_TYPE.COIN_TYPE;
|
|
49
|
+
if (typeName === 'kal_txn.MintTXN')
|
|
50
|
+
return TRANSACTION_TYPE.MINT_TYPE;
|
|
51
|
+
if (typeName === 'kal_txn.ItemizedMintTXN')
|
|
52
|
+
return TRANSACTION_TYPE.ITEM_MINT_TYPE;
|
|
53
|
+
if (typeName === 'kal_txn.InstrumentContract')
|
|
54
|
+
return TRANSACTION_TYPE.CONTRACT_TXN_TYPE;
|
|
55
|
+
if (typeName === 'kal_txn.GovernanceVote')
|
|
56
|
+
return TRANSACTION_TYPE.VOTE_TYPE;
|
|
57
|
+
if (typeName === 'kal_txn.GovernanceProposal')
|
|
58
|
+
return TRANSACTION_TYPE.PROPOSAL_TYPE;
|
|
59
|
+
if (typeName === 'kal_txn.SmartContractTXN')
|
|
60
|
+
return TRANSACTION_TYPE.SMART_CONTRACT_TYPE;
|
|
61
|
+
if (typeName === 'kal_txn.SmartContractExecuteTXN')
|
|
62
|
+
return TRANSACTION_TYPE.SMART_CONTRACT_EXECUTE_TYPE;
|
|
63
|
+
if (typeName === 'kal_txn.ExpenseRatioTXN')
|
|
64
|
+
return TRANSACTION_TYPE.EXPENSE_RATIO_TYPE;
|
|
65
|
+
if (typeName === 'kal_txn.NFTTXN')
|
|
66
|
+
return TRANSACTION_TYPE.NFT_TYPE;
|
|
67
|
+
if (typeName === 'kal_txn.ContractUpdateTXN')
|
|
68
|
+
return TRANSACTION_TYPE.UPDATE_CONTRACT_TYPE;
|
|
69
|
+
if (typeName === 'kal_txn.ValidatorRegistration')
|
|
70
|
+
return TRANSACTION_TYPE.VALIDATOR_REGISTRATION_TYPE;
|
|
71
|
+
if (typeName === 'kal_txn.ValidatorHeartbeat')
|
|
72
|
+
return TRANSACTION_TYPE.VALIDATOR_HEARTBEAT_TYPE;
|
|
73
|
+
if (typeName === 'kal_txn.ProposalResult')
|
|
74
|
+
return TRANSACTION_TYPE.PROPOSAL_RESULT_TYPE;
|
|
75
|
+
if (typeName === 'kal_txn.DelegatedTXN')
|
|
76
|
+
return TRANSACTION_TYPE.DELEGATED_VOTING_TYPE;
|
|
77
|
+
if (typeName === 'kal_txn.RevokeTXN')
|
|
78
|
+
return TRANSACTION_TYPE.REVOKE_TYPE;
|
|
79
|
+
if (typeName === 'kal_txn.QuashTXN')
|
|
80
|
+
return TRANSACTION_TYPE.QUASH_TYPE;
|
|
81
|
+
if (typeName === 'kal_txn.ComplianceTXN')
|
|
82
|
+
return TRANSACTION_TYPE.COMPLIANCE_TYPE;
|
|
83
|
+
if (typeName === 'kal_txn.BurnSBTTXN')
|
|
84
|
+
return TRANSACTION_TYPE.SBT_BURN_TYPE;
|
|
85
|
+
if (typeName === 'kal_txn.RequiredVersion')
|
|
86
|
+
return TRANSACTION_TYPE.REQUIRED_VERSION;
|
|
87
|
+
if (typeName === 'kal_txn.SmartContractInstantiateTXN')
|
|
88
|
+
return TRANSACTION_TYPE.SMART_CONTRACT_INSTANTIATE_TYPE;
|
|
89
|
+
if (typeName === 'kal_txn.AllowanceTXN')
|
|
90
|
+
return TRANSACTION_TYPE.ALLOWANCE_TYPE;
|
|
91
|
+
if (typeName === 'kal_txn.ProposalCancelTXN')
|
|
92
|
+
return TRANSACTION_TYPE.PROPOSAL_CANCEL_TYPE;
|
|
93
|
+
// If we can't determine the type, throw an error
|
|
94
|
+
throw new Error('Unable to determine transaction type from protoObject structure');
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Failed to extract transaction type from protoObject: ${error instanceof Error ? error.message : String(error)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extract key types and restricted status from a transaction protobuf object
|
|
102
|
+
*/
|
|
103
|
+
function extractKeyTypesFromTransaction(protoObject) {
|
|
104
|
+
const keyTypes = [];
|
|
105
|
+
let isRestricted = false;
|
|
106
|
+
try {
|
|
107
|
+
// Check if this is a CoinTXN (has auth field with publicKey array)
|
|
108
|
+
if (hasAuthProperty(protoObject) &&
|
|
109
|
+
typeof protoObject.auth === 'object' &&
|
|
110
|
+
protoObject.auth !== null &&
|
|
111
|
+
'publicKey' in protoObject.auth &&
|
|
112
|
+
Array.isArray(protoObject.auth.publicKey)) {
|
|
113
|
+
// CoinTXN: extract key types from TransferAuthentication.publicKey array
|
|
114
|
+
const authObj = protoObject.auth;
|
|
115
|
+
for (const publicKey of authObj.publicKey) {
|
|
116
|
+
if (typeof publicKey === 'object' && publicKey !== null && 'single' in publicKey) {
|
|
117
|
+
const publicKeyObj = publicKey;
|
|
118
|
+
// Single key - convert bytes back to string identifier for key type detection
|
|
119
|
+
const publicKeyString = getPublicKeyIdentifierFromBytes(publicKeyObj.single);
|
|
120
|
+
// Check if this public key is restricted (starts with 'r_')
|
|
121
|
+
if (publicKeyString.startsWith('r_')) {
|
|
122
|
+
isRestricted = true;
|
|
123
|
+
}
|
|
124
|
+
const keyType = getKeyTypeFromPublicKey(publicKeyString);
|
|
125
|
+
keyTypes.push(keyType);
|
|
126
|
+
}
|
|
127
|
+
else if (typeof publicKey === 'object' && publicKey !== null && 'multi' in publicKey) {
|
|
128
|
+
const publicKeyObj = publicKey;
|
|
129
|
+
if (publicKeyObj.multi && typeof publicKeyObj.multi === 'object' && publicKeyObj.multi !== null && 'publicKeys' in publicKeyObj.multi) {
|
|
130
|
+
throw new Error('Multi-signature wallets are not currentlysupported in the SDK');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (hasBaseProperty(protoObject) &&
|
|
136
|
+
typeof protoObject.base === 'object' &&
|
|
137
|
+
protoObject.base !== null &&
|
|
138
|
+
'publicKey' in protoObject.base) {
|
|
139
|
+
// Non-CoinTXN: extract key type from BaseTXN.public_key
|
|
140
|
+
const baseObj = protoObject.base;
|
|
141
|
+
const publicKey = baseObj.publicKey;
|
|
142
|
+
if (typeof publicKey === 'object' && publicKey !== null && 'single' in publicKey) {
|
|
143
|
+
const publicKeyObj = publicKey;
|
|
144
|
+
const publicKeyString = getPublicKeyIdentifierFromBytes(publicKeyObj.single);
|
|
145
|
+
// Check if this public key is restricted (starts with 'r_')
|
|
146
|
+
if (publicKeyString.startsWith('r_')) {
|
|
147
|
+
isRestricted = true;
|
|
148
|
+
}
|
|
149
|
+
const keyType = getKeyTypeFromPublicKey(publicKeyString);
|
|
150
|
+
keyTypes.push(keyType);
|
|
151
|
+
}
|
|
152
|
+
else if (typeof publicKey === 'object' && publicKey !== null && 'multi' in publicKey) {
|
|
153
|
+
const publicKeyObj = publicKey;
|
|
154
|
+
if (publicKeyObj.multi && typeof publicKeyObj.multi === 'object' && publicKeyObj.multi !== null && 'publicKeys' in publicKeyObj.multi) {
|
|
155
|
+
logger.warn('Multi-signature wallet not currently supported', {
|
|
156
|
+
operation: 'extractHashTypes',
|
|
157
|
+
walletType: 'multi-signature'
|
|
158
|
+
});
|
|
159
|
+
throw new Error('Multi-signature wallet not currently supported in SDK');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new Error(`Failed to extract key types from transaction: ${error instanceof Error ? error.message : String(error)}`);
|
|
166
|
+
}
|
|
167
|
+
// Throw error if no key types found
|
|
168
|
+
if (keyTypes.length === 0) {
|
|
169
|
+
if (hasAuthProperty(protoObject) &&
|
|
170
|
+
typeof protoObject.auth === 'object' &&
|
|
171
|
+
protoObject.auth !== null &&
|
|
172
|
+
'publicKey' in protoObject.auth) {
|
|
173
|
+
throw new Error('Failed to detect key types from CoinTXN transaction. Check that publicKey array contains valid key structures.');
|
|
174
|
+
}
|
|
175
|
+
else if (hasBaseProperty(protoObject) &&
|
|
176
|
+
typeof protoObject.base === 'object' &&
|
|
177
|
+
protoObject.base !== null &&
|
|
178
|
+
'publicKey' in protoObject.base) {
|
|
179
|
+
throw new Error('Failed to detect key type from BaseTXN transaction. Check that publicKey contains valid key structure.');
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw new Error('Failed to detect key types from transaction. Transaction must have either auth.publicKey (CoinTXN) or base.publicKey (other types).');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { keyTypes, isRestricted };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Calculate total transaction size from protobuf object + signatures + hashes
|
|
189
|
+
*/
|
|
190
|
+
function calculateTotalTransactionSize(protoObject) {
|
|
191
|
+
// Auto-detect transaction type from protobuf object
|
|
192
|
+
const detectedTransactionType = extractTransactionTypeFromProtoObject(protoObject);
|
|
193
|
+
// Check if transaction type is valid (0 is a valid transaction type, so check for null/undefined)
|
|
194
|
+
if (detectedTransactionType === null || detectedTransactionType === undefined) {
|
|
195
|
+
throw new Error('detectedTransactionType is null or undefined');
|
|
196
|
+
}
|
|
197
|
+
// Get the serialized size of the protobuf object using v2 schema-based toBinary
|
|
198
|
+
const typeName = protoObject.$typeName;
|
|
199
|
+
if (!typeName) {
|
|
200
|
+
throw new Error('Cannot serialize transaction: missing $typeName property');
|
|
201
|
+
}
|
|
202
|
+
const schema = getSchemaForTypeName(typeName);
|
|
203
|
+
if (!schema) {
|
|
204
|
+
throw new Error(`Cannot serialize transaction: no schema found for type "${typeName}"`);
|
|
205
|
+
}
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
|
+
const binary = toBinary(schema, protoObject);
|
|
208
|
+
const protoSize = binary.length;
|
|
209
|
+
// Auto-detect key types from transaction
|
|
210
|
+
const { keyTypes } = extractKeyTypesFromTransaction(protoObject);
|
|
211
|
+
// Calculate signature sizes
|
|
212
|
+
let signatureSize = 0;
|
|
213
|
+
for (const keyType of keyTypes) {
|
|
214
|
+
const rawSignatureSize = getSignatureSize(keyType);
|
|
215
|
+
if (detectedTransactionType === TRANSACTION_TYPE.COIN_TYPE) {
|
|
216
|
+
signatureSize += rawSignatureSize + PROTOBUF_AUTH_SIGNATURE_OVERHEAD;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
signatureSize += rawSignatureSize + PROTOBUF_BASE_SIGNATURE_OVERHEAD;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Accomodate single ED448 key signature overhead (inferred cause of calculation issue based on integration testing)
|
|
223
|
+
if (keyTypes.length === 1 && keyTypes[0] === KEY_TYPE.ED448) {
|
|
224
|
+
signatureSize += 1;
|
|
225
|
+
}
|
|
226
|
+
// Calculate hash size with protobuf overhead
|
|
227
|
+
const totalHashSize = HASH_SIZE + PROTOBUF_HASH_OVERHEAD;
|
|
228
|
+
return protoSize + signatureSize + totalHashSize;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Calculate contract fee using the service
|
|
232
|
+
*/
|
|
233
|
+
function calculateContractFee(protoObject, contractFeeId, contractFee, contractFeeParts, tokenInfoMap, overestimatePercent = 5.0) {
|
|
234
|
+
try {
|
|
235
|
+
// Extract contract ID and outputs directly from the protobuf object
|
|
236
|
+
const contractId = isCoinTXN(protoObject) ? protoObject.contractId : 'invalid';
|
|
237
|
+
if (contractId === 'invalid') {
|
|
238
|
+
throw new Error('contractId not found');
|
|
239
|
+
}
|
|
240
|
+
// Handle manual contract fee in smallest units/parts - skip all calculation and conversion
|
|
241
|
+
if (contractFeeParts !== undefined && contractFeeId) {
|
|
242
|
+
logger.warn('Manual contract fee parts specified - skipping fee calculation and conversion. Fee is not validated and may be insufficient, causing transaction failure.', {
|
|
243
|
+
contractFeeId,
|
|
244
|
+
providedFeeParts: contractFeeParts,
|
|
245
|
+
operation: 'manualContractFeeParts'
|
|
246
|
+
});
|
|
247
|
+
const coinTxnProto = protoObject;
|
|
248
|
+
coinTxnProto.contractFeeId = contractFeeId;
|
|
249
|
+
coinTxnProto.contractFeeAmount = contractFeeParts;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
// Handle manual contract fee - skip all calculation, validation, and overestimation
|
|
253
|
+
if (contractFee !== undefined && contractFeeId) {
|
|
254
|
+
const contractFeeInSmallestUnits = toSmallestUnits(contractFee, contractFeeId, tokenInfoMap ? { tokenInfoMap } : {});
|
|
255
|
+
logger.warn('Manual contract fee specified - skipping fee calculation and validation. Fee is not validated and may be insufficient, causing transaction failure.', {
|
|
256
|
+
contractFeeId,
|
|
257
|
+
providedFee: contractFeeInSmallestUnits,
|
|
258
|
+
operation: 'manualContractFee'
|
|
259
|
+
});
|
|
260
|
+
// Set the contract fee directly (no overestimation for manual fees)
|
|
261
|
+
const coinTxnProto = protoObject;
|
|
262
|
+
coinTxnProto.contractFeeId = contractFeeId;
|
|
263
|
+
coinTxnProto.contractFeeAmount = contractFeeInSmallestUnits;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const outputTransfers = isCoinTXN(protoObject) ? (protoObject.outputTransfers || []) : [];
|
|
267
|
+
const contractFeeInfo = tokenInfoMap?.get(contractId)?.contractFees;
|
|
268
|
+
let transactionAmount = '0';
|
|
269
|
+
if (contractFeeInfo && Object.keys(contractFeeInfo).length > 0) {
|
|
270
|
+
// Check if contract allows any fee instruments at all
|
|
271
|
+
if (!contractFeeInfo.allowedFeeInstrument || contractFeeInfo.allowedFeeInstrument.length === 0) {
|
|
272
|
+
// Contract doesn't allow fee instruments, skip contract fee
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
// Default contractFeeId to contractId if undefined
|
|
276
|
+
contractFeeId = contractFeeId || contractId;
|
|
277
|
+
// Check to see is contractFeeId is a valid for this contractID
|
|
278
|
+
if (contractFeeInfo.allowedFeeInstrument && !contractFeeInfo.allowedFeeInstrument.includes(contractFeeId)) {
|
|
279
|
+
logger.warn('Contract fee ID not allowed for contract', {
|
|
280
|
+
contractId,
|
|
281
|
+
contractFeeId,
|
|
282
|
+
allowedFeeInstrument: contractFeeInfo.allowedFeeInstrument,
|
|
283
|
+
operation: 'validateContractFeeId'
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
// Get the current token rate for converting transaction amount to USD
|
|
287
|
+
const currentTokenInfo = tokenInfoMap?.get(contractId);
|
|
288
|
+
if (!currentTokenInfo?.rate) {
|
|
289
|
+
throw new Error(`Exchange rate not available for contract ${contractId}`);
|
|
290
|
+
}
|
|
291
|
+
// Calculate total transaction amount
|
|
292
|
+
const outputAmounts = outputTransfers.map((o) => toDecimal(o.amount));
|
|
293
|
+
const totalTransactionAmountInSmallestUnits = outputAmounts.reduce((sum, amount) => {
|
|
294
|
+
return sum.add(amount);
|
|
295
|
+
}, new Decimal(0));
|
|
296
|
+
let denominationDecimals;
|
|
297
|
+
if (currentTokenInfo.denomination) {
|
|
298
|
+
denominationDecimals = getDecimalPlacesFromDenomination(currentTokenInfo.denomination);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
const fallbackDenomination = getDenominationFallback(contractId);
|
|
302
|
+
denominationDecimals = getDecimalPlacesFromDenomination(fallbackDenomination);
|
|
303
|
+
}
|
|
304
|
+
// Convert smallest units to USD value
|
|
305
|
+
// Formula: ((smallest_units / 10^denomination_decimals) * rate) / 1e18 = USD value
|
|
306
|
+
const transactionAmountInTokenUnits = toDecimal(totalTransactionAmountInSmallestUnits).div(new Decimal(10).pow(denominationDecimals));
|
|
307
|
+
const rateDecimal = toDecimal(currentTokenInfo.rate);
|
|
308
|
+
const usdValueScaled = transactionAmountInTokenUnits.mul(rateDecimal);
|
|
309
|
+
// Helper function to get fee token info and decimals
|
|
310
|
+
const getFeeTokenInfo = (feeContractId) => {
|
|
311
|
+
const feeTokenInfo = tokenInfoMap?.get(feeContractId);
|
|
312
|
+
if (!feeTokenInfo?.rate) {
|
|
313
|
+
throw new Error(`Exchange rate not available for fee contract ${feeContractId}`);
|
|
314
|
+
}
|
|
315
|
+
let feeTokenDecimals;
|
|
316
|
+
if (feeTokenInfo.denomination) {
|
|
317
|
+
feeTokenDecimals = getDecimalPlacesFromDenomination(feeTokenInfo.denomination);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const feeTokenFallbackDenomination = getDenominationFallback(feeContractId);
|
|
321
|
+
feeTokenDecimals = getDecimalPlacesFromDenomination(feeTokenFallbackDenomination);
|
|
322
|
+
}
|
|
323
|
+
return { feeTokenInfo, feeTokenDecimals };
|
|
324
|
+
};
|
|
325
|
+
// Helper function to convert USD amount to fee token smallest units
|
|
326
|
+
const convertUsdToFeeTokenSmallestUnits = (usdAmount, feeContractId) => {
|
|
327
|
+
const { feeTokenInfo, feeTokenDecimals } = getFeeTokenInfo(feeContractId);
|
|
328
|
+
const feeTokenRateDecimal = toDecimal(feeTokenInfo.rate);
|
|
329
|
+
const feeTokenUnitsDecimal = usdAmount.div(feeTokenRateDecimal);
|
|
330
|
+
const feeTokenAmountDecimal = feeTokenUnitsDecimal.mul(new Decimal(10).pow(feeTokenDecimals));
|
|
331
|
+
return feeTokenAmountDecimal.floor().toString();
|
|
332
|
+
};
|
|
333
|
+
// Calculate transaction amount based on fee type
|
|
334
|
+
if (contractFeeInfo.contractFeeType === CONTRACT_FEE_TYPE.FIXED) {
|
|
335
|
+
// Fixed fee - feeAmountDecimal is the number of token units, not USD value
|
|
336
|
+
transactionAmount = contractFeeInfo.fee;
|
|
337
|
+
// If fee is not in the contractId token, need conversions
|
|
338
|
+
if (contractFeeId !== contractId) {
|
|
339
|
+
const feeAmountDecimal = toDecimal(contractFeeInfo.fee);
|
|
340
|
+
const feeAmountInUsd = feeAmountDecimal.mul(new Decimal(10).pow(-denominationDecimals)).mul(rateDecimal);
|
|
341
|
+
transactionAmount = convertUsdToFeeTokenSmallestUnits(feeAmountInUsd, contractFeeId);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else if (contractFeeInfo.contractFeeType === CONTRACT_FEE_TYPE.CUR_EQUIVALENT) {
|
|
345
|
+
// Currency equivalent fee - convert USD amount to fee contract ID
|
|
346
|
+
const feeAmountDecimal = toDecimal(contractFeeInfo.fee);
|
|
347
|
+
transactionAmount = convertUsdToFeeTokenSmallestUnits(feeAmountDecimal, contractFeeId);
|
|
348
|
+
}
|
|
349
|
+
else if (contractFeeInfo.contractFeeType === CONTRACT_FEE_TYPE.PERCENTAGE) {
|
|
350
|
+
// Percentage fee - contractFeeInfo.fee is in smallest units where 1e18 = 100%
|
|
351
|
+
const feePercentageDecimal = toDecimal(contractFeeInfo.fee);
|
|
352
|
+
if (contractFeeId !== contractId) {
|
|
353
|
+
// Convert smallest units to percentage (1e18 = 100%), then calculate USD equivalent
|
|
354
|
+
const percentageValue = feePercentageDecimal.div(new Decimal(10).pow(18)).mul(100);
|
|
355
|
+
const percentageOfTransactionUSD = usdValueScaled.mul(percentageValue).div(100);
|
|
356
|
+
transactionAmount = convertUsdToFeeTokenSmallestUnits(percentageOfTransactionUSD, contractFeeId);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
// Same currency - convert smallest units to percentage, then calculate directly
|
|
360
|
+
const percentageValue = feePercentageDecimal.div(new Decimal(10).pow(18)).mul(100);
|
|
361
|
+
const percentageOfTransaction = totalTransactionAmountInSmallestUnits.mul(percentageValue).div(100);
|
|
362
|
+
transactionAmount = percentageOfTransaction.floor().toString();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (contractFeeInfo.contractFeeType === CONTRACT_FEE_TYPE.NONE) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
logger.warn('Unsupported contract fee type', {
|
|
370
|
+
contractFeeType: contractFeeInfo.contractFeeType,
|
|
371
|
+
operation: 'calculateContractFee'
|
|
372
|
+
});
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
// Apply overestimation to fee
|
|
380
|
+
if (overestimatePercent > 0) {
|
|
381
|
+
const overestimateMultiplier = new Decimal(100 + overestimatePercent).div(100);
|
|
382
|
+
const overestimatedFeeDecimal = toDecimal(transactionAmount).mul(overestimateMultiplier);
|
|
383
|
+
transactionAmount = overestimatedFeeDecimal.floor().toString();
|
|
384
|
+
}
|
|
385
|
+
// Add contract fee fields to protoObject for TRANSACTION_TYPE.COIN_TYPE
|
|
386
|
+
if (contractFeeId && transactionAmount) {
|
|
387
|
+
const coinTxnProto = protoObject;
|
|
388
|
+
coinTxnProto.contractFeeId = contractFeeId;
|
|
389
|
+
coinTxnProto.contractFeeAmount = transactionAmount;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
throw new Error(`Contract fee calculation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Calculate interface fee
|
|
398
|
+
*/
|
|
399
|
+
function calculateInterfaceFee(protoObject, interfaceFeeAmount, interfaceFeeId, interfaceAddress, tokenInfoMap) {
|
|
400
|
+
if (!interfaceFeeAmount || !interfaceFeeId) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (!interfaceAddress) {
|
|
404
|
+
logger.warn('Interface address required for interface fee', {
|
|
405
|
+
operation: 'calculateInterfaceFee'
|
|
406
|
+
});
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
// Convert interface fee to smallest units
|
|
410
|
+
const feeInSmallestUnits = toSmallestUnits(interfaceFeeAmount, interfaceFeeId, tokenInfoMap ? { tokenInfoMap } : {});
|
|
411
|
+
// Add interface fee fields to base object (works for all transaction types)
|
|
412
|
+
const txnProto = protoObject;
|
|
413
|
+
if (txnProto.base) {
|
|
414
|
+
txnProto.base.interfaceFee = feeInSmallestUnits;
|
|
415
|
+
txnProto.base.interfaceFeeId = interfaceFeeId;
|
|
416
|
+
if (interfaceAddress) {
|
|
417
|
+
txnProto.base.interfaceAddress = sanitizeAndDecodeAddress(interfaceAddress);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Calculate gas fee in smallest units from USD
|
|
423
|
+
*/
|
|
424
|
+
function calculateGasFee(gasFeeInUsd, baseFeeId, tokenInfoMap) {
|
|
425
|
+
const tokenInfo = tokenInfoMap?.get(baseFeeId);
|
|
426
|
+
if (!tokenInfo) {
|
|
427
|
+
throw new Error(`Token info not found for fee ID ${baseFeeId} when calculating gas fee`);
|
|
428
|
+
}
|
|
429
|
+
// Non-native fee instruments (anything other than KALXvxhUMJERCse4e6b2jeXFkcqqpiUByQQckvPZm4szmF3Ao) incur a 10x cost multiplier
|
|
430
|
+
const NON_NATIVE_FEE_MULTIPLIER = 10;
|
|
431
|
+
const feeMultiplier = baseFeeId !== KALVORA_NATIVE_TOKEN ? NON_NATIVE_FEE_MULTIPLIER : 1;
|
|
432
|
+
// Gas fee is provided in USD (e.g., 0.50 for 50 cents)
|
|
433
|
+
// Scale to 1e18 for precision: convert USD to scaled cents (multiply by 100 to get cents, then by 1e18)
|
|
434
|
+
const gasFeeInUsdScaled = new Decimal(gasFeeInUsd).mul(1e18).mul(feeMultiplier);
|
|
435
|
+
// Convert USD cents to fee token units using exchange rate
|
|
436
|
+
// Exchange rate is stored as: 1 fee token = X USD cents
|
|
437
|
+
const exchangeRate = tokenInfo.rate ? toDecimal(tokenInfo.rate) : new Decimal(1);
|
|
438
|
+
// Gas fee in fee token units = gasFeeInCents / exchangeRate
|
|
439
|
+
const gasFeeInTokenUnits = gasFeeInUsdScaled.div(exchangeRate);
|
|
440
|
+
// Get decimals for precision handling
|
|
441
|
+
let decimals;
|
|
442
|
+
if (tokenInfo.denomination) {
|
|
443
|
+
decimals = getDecimalPlacesFromDenomination(tokenInfo.denomination);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
throw new Error(`Token info missing denomination for ${baseFeeId}`);
|
|
447
|
+
}
|
|
448
|
+
// Round to proper precision
|
|
449
|
+
const precisionMultiplier = new Decimal(10).pow(decimals);
|
|
450
|
+
const roundedGasFee = gasFeeInTokenUnits.mul(precisionMultiplier).floor().div(precisionMultiplier);
|
|
451
|
+
// Ensure minimum if rounding results in zero but original was > 0
|
|
452
|
+
const finalGasFee = roundedGasFee.equals(0) && gasFeeInTokenUnits.greaterThan(0)
|
|
453
|
+
? new Decimal(10).pow(-decimals)
|
|
454
|
+
: roundedGasFee;
|
|
455
|
+
// Convert to smallest units
|
|
456
|
+
return toSmallestUnits(finalGasFee.toString(), baseFeeId, tokenInfoMap ? { tokenInfoMap } : {});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Extract the first PublicKey protobuf object from a transaction.
|
|
460
|
+
* Used to pass the public key to the BaseFee API for accurate fee calculation.
|
|
461
|
+
*/
|
|
462
|
+
function extractPublicKeyFromTransaction(protoObject) {
|
|
463
|
+
try {
|
|
464
|
+
// CoinTXN: public keys are in auth.publicKey[]
|
|
465
|
+
if (hasAuthProperty(protoObject) &&
|
|
466
|
+
typeof protoObject.auth === 'object' &&
|
|
467
|
+
protoObject.auth !== null &&
|
|
468
|
+
'publicKey' in protoObject.auth &&
|
|
469
|
+
Array.isArray(protoObject.auth.publicKey)) {
|
|
470
|
+
const authObj = protoObject.auth;
|
|
471
|
+
const publicKeys = authObj.publicKey;
|
|
472
|
+
if (publicKeys.length > 0) {
|
|
473
|
+
return publicKeys[0];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
// Other transaction types: public key is in base.publicKey
|
|
477
|
+
else if (hasBaseProperty(protoObject) &&
|
|
478
|
+
typeof protoObject.base === 'object' &&
|
|
479
|
+
protoObject.base !== null &&
|
|
480
|
+
'publicKey' in protoObject.base) {
|
|
481
|
+
const baseObj = protoObject.base;
|
|
482
|
+
return baseObj.publicKey;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
// If extraction fails, return undefined (will use fallback constants)
|
|
487
|
+
}
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Calculate network fee based on proto object.
|
|
492
|
+
*
|
|
493
|
+
* Tries the BaseFee gRPC API first to get network-sourced key_fee and byte_fee.
|
|
494
|
+
* Falls back to hardcoded constants if the API call fails.
|
|
495
|
+
*
|
|
496
|
+
* Returns the newWalletFee from the BaseFee API response (in 1e18 = $1.00 format)
|
|
497
|
+
* for use in new token balance fee calculation.
|
|
498
|
+
*
|
|
499
|
+
*! Note: This function may not be 100% accurate. Nominal testing indicates accuracy within >= 99.999999% (usually exact or 1 denomination unit greater). Minimal accuracy difference design choice for better code understandability rather than working strictly with scaled numbers.
|
|
500
|
+
*! Note: Suggest 'maximum' overestimation to account for edge cases such as changes in ACE rates after transaction calculation.
|
|
501
|
+
*/
|
|
502
|
+
async function calculateNetworkFee(protoObject, transactionType, baseFeeId = KALVORA_NATIVE_TOKEN, baseFee, baseFeeParts, tokenInfoMap, overestimatePercent = 5.0, gasFeeInUsd, grpcConfig, onBaseFeeCalculated) {
|
|
503
|
+
// Handle manual base fee in smallest units/parts - skip all calculation and conversion
|
|
504
|
+
if (baseFeeParts !== undefined) {
|
|
505
|
+
logger.warn('Manual base fee parts specified - skipping fee calculation and conversion. Fee is not validated and may be insufficient, causing transaction failure.', {
|
|
506
|
+
baseFeeId,
|
|
507
|
+
providedFeeParts: baseFeeParts,
|
|
508
|
+
operation: 'manualBaseFeeParts'
|
|
509
|
+
});
|
|
510
|
+
let finalFee = baseFeeParts;
|
|
511
|
+
// Add gas fee if provided (only applicable for SmartContractExecuteTXN)
|
|
512
|
+
if (gasFeeInUsd !== undefined && gasFeeInUsd > 0) {
|
|
513
|
+
const gasFeeInSmallestUnits = calculateGasFee(gasFeeInUsd, baseFeeId, tokenInfoMap);
|
|
514
|
+
const baseFeeDecimal = toDecimal(finalFee);
|
|
515
|
+
const gasFeeDecimal = toDecimal(gasFeeInSmallestUnits);
|
|
516
|
+
finalFee = baseFeeDecimal.add(gasFeeDecimal).floor().toString();
|
|
517
|
+
}
|
|
518
|
+
const txnProto = protoObject;
|
|
519
|
+
if (txnProto.base) {
|
|
520
|
+
txnProto.base.feeAmount = finalFee;
|
|
521
|
+
txnProto.base.feeId = baseFeeId;
|
|
522
|
+
}
|
|
523
|
+
return '0';
|
|
524
|
+
}
|
|
525
|
+
// Handle manual base fee - skip all calculation, validation, and overestimation
|
|
526
|
+
if (baseFee !== undefined) {
|
|
527
|
+
const baseFeeInSmallestUnits = toSmallestUnits(baseFee, baseFeeId, tokenInfoMap ? { tokenInfoMap } : {});
|
|
528
|
+
logger.warn('Manual base fee specified - skipping fee calculation and validation. Fee is not validated and may be insufficient, causing transaction failure.', {
|
|
529
|
+
baseFeeId,
|
|
530
|
+
providedFee: baseFeeInSmallestUnits,
|
|
531
|
+
operation: 'manualBaseFee'
|
|
532
|
+
});
|
|
533
|
+
// Use the manual fee directly (no overestimation for manual fees)
|
|
534
|
+
let finalFee = baseFeeInSmallestUnits;
|
|
535
|
+
// Add gas fee if provided (only applicable for SmartContractExecuteTXN)
|
|
536
|
+
if (gasFeeInUsd !== undefined && gasFeeInUsd > 0) {
|
|
537
|
+
const gasFeeInSmallestUnits = calculateGasFee(gasFeeInUsd, baseFeeId, tokenInfoMap);
|
|
538
|
+
const baseFeeDecimal = toDecimal(finalFee);
|
|
539
|
+
const gasFeeDecimal = toDecimal(gasFeeInSmallestUnits);
|
|
540
|
+
finalFee = baseFeeDecimal.add(gasFeeDecimal).floor().toString();
|
|
541
|
+
}
|
|
542
|
+
// Set the base fee directly
|
|
543
|
+
const txnProto = protoObject;
|
|
544
|
+
if (txnProto.base) {
|
|
545
|
+
txnProto.base.feeAmount = finalFee;
|
|
546
|
+
txnProto.base.feeId = baseFeeId;
|
|
547
|
+
}
|
|
548
|
+
return '0';
|
|
549
|
+
}
|
|
550
|
+
// Calculate initial transaction size (with placeholder fee amount)
|
|
551
|
+
let transactionSize = calculateTotalTransactionSize(protoObject);
|
|
552
|
+
// Get fees from the BaseFee API (network-sourced, always up to date)
|
|
553
|
+
const publicKey = extractPublicKeyFromTransaction(protoObject);
|
|
554
|
+
const baseFeeResponse = await getBaseFee(transactionType, publicKey ?? undefined, grpcConfig);
|
|
555
|
+
// Capture the new wallet fee from the API response (1e18 = $1.00 format)
|
|
556
|
+
const newWalletFeeScaled = baseFeeResponse.newWalletFee || '0';
|
|
557
|
+
// Non-native fee instruments (anything other than KALXvxhUMJERCse4e6b2jeXFkcqqpiUByQQckvPZm4szmF3Ao) incur a 10x cost multiplier
|
|
558
|
+
const NON_NATIVE_FEE_MULTIPLIER = 10;
|
|
559
|
+
const feeMultiplier = baseFeeId !== KALVORA_NATIVE_TOKEN ? NON_NATIVE_FEE_MULTIPLIER : 1;
|
|
560
|
+
// API returns fees in 1e18 = $1.00 format, convert to USD
|
|
561
|
+
// byte_fee is per-byte, key_fee is the total key+hash fee for this signer
|
|
562
|
+
const perByteFee = new Decimal(baseFeeResponse.byteFee || '0').div(new Decimal(10).pow(18));
|
|
563
|
+
const totalKeyAndHashFees = new Decimal(baseFeeResponse.keyFee || '0').div(new Decimal(10).pow(18)).mul(feeMultiplier);
|
|
564
|
+
// Calculate initial base network fee: transaction size * per-byte fee (with non-native multiplier)
|
|
565
|
+
const baseNetworkFeeEquiv = toDecimal(transactionSize).mul(perByteFee).mul(feeMultiplier);
|
|
566
|
+
// Calculate initial total network fee: base fee + key fees + hash fees
|
|
567
|
+
const totalNetworkFeeScaled = baseNetworkFeeEquiv.add(totalKeyAndHashFees).mul(1e18);
|
|
568
|
+
// Get exchange rate for base fee
|
|
569
|
+
const tokenInfo = tokenInfoMap?.get(baseFeeId);
|
|
570
|
+
const exchangeRate = tokenInfo?.rate ? toDecimal(tokenInfo.rate) : new Decimal(1);
|
|
571
|
+
// Use precise division with proper rounding for base fees
|
|
572
|
+
const totalNetworkFee = totalNetworkFeeScaled.div(exchangeRate);
|
|
573
|
+
// Get token fee info to determine precision from denomination
|
|
574
|
+
let decimals;
|
|
575
|
+
if (tokenInfoMap && tokenInfoMap.has(baseFeeId)) {
|
|
576
|
+
// Use cached token info for faster access and consistency
|
|
577
|
+
const tokenInfo = tokenInfoMap.get(baseFeeId);
|
|
578
|
+
if (tokenInfo?.denomination) {
|
|
579
|
+
decimals = getDecimalPlacesFromDenomination(tokenInfo.denomination);
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
throw new Error(`Unexpected error: Token info found but missing denomination for ${baseFeeId}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
throw new Error(`Token info not found for base fee ID ${baseFeeId}`);
|
|
587
|
+
}
|
|
588
|
+
// Round to the precision specified by the denomination
|
|
589
|
+
const precisionMultiplier = new Decimal(10).pow(decimals);
|
|
590
|
+
let roundedFee = totalNetworkFee.mul(precisionMultiplier).floor().div(precisionMultiplier);
|
|
591
|
+
// Ensure minimum fee if rounding results in zero but original fee was > 0
|
|
592
|
+
if (roundedFee.equals(0) && totalNetworkFee.greaterThan(0)) {
|
|
593
|
+
roundedFee = new Decimal(10).pow(-decimals); // Set to minimum unit (1 satoshi)
|
|
594
|
+
}
|
|
595
|
+
// Convert to smallest units with precise denomination-based precision
|
|
596
|
+
const conversionOptions = { isBaseFee: true };
|
|
597
|
+
if (tokenInfoMap) {
|
|
598
|
+
conversionOptions.tokenInfoMap = tokenInfoMap;
|
|
599
|
+
}
|
|
600
|
+
let transactionAmount = toSmallestUnits(roundedFee.toString(), baseFeeId, conversionOptions);
|
|
601
|
+
// Calculate the difference in size between placeholder '1' and actual fee
|
|
602
|
+
const placeholderFeeSize = 1; // Size of '1' in bytes
|
|
603
|
+
const actualFeeSize = transactionAmount.length; // Size of actual fee string in bytes
|
|
604
|
+
const feeSizeDifference = actualFeeSize - placeholderFeeSize;
|
|
605
|
+
// If there's a size difference, recalculate the fee with the corrected transaction size
|
|
606
|
+
if (feeSizeDifference > 0) {
|
|
607
|
+
// Add the size difference to transaction size
|
|
608
|
+
const correctedTransactionSize = transactionSize + feeSizeDifference;
|
|
609
|
+
// Recalculate base network fee with corrected size (with non-native multiplier)
|
|
610
|
+
const correctedBaseNetworkFeeEquiv = toDecimal(correctedTransactionSize).mul(perByteFee).mul(feeMultiplier);
|
|
611
|
+
// Recalculate total network fee
|
|
612
|
+
const correctedTotalNetworkFeeEquiv = correctedBaseNetworkFeeEquiv.add(totalKeyAndHashFees).mul(1e18);
|
|
613
|
+
// Use precise division with proper rounding for base fees
|
|
614
|
+
const correctedTotalNetworkFee = correctedTotalNetworkFeeEquiv.div(exchangeRate);
|
|
615
|
+
// Round to the precision specified by the denomination
|
|
616
|
+
const precisionMultiplier = new Decimal(10).pow(decimals);
|
|
617
|
+
const correctedRoundedFee = correctedTotalNetworkFee.mul(precisionMultiplier).floor().div(precisionMultiplier);
|
|
618
|
+
// Update the fee in smallest units with precise denomination-based precision
|
|
619
|
+
transactionAmount = toSmallestUnits(correctedRoundedFee.toString(), baseFeeId, conversionOptions);
|
|
620
|
+
// Update transaction size for return value
|
|
621
|
+
transactionSize = correctedTransactionSize;
|
|
622
|
+
}
|
|
623
|
+
// Apply overestimation to fee
|
|
624
|
+
if (overestimatePercent > 0) {
|
|
625
|
+
const overestimateMultiplier = new Decimal(100 + overestimatePercent).div(100);
|
|
626
|
+
const overestimatedFeeDecimal = toDecimal(transactionAmount).mul(overestimateMultiplier);
|
|
627
|
+
transactionAmount = overestimatedFeeDecimal.floor().toString();
|
|
628
|
+
}
|
|
629
|
+
// Add gas fee if provided (only applicable for SmartContractExecuteTXN)
|
|
630
|
+
if (gasFeeInUsd !== undefined && gasFeeInUsd > 0) {
|
|
631
|
+
const gasFeeInSmallestUnits = calculateGasFee(gasFeeInUsd, baseFeeId, tokenInfoMap);
|
|
632
|
+
const baseFeeDecimal = toDecimal(transactionAmount);
|
|
633
|
+
const gasFeeDecimal = toDecimal(gasFeeInSmallestUnits);
|
|
634
|
+
const totalFeeDecimal = baseFeeDecimal.add(gasFeeDecimal);
|
|
635
|
+
transactionAmount = totalFeeDecimal.floor().toString();
|
|
636
|
+
}
|
|
637
|
+
// Add base fee fields to base object (works for all transaction types)
|
|
638
|
+
const txnProto = protoObject;
|
|
639
|
+
if (txnProto.base) {
|
|
640
|
+
txnProto.base.feeAmount = transactionAmount;
|
|
641
|
+
txnProto.base.feeId = baseFeeId;
|
|
642
|
+
}
|
|
643
|
+
onBaseFeeCalculated?.({
|
|
644
|
+
transactionType,
|
|
645
|
+
baseFeeId,
|
|
646
|
+
...(publicKey ? { publicKey } : {}),
|
|
647
|
+
baseFeeResponse,
|
|
648
|
+
feeMultiplier,
|
|
649
|
+
transactionSize,
|
|
650
|
+
feeAmountParts: transactionAmount,
|
|
651
|
+
newWalletFeeScaled
|
|
652
|
+
});
|
|
653
|
+
return newWalletFeeScaled;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Calculate additional network fee for addresses that don't hold the transferred token.
|
|
657
|
+
*
|
|
658
|
+
* For CoinTXN (token transfers), the network charges an additional fee when a recipient
|
|
659
|
+
* address doesn't currently have that token. This function checks all destination
|
|
660
|
+
* addresses, adding the network-sourced new wallet fee per recipient without a balance.
|
|
661
|
+
*
|
|
662
|
+
* @note The sender is NOT checked — only output (recipient) addresses are relevant.
|
|
663
|
+
*
|
|
664
|
+
* @param protoObject - The CoinTXN protobuf object (must have outputTransfers)
|
|
665
|
+
* @param baseFeeId - The base fee instrument ID (e.g., 'KALXvxhUMJERCse4e6b2jeXFkcqqpiUByQQckvPZm4szmF3Ao')
|
|
666
|
+
* @param contractId - The contract ID of the token being transferred
|
|
667
|
+
* @param tokenInfoMap - Map of token info including exchange rates
|
|
668
|
+
* @param newWalletFeeScaled - The new wallet fee from BaseFee API in 1e18 = $1.00 format
|
|
669
|
+
* @param grpcConfig - gRPC configuration for balance lookups
|
|
670
|
+
* @param needsInitialization - Optional override: true = always add fee, false = never add fee, undefined = auto-detect
|
|
671
|
+
*/
|
|
672
|
+
async function calculateNewTokenBalanceFee(protoObject, baseFeeId, contractId, tokenInfoMap, newWalletFeeScaled, grpcConfig, needsInitialization) {
|
|
673
|
+
if (!isCoinTXN(protoObject))
|
|
674
|
+
return;
|
|
675
|
+
const coinTxn = protoObject;
|
|
676
|
+
const addressesToCheck = [];
|
|
677
|
+
// 1. Extract destination addresses from outputTransfers (stored as base58-decoded Uint8Array)
|
|
678
|
+
if (coinTxn.outputTransfers && coinTxn.outputTransfers.length > 0) {
|
|
679
|
+
for (const output of coinTxn.outputTransfers) {
|
|
680
|
+
if (output.walletAddress && output.walletAddress.length > 0) {
|
|
681
|
+
try {
|
|
682
|
+
const addressString = bs58.encode(output.walletAddress);
|
|
683
|
+
if (addressString && !addressesToCheck.includes(addressString)) {
|
|
684
|
+
addressesToCheck.push(addressString);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
catch {
|
|
688
|
+
// Skip addresses that can't be decoded — shouldn't happen with valid transactions
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (addressesToCheck.length === 0)
|
|
694
|
+
return;
|
|
695
|
+
// 3. Determine how many addresses don't hold the token
|
|
696
|
+
let addressesWithoutBalance = 0;
|
|
697
|
+
if (needsInitialization === true) {
|
|
698
|
+
// Override: user says all addresses need initialization — skip API calls entirely
|
|
699
|
+
addressesWithoutBalance = addressesToCheck.length;
|
|
700
|
+
logger.info('needsInitialization=true override: treating all addresses as needing initialization', {
|
|
701
|
+
addressCount: addressesToCheck.length,
|
|
702
|
+
operation: 'calculateNewTokenBalanceFee'
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
else if (needsInitialization === false) {
|
|
706
|
+
// Override: user says no addresses need initialization — skip API calls entirely
|
|
707
|
+
logger.info('needsInitialization=false override: skipping new token balance fee', {
|
|
708
|
+
operation: 'calculateNewTokenBalanceFee'
|
|
709
|
+
});
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
// Default: check balance for each address via API
|
|
714
|
+
for (const address of addressesToCheck) {
|
|
715
|
+
try {
|
|
716
|
+
const balanceResponse = await getBalance(address, contractId, grpcConfig || {});
|
|
717
|
+
// The validator returns balance: '0' when the wallet doesn't have that token
|
|
718
|
+
if (balanceResponse.balance === '0') {
|
|
719
|
+
addressesWithoutBalance++;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
catch {
|
|
723
|
+
// If we can't check balance, assume the address doesn't have it (safer to overestimate)
|
|
724
|
+
addressesWithoutBalance++;
|
|
725
|
+
logger.warn('Failed to check balance for new token fee estimation, assuming address does not hold token', {
|
|
726
|
+
address,
|
|
727
|
+
contractId,
|
|
728
|
+
operation: 'calculateNewTokenBalanceFee'
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if (addressesWithoutBalance === 0)
|
|
734
|
+
return;
|
|
735
|
+
// 4. Calculate new wallet fee per address in the base fee token's smallest units
|
|
736
|
+
// newWalletFeeScaled is in 1e18 = $1.00 format from the BaseFee API
|
|
737
|
+
// Non-native fee instruments (anything other than KALXvxhUMJERCse4e6b2jeXFkcqqpiUByQQckvPZm4szmF3Ao) incur a 10x cost multiplier
|
|
738
|
+
const NON_NATIVE_FEE_MULTIPLIER = 10;
|
|
739
|
+
const feeMultiplier = baseFeeId !== KALVORA_NATIVE_TOKEN ? NON_NATIVE_FEE_MULTIPLIER : 1;
|
|
740
|
+
const feePerAddressScaled = new Decimal(newWalletFeeScaled);
|
|
741
|
+
const totalFeeScaled = feePerAddressScaled.mul(addressesWithoutBalance).mul(feeMultiplier);
|
|
742
|
+
// Convert USD to base fee token smallest units using exchange rate
|
|
743
|
+
const tokenInfo = tokenInfoMap.get(baseFeeId);
|
|
744
|
+
if (!tokenInfo?.rate) {
|
|
745
|
+
logger.warn('Cannot calculate new token balance fee: missing exchange rate for base fee token', {
|
|
746
|
+
baseFeeId,
|
|
747
|
+
operation: 'calculateNewTokenBalanceFee'
|
|
748
|
+
});
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
const exchangeRate = toDecimal(tokenInfo.rate);
|
|
752
|
+
// totalFeeScaled is already in 1e18 precision (from the BaseFee API)
|
|
753
|
+
const feeInTokenUnits = totalFeeScaled.div(exchangeRate);
|
|
754
|
+
// Get denomination decimals
|
|
755
|
+
let decimals;
|
|
756
|
+
if (tokenInfo.denomination) {
|
|
757
|
+
decimals = getDecimalPlacesFromDenomination(tokenInfo.denomination);
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
throw new Error(`Token info missing denomination for ${baseFeeId}`);
|
|
761
|
+
}
|
|
762
|
+
// Convert to smallest units
|
|
763
|
+
const precisionMultiplier = new Decimal(10).pow(decimals);
|
|
764
|
+
const feeInSmallestUnits = feeInTokenUnits.mul(precisionMultiplier).floor();
|
|
765
|
+
// 5. Add the fee to the existing base fee
|
|
766
|
+
const txnProto = protoObject;
|
|
767
|
+
if (txnProto.base?.feeAmount) {
|
|
768
|
+
const currentFee = toDecimal(txnProto.base.feeAmount);
|
|
769
|
+
const newFee = currentFee.add(feeInSmallestUnits);
|
|
770
|
+
txnProto.base.feeAmount = newFee.floor().toString();
|
|
771
|
+
logger.info('Added new token balance fee to base fee', {
|
|
772
|
+
addressesChecked: addressesToCheck.length,
|
|
773
|
+
addressesWithoutBalance,
|
|
774
|
+
feePerAddressScaled: feePerAddressScaled.toString(),
|
|
775
|
+
totalAdditionalFeeSmallestUnits: feeInSmallestUnits.toString(),
|
|
776
|
+
newTotalBaseFee: txnProto.base.feeAmount,
|
|
777
|
+
operation: 'calculateNewTokenBalanceFee'
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Universal Fee Calculator class
|
|
783
|
+
*/
|
|
784
|
+
export class UniversalFeeCalculator {
|
|
785
|
+
/**
|
|
786
|
+
* Unified fee calculation method
|
|
787
|
+
* Calculates network fees, contract fees, and interface fees
|
|
788
|
+
* Returns the modified proto object with all fee fields populated
|
|
789
|
+
* @param options - Fee calculation parameters
|
|
790
|
+
* @returns Modified proto object with fee fields
|
|
791
|
+
*/
|
|
792
|
+
static async calculateFee(options) {
|
|
793
|
+
// Ensure base fee id default and normalize casing
|
|
794
|
+
const effectiveBaseFeeId = normalizeContractId(options.baseFeeId || KALVORA_NATIVE_TOKEN);
|
|
795
|
+
// Ensure tokenInfoMap includes base fee token info
|
|
796
|
+
const workingTokenInfoMap = options.tokenInfoMap || new Map();
|
|
797
|
+
if (!workingTokenInfoMap.has(effectiveBaseFeeId)) {
|
|
798
|
+
try {
|
|
799
|
+
const response = await getTokenFeeInfo({
|
|
800
|
+
contractIds: [effectiveBaseFeeId],
|
|
801
|
+
includeRates: true,
|
|
802
|
+
includeContractFees: true
|
|
803
|
+
}, options.grpcConfig);
|
|
804
|
+
for (const token of response.tokens) {
|
|
805
|
+
workingTokenInfoMap.set(token.contractId, token);
|
|
806
|
+
// Also store under normalized form if API-returned case differs
|
|
807
|
+
const normalized = normalizeContractId(token.contractId);
|
|
808
|
+
if (normalized !== token.contractId) {
|
|
809
|
+
workingTokenInfoMap.set(normalized, token);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
catch {
|
|
814
|
+
// If we cannot fetch, proceed; downstream will error with a precise message if needed
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
// Check if this is a CoinTXN transaction and contractFeeId is provided
|
|
818
|
+
const transactionType = extractTransactionTypeFromProtoObject(options.protoObject);
|
|
819
|
+
// STEP 1: Calculate contract fee FIRST (if applicable)
|
|
820
|
+
// Extract contractId from protoObject for CoinTXN (contractId in options is only for convenience)
|
|
821
|
+
const contractIdForFeeCheck = transactionType === TRANSACTION_TYPE.COIN_TYPE && isCoinTXN(options.protoObject)
|
|
822
|
+
? options.protoObject.contractId
|
|
823
|
+
: options.contractId;
|
|
824
|
+
if (transactionType === TRANSACTION_TYPE.COIN_TYPE && contractIdForFeeCheck && options.tokenInfoMap?.get(contractIdForFeeCheck)?.contractFees) {
|
|
825
|
+
try {
|
|
826
|
+
calculateContractFee(options.protoObject, options.contractFeeId, options.contractFee, options.contractFeeParts, options.tokenInfoMap, options.overestimatePercent);
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
throw new Error(`Contract fee calculation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
// STEP 2: Calculate interface fee (if specified)
|
|
833
|
+
if (options.interfaceFeeId && options.interfaceFee) {
|
|
834
|
+
try {
|
|
835
|
+
calculateInterfaceFee(options.protoObject, options.interfaceFee, options.interfaceFeeId, options.interfaceAddress, options.tokenInfoMap);
|
|
836
|
+
}
|
|
837
|
+
catch (error) {
|
|
838
|
+
throw new Error(`Interface fee calculation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
// STEP 3: Calculate network fee based on the proto object (uses BaseFee API)
|
|
842
|
+
// Returns the newWalletFee from the API response for use in Step 4
|
|
843
|
+
const newWalletFeeScaled = await calculateNetworkFee(options.protoObject, transactionType, effectiveBaseFeeId, options.baseFee, options.baseFeeParts, workingTokenInfoMap, options.overestimatePercent, options.gasFeeInUsd, options.grpcConfig, options.onBaseFeeCalculated);
|
|
844
|
+
// STEP 4: Add new token balance fee for CoinTXN (only for auto-calculated base fees)
|
|
845
|
+
// Checks if any destination address doesn't hold the transferred token,
|
|
846
|
+
// and adds the network-sourced new_wallet_fee per such address to the base network fee.
|
|
847
|
+
if (transactionType === TRANSACTION_TYPE.COIN_TYPE && options.baseFee === undefined && options.baseFeeParts === undefined) {
|
|
848
|
+
const coinContractId = isCoinTXN(options.protoObject) ? options.protoObject.contractId : undefined;
|
|
849
|
+
if (coinContractId) {
|
|
850
|
+
try {
|
|
851
|
+
await calculateNewTokenBalanceFee(options.protoObject, effectiveBaseFeeId, coinContractId, workingTokenInfoMap, newWalletFeeScaled, options.grpcConfig, options.needsInitialization);
|
|
852
|
+
}
|
|
853
|
+
catch (error) {
|
|
854
|
+
// Non-fatal: if balance check fails, proceed without the additional fee.
|
|
855
|
+
// The network will reject the transaction if fees are insufficient,
|
|
856
|
+
// but we don't want to block transaction creation due to balance lookup failures.
|
|
857
|
+
logger.warn('New token balance fee check failed, proceeding without additional fee', {
|
|
858
|
+
error: error instanceof Error ? error.message : String(error),
|
|
859
|
+
operation: 'calculateFee'
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return options.protoObject;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Get exchange rate for a given contract ID
|
|
868
|
+
*/
|
|
869
|
+
static async getExchangeRate(contractId) {
|
|
870
|
+
return ExchangeRateService.getExchangeRate(contractId);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Get comprehensive fee information for contracts
|
|
874
|
+
*
|
|
875
|
+
* @param contractIds - Array of contract IDs to get fee info for
|
|
876
|
+
* @param options - Optional gRPC configuration
|
|
877
|
+
* @returns Promise with fee information including rates and contract details
|
|
878
|
+
*/
|
|
879
|
+
static async getTokenFeeInfo(contractIds, options = {}) {
|
|
880
|
+
const response = await getTokenFeeInfo({
|
|
881
|
+
contractIds,
|
|
882
|
+
includeRates: true,
|
|
883
|
+
includeContractFees: true
|
|
884
|
+
}, options);
|
|
885
|
+
// Transform the response to match the expected return type
|
|
886
|
+
return response.tokens.map((token) => ({
|
|
887
|
+
contractId: token.contractId,
|
|
888
|
+
rate: toDecimal(token.rate),
|
|
889
|
+
authorized: token.authorized,
|
|
890
|
+
denomination: token.denomination,
|
|
891
|
+
contractFees: token.contractFees ? {
|
|
892
|
+
fee: token.contractFees.fee,
|
|
893
|
+
...(token.contractFees.feeAddress && { feeAddress: token.contractFees.feeAddress }),
|
|
894
|
+
burn: token.contractFees.burn,
|
|
895
|
+
validator: token.contractFees.validator
|
|
896
|
+
} : undefined
|
|
897
|
+
}));
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
//# sourceMappingURL=universal-fee-calculator.js.map
|