@airgap/tezos 0.13.45-beta.3 → 0.13.45-beta.4
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/package.json +5 -5
- package/v0/actions/GetKtAccountsAction.js +81 -11
- package/v0/actions/GetKtAccountsAction.js.map +1 -1
- package/v0/constants.js +6 -6
- package/v0/constants.js.map +1 -1
- package/v0/index.js +38 -38
- package/v0/index.js.map +1 -1
- package/v0/protocol/TezosAddress.d.ts +1 -0
- package/v0/protocol/TezosAddress.js +81 -41
- package/v0/protocol/TezosAddress.js.map +1 -1
- package/v0/protocol/TezosCryptoClient.d.ts +1 -0
- package/v0/protocol/TezosCryptoClient.js +123 -68
- package/v0/protocol/TezosCryptoClient.js.map +1 -1
- package/v0/protocol/TezosProtocol.js +1631 -978
- package/v0/protocol/TezosProtocol.js.map +1 -1
- package/v0/protocol/TezosProtocolOptions.d.ts +1 -1
- package/v0/protocol/TezosProtocolOptions.js +98 -26
- package/v0/protocol/TezosProtocolOptions.js.map +1 -1
- package/v0/protocol/TezosUtils.d.ts +1 -0
- package/v0/protocol/TezosUtils.js +165 -131
- package/v0/protocol/TezosUtils.js.map +1 -1
- package/v0/protocol/contract/TezosContract.js +472 -243
- package/v0/protocol/contract/TezosContract.js.map +1 -1
- package/v0/protocol/contract/TezosContractCall.js +10 -8
- package/v0/protocol/contract/TezosContractCall.js.map +1 -1
- package/v0/protocol/contract/TezosContractEntrypoint.js +19 -14
- package/v0/protocol/contract/TezosContractEntrypoint.js.map +1 -1
- package/v0/protocol/contract/TezosContractStorage.js +9 -8
- package/v0/protocol/contract/TezosContractStorage.js.map +1 -1
- package/v0/protocol/contract/remote-data/TezosContractRemoteDataFactory.js +25 -8
- package/v0/protocol/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -1
- package/v0/protocol/contract/remote-data/TezosStorageRemoteData.js +113 -39
- package/v0/protocol/contract/remote-data/TezosStorageRemoteData.js.map +1 -1
- package/v0/protocol/domains/TezosDomains.js +270 -165
- package/v0/protocol/domains/TezosDomains.js.map +1 -1
- package/v0/protocol/fa/TezosBTC.js +98 -19
- package/v0/protocol/fa/TezosBTC.js.map +1 -1
- package/v0/protocol/fa/TezosBTCtez.js +48 -17
- package/v0/protocol/fa/TezosBTCtez.js.map +1 -1
- package/v0/protocol/fa/TezosCTez.js +45 -17
- package/v0/protocol/fa/TezosCTez.js.map +1 -1
- package/v0/protocol/fa/TezosDOGA.js +45 -17
- package/v0/protocol/fa/TezosDOGA.js.map +1 -1
- package/v0/protocol/fa/TezosETHtz.js +68 -10
- package/v0/protocol/fa/TezosETHtz.js.map +1 -1
- package/v0/protocol/fa/TezosFA1Protocol.js +276 -119
- package/v0/protocol/fa/TezosFA1Protocol.js.map +1 -1
- package/v0/protocol/fa/TezosFA1p2Protocol.js +101 -22
- package/v0/protocol/fa/TezosFA1p2Protocol.js.map +1 -1
- package/v0/protocol/fa/TezosFA2Protocol.js +402 -213
- package/v0/protocol/fa/TezosFA2Protocol.js.map +1 -1
- package/v0/protocol/fa/TezosFAProtocol.js +418 -211
- package/v0/protocol/fa/TezosFAProtocol.js.map +1 -1
- package/v0/protocol/fa/TezosFAProtocolOptions.d.ts +2 -2
- package/v0/protocol/fa/TezosFAProtocolOptions.js +195 -92
- package/v0/protocol/fa/TezosFAProtocolOptions.js.map +1 -1
- package/v0/protocol/fa/TezosKolibriUSD.js +70 -11
- package/v0/protocol/fa/TezosKolibriUSD.js.map +1 -1
- package/v0/protocol/fa/TezosPlanty.js +45 -17
- package/v0/protocol/fa/TezosPlanty.js.map +1 -1
- package/v0/protocol/fa/TezosQUIPU.js +48 -17
- package/v0/protocol/fa/TezosQUIPU.js.map +1 -1
- package/v0/protocol/fa/TezosSIRS.js +45 -17
- package/v0/protocol/fa/TezosSIRS.js.map +1 -1
- package/v0/protocol/fa/TezosStaker.js +70 -11
- package/v0/protocol/fa/TezosStaker.js.map +1 -1
- package/v0/protocol/fa/TezosUBTC.js +48 -17
- package/v0/protocol/fa/TezosUBTC.js.map +1 -1
- package/v0/protocol/fa/TezosUDEFI.js +48 -17
- package/v0/protocol/fa/TezosUDEFI.js.map +1 -1
- package/v0/protocol/fa/TezosUSD.js +70 -11
- package/v0/protocol/fa/TezosUSD.js.map +1 -1
- package/v0/protocol/fa/TezosUSDT.js +48 -17
- package/v0/protocol/fa/TezosUSDT.js.map +1 -1
- package/v0/protocol/fa/TezosUUSD.js +27 -8
- package/v0/protocol/fa/TezosUUSD.js.map +1 -1
- package/v0/protocol/fa/TezosUXTZ.js +48 -17
- package/v0/protocol/fa/TezosUXTZ.js.map +1 -1
- package/v0/protocol/fa/TezosWRAP.js +48 -17
- package/v0/protocol/fa/TezosWRAP.js.map +1 -1
- package/v0/protocol/fa/TezosWrapped.js +70 -11
- package/v0/protocol/fa/TezosWrapped.js.map +1 -1
- package/v0/protocol/fa/TezosYOU.js +27 -8
- package/v0/protocol/fa/TezosYOU.js.map +1 -1
- package/v0/protocol/fa/metadata/BigMapTokenMetadataIndexer.js +162 -84
- package/v0/protocol/fa/metadata/BigMapTokenMetadataIndexer.js.map +1 -1
- package/v0/protocol/fa/metadata/ObjktTokenMetadataIndexer.js +87 -37
- package/v0/protocol/fa/metadata/ObjktTokenMetadataIndexer.js.map +1 -1
- package/v0/protocol/indexerClient/TezosIndexerClient.js +259 -115
- package/v0/protocol/indexerClient/TezosIndexerClient.js.map +1 -1
- package/v0/protocol/kt/TezosKtAddress.js +67 -7
- package/v0/protocol/kt/TezosKtAddress.js.map +1 -1
- package/v0/protocol/kt/TezosKtProtocol.js +309 -161
- package/v0/protocol/kt/TezosKtProtocol.js.map +1 -1
- package/v0/protocol/sapling/TezosSaplingAddress.d.ts +1 -0
- package/v0/protocol/sapling/TezosSaplingAddress.js +117 -46
- package/v0/protocol/sapling/TezosSaplingAddress.js.map +1 -1
- package/v0/protocol/sapling/TezosSaplingCryptoClient.d.ts +1 -0
- package/v0/protocol/sapling/TezosSaplingCryptoClient.js +220 -125
- package/v0/protocol/sapling/TezosSaplingCryptoClient.js.map +1 -1
- package/v0/protocol/sapling/TezosSaplingProtocol.d.ts +1 -0
- package/v0/protocol/sapling/TezosSaplingProtocol.js +1127 -600
- package/v0/protocol/sapling/TezosSaplingProtocol.js.map +1 -1
- package/v0/protocol/sapling/TezosSaplingProtocolOptions.d.ts +1 -0
- package/v0/protocol/sapling/TezosSaplingProtocolOptions.js +61 -32
- package/v0/protocol/sapling/TezosSaplingProtocolOptions.js.map +1 -1
- package/v0/protocol/sapling/TezosShieldedTezProtocol.js +134 -50
- package/v0/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -1
- package/v0/protocol/sapling/injector/TezosSaplingInjectorClient.js +56 -10
- package/v0/protocol/sapling/injector/TezosSaplingInjectorClient.js.map +1 -1
- package/v0/protocol/sapling/node/TezosSaplingNodeClient.js +67 -12
- package/v0/protocol/sapling/node/TezosSaplingNodeClient.js.map +1 -1
- package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.d.ts +1 -0
- package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.js +539 -221
- package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.js.map +1 -1
- package/v0/protocol/sapling/utils/TezosSaplingEncoder.d.ts +1 -0
- package/v0/protocol/sapling/utils/TezosSaplingEncoder.js +104 -101
- package/v0/protocol/sapling/utils/TezosSaplingEncoder.js.map +1 -1
- package/v0/protocol/sapling/utils/TezosSaplingForger.d.ts +1 -0
- package/v0/protocol/sapling/utils/TezosSaplingForger.js +266 -107
- package/v0/protocol/sapling/utils/TezosSaplingForger.js.map +1 -1
- package/v0/protocol/sapling/utils/TezosSaplingState.js +239 -110
- package/v0/protocol/sapling/utils/TezosSaplingState.js.map +1 -1
- package/v0/protocol/types/TezosOperationType.js +1 -1
- package/v0/protocol/types/TezosOperationType.js.map +1 -1
- package/v0/protocol/types/contract/BigMapEntry.d.ts +1 -1
- package/v0/protocol/types/contract/TezosContractMetadata.d.ts +2 -2
- package/v0/protocol/types/micheline/MichelineNode.d.ts +7 -7
- package/v0/protocol/types/micheline/MichelineNodeUtils.js +13 -9
- package/v0/protocol/types/micheline/MichelineNodeUtils.js.map +1 -1
- package/v0/protocol/types/michelson/MichelsonType.d.ts +1 -0
- package/v0/protocol/types/michelson/MichelsonType.js +12 -11
- package/v0/protocol/types/michelson/MichelsonType.js.map +1 -1
- package/v0/protocol/types/michelson/MichelsonTypeMeta.js +92 -45
- package/v0/protocol/types/michelson/MichelsonTypeMeta.js.map +1 -1
- package/v0/protocol/types/michelson/MichelsonTypeUtils.d.ts +1 -0
- package/v0/protocol/types/michelson/MichelsonTypeUtils.js +219 -58
- package/v0/protocol/types/michelson/MichelsonTypeUtils.js.map +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonList.js +43 -24
- package/v0/protocol/types/michelson/generics/MichelsonList.js.map +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonMap.js +61 -39
- package/v0/protocol/types/michelson/generics/MichelsonMap.js.map +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonOption.d.ts +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonOption.js +75 -46
- package/v0/protocol/types/michelson/generics/MichelsonOption.js.map +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonOr.d.ts +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonOr.js +76 -50
- package/v0/protocol/types/michelson/generics/MichelsonOr.js.map +1 -1
- package/v0/protocol/types/michelson/generics/MichelsonPair.js +85 -52
- package/v0/protocol/types/michelson/generics/MichelsonPair.js.map +1 -1
- package/v0/protocol/types/michelson/grammar/MichelsonGrammarData.d.ts +1 -1
- package/v0/protocol/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -1
- package/v0/protocol/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonAddress.d.ts +1 -0
- package/v0/protocol/types/michelson/primitives/MichelsonAddress.js +47 -28
- package/v0/protocol/types/michelson/primitives/MichelsonAddress.js.map +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonBool.js +39 -20
- package/v0/protocol/types/michelson/primitives/MichelsonBool.js.map +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonBytes.d.ts +1 -0
- package/v0/protocol/types/michelson/primitives/MichelsonBytes.js +54 -35
- package/v0/protocol/types/michelson/primitives/MichelsonBytes.js.map +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonInt.d.ts +1 -0
- package/v0/protocol/types/michelson/primitives/MichelsonInt.js +49 -30
- package/v0/protocol/types/michelson/primitives/MichelsonInt.js.map +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonString.d.ts +1 -0
- package/v0/protocol/types/michelson/primitives/MichelsonString.js +52 -33
- package/v0/protocol/types/michelson/primitives/MichelsonString.js.map +1 -1
- package/v0/protocol/types/michelson/primitives/MichelsonUnit.js +34 -14
- package/v0/protocol/types/michelson/primitives/MichelsonUnit.js.map +1 -1
- package/v0/protocol/types/sapling/TezosSaplingStateTree.d.ts +1 -1
- package/v0/protocol/types/sapling/TezosSaplingTransaction.d.ts +1 -0
- package/v0/protocol/types/utils.js +10 -8
- package/v0/protocol/types/utils.js.map +1 -1
- package/v0/serializer/validators/transaction-validator.js +78 -29
- package/v0/serializer/validators/transaction-validator.js.map +1 -1
- package/v0/serializer/validators/transaction-xtz-btc-validator.js +129 -55
- package/v0/serializer/validators/transaction-xtz-btc-validator.js.map +1 -1
- package/v0/serializer/validators/validators.js +103 -43
- package/v0/serializer/validators/validators.js.map +1 -1
- package/v1/block-explorer/TzKTBlockExplorer.js +61 -12
- package/v1/block-explorer/TzKTBlockExplorer.js.map +1 -1
- package/v1/block-explorer/factory.js +5 -4
- package/v1/block-explorer/factory.js.map +1 -1
- package/v1/contract/TezosContract.js +471 -242
- package/v1/contract/TezosContract.js.map +1 -1
- package/v1/contract/TezosContractCall.js +10 -8
- package/v1/contract/TezosContractCall.js.map +1 -1
- package/v1/contract/TezosContractEntrypoint.d.ts +1 -1
- package/v1/contract/TezosContractEntrypoint.js +19 -14
- package/v1/contract/TezosContractEntrypoint.js.map +1 -1
- package/v1/contract/TezosContractStorage.js +9 -8
- package/v1/contract/TezosContractStorage.js.map +1 -1
- package/v1/contract/remote-data/TezosContractRemoteDataFactory.js +25 -8
- package/v1/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -1
- package/v1/contract/remote-data/TezosStorageRemoteData.js +113 -39
- package/v1/contract/remote-data/TezosStorageRemoteData.js.map +1 -1
- package/v1/crypto/TezosCryptoClient.d.ts +1 -0
- package/v1/crypto/TezosCryptoClient.js +117 -64
- package/v1/crypto/TezosCryptoClient.js.map +1 -1
- package/v1/crypto/TezosSaplingCryptoClient.d.ts +1 -0
- package/v1/crypto/TezosSaplingCryptoClient.js +194 -116
- package/v1/crypto/TezosSaplingCryptoClient.js.map +1 -1
- package/v1/data/TezosAddress.js +14 -13
- package/v1/data/TezosAddress.js.map +1 -1
- package/v1/data/TezosSaplingAddress.d.ts +1 -0
- package/v1/data/TezosSaplingAddress.js +94 -29
- package/v1/data/TezosSaplingAddress.js.map +1 -1
- package/v1/domains/TezosDomains.js +270 -165
- package/v1/domains/TezosDomains.js.map +1 -1
- package/v1/index.js +39 -39
- package/v1/index.js.map +1 -1
- package/v1/indexer/TzKTIndexerClient.js +270 -126
- package/v1/indexer/TzKTIndexerClient.js.map +1 -1
- package/v1/indexer/factory.js +5 -4
- package/v1/indexer/factory.js.map +1 -1
- package/v1/indexer/token-metadata/BigMapTokenMetadataIndexerClient.js +161 -83
- package/v1/indexer/token-metadata/BigMapTokenMetadataIndexerClient.js.map +1 -1
- package/v1/indexer/token-metadata/ObjktTokenMetadataIndexerClient.js +85 -36
- package/v1/indexer/token-metadata/ObjktTokenMetadataIndexerClient.js.map +1 -1
- package/v1/injector/TezosSaplingInjectorClient.js +56 -10
- package/v1/injector/TezosSaplingInjectorClient.js.map +1 -1
- package/v1/module/TezosModule.js +155 -88
- package/v1/module/TezosModule.js.map +1 -1
- package/v1/module.js +3 -2
- package/v1/module.js.map +1 -1
- package/v1/node/TezosSaplingNodeClient.js +67 -12
- package/v1/node/TezosSaplingNodeClient.js.map +1 -1
- package/v1/protocol/TezosProtocol.js +1385 -848
- package/v1/protocol/TezosProtocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA1Protocol.js +205 -81
- package/v1/protocol/fa/TezosFA1Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA1p2Protocol.js +111 -32
- package/v1/protocol/fa/TezosFA1p2Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA2Protocol.js +332 -174
- package/v1/protocol/fa/TezosFA2Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFAProtocol.js +528 -255
- package/v1/protocol/fa/TezosFAProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/BTCTezProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/BTCTezProtocol.js +47 -30
- package/v1/protocol/fa/tokens/BTCTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/CTezProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/CTezProtocol.js +47 -27
- package/v1/protocol/fa/tokens/CTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/DogamiProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/DogamiProtocol.js +47 -27
- package/v1/protocol/fa/tokens/DogamiProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/ETHTezProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/ETHTezProtocol.js +90 -30
- package/v1/protocol/fa/tokens/ETHTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/KolibriUSDProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/KolibriUSDProtocol.js +90 -30
- package/v1/protocol/fa/tokens/KolibriUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/PlentyProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/PlentyProtocol.js +90 -30
- package/v1/protocol/fa/tokens/PlentyProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/QuipuswapProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/QuipuswapProtocol.js +47 -30
- package/v1/protocol/fa/tokens/QuipuswapProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/SiriusProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/SiriusProtocol.js +47 -27
- package/v1/protocol/fa/tokens/SiriusProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/StakerProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/StakerProtocol.js +90 -30
- package/v1/protocol/fa/tokens/StakerProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/TetherUSDProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/TetherUSDProtocol.js +47 -30
- package/v1/protocol/fa/tokens/TetherUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/TzBTCProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/TzBTCProtocol.js +47 -27
- package/v1/protocol/fa/tokens/TzBTCProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UBTCProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/UBTCProtocol.js +47 -30
- package/v1/protocol/fa/tokens/UBTCProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UDEFIProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/UDEFIProtocol.js +47 -30
- package/v1/protocol/fa/tokens/UDEFIProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/USDTezProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/USDTezProtocol.js +47 -27
- package/v1/protocol/fa/tokens/USDTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UUSDProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/UUSDProtocol.js +47 -30
- package/v1/protocol/fa/tokens/UUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UXTZProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/UXTZProtocol.js +47 -30
- package/v1/protocol/fa/tokens/UXTZProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/WrapProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/WrapProtocol.js +47 -30
- package/v1/protocol/fa/tokens/WrapProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/WrappedTezosProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/WrappedTezosProtocol.js +47 -27
- package/v1/protocol/fa/tokens/WrappedTezosProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/YouProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/YouProtocol.js +47 -30
- package/v1/protocol/fa/tokens/YouProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/stXTZProtocol.d.ts +2 -2
- package/v1/protocol/fa/tokens/stXTZProtocol.js +47 -30
- package/v1/protocol/fa/tokens/stXTZProtocol.js.map +1 -1
- package/v1/protocol/kt/TezosKtProtocol.js +498 -254
- package/v1/protocol/kt/TezosKtProtocol.js.map +1 -1
- package/v1/protocol/sapling/TezosSaplingProtocol.d.ts +1 -0
- package/v1/protocol/sapling/TezosSaplingProtocol.js +933 -532
- package/v1/protocol/sapling/TezosSaplingProtocol.js.map +1 -1
- package/v1/protocol/sapling/TezosShieldedTezProtocol.js +164 -72
- package/v1/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +26 -14
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +188 -103
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +143 -54
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +100 -40
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/block-explorer.d.ts +1 -1
- package/v1/types/contract/TezosContractMetadata.d.ts +2 -2
- package/v1/types/contract/bigmap/BigMapEntry.d.ts +1 -1
- package/v1/types/crypto.d.ts +2 -2
- package/v1/types/fa/TezosFA1ContractEntrypoint.d.ts +1 -1
- package/v1/types/fa/TezosFA1p2ContractEntrypoint.d.ts +1 -1
- package/v1/types/fa/TezosFA2ContractEntrypoint.d.ts +1 -1
- package/v1/types/indexer.d.ts +1 -1
- package/v1/types/micheline/MichelineNode.d.ts +7 -7
- package/v1/types/micheline/MichelineNodeUtils.js +13 -9
- package/v1/types/micheline/MichelineNodeUtils.js.map +1 -1
- package/v1/types/michelson/MichelsonType.d.ts +1 -0
- package/v1/types/michelson/MichelsonType.js +12 -11
- package/v1/types/michelson/MichelsonType.js.map +1 -1
- package/v1/types/michelson/MichelsonTypeMeta.js +92 -45
- package/v1/types/michelson/MichelsonTypeMeta.js.map +1 -1
- package/v1/types/michelson/MichelsonTypeUtils.d.ts +1 -0
- package/v1/types/michelson/MichelsonTypeUtils.js +219 -58
- package/v1/types/michelson/MichelsonTypeUtils.js.map +1 -1
- package/v1/types/michelson/generics/MichelsonList.js +43 -24
- package/v1/types/michelson/generics/MichelsonList.js.map +1 -1
- package/v1/types/michelson/generics/MichelsonMap.js +61 -39
- package/v1/types/michelson/generics/MichelsonMap.js.map +1 -1
- package/v1/types/michelson/generics/MichelsonOption.d.ts +1 -1
- package/v1/types/michelson/generics/MichelsonOption.js +75 -46
- package/v1/types/michelson/generics/MichelsonOption.js.map +1 -1
- package/v1/types/michelson/generics/MichelsonOr.d.ts +1 -1
- package/v1/types/michelson/generics/MichelsonOr.js +76 -50
- package/v1/types/michelson/generics/MichelsonOr.js.map +1 -1
- package/v1/types/michelson/generics/MichelsonPair.js +85 -52
- package/v1/types/michelson/generics/MichelsonPair.js.map +1 -1
- package/v1/types/michelson/grammar/MichelsonGrammarData.d.ts +1 -1
- package/v1/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -1
- package/v1/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -1
- package/v1/types/michelson/primitives/MichelsonAddress.d.ts +1 -0
- package/v1/types/michelson/primitives/MichelsonAddress.js +47 -28
- package/v1/types/michelson/primitives/MichelsonAddress.js.map +1 -1
- package/v1/types/michelson/primitives/MichelsonBool.js +39 -20
- package/v1/types/michelson/primitives/MichelsonBool.js.map +1 -1
- package/v1/types/michelson/primitives/MichelsonBytes.d.ts +1 -0
- package/v1/types/michelson/primitives/MichelsonBytes.js +54 -35
- package/v1/types/michelson/primitives/MichelsonBytes.js.map +1 -1
- package/v1/types/michelson/primitives/MichelsonInt.d.ts +1 -0
- package/v1/types/michelson/primitives/MichelsonInt.js +49 -30
- package/v1/types/michelson/primitives/MichelsonInt.js.map +1 -1
- package/v1/types/michelson/primitives/MichelsonString.d.ts +1 -0
- package/v1/types/michelson/primitives/MichelsonString.js +52 -33
- package/v1/types/michelson/primitives/MichelsonString.js.map +1 -1
- package/v1/types/michelson/primitives/MichelsonUnit.js +34 -14
- package/v1/types/michelson/primitives/MichelsonUnit.js.map +1 -1
- package/v1/types/network.js +1 -1
- package/v1/types/network.js.map +1 -1
- package/v1/types/operations/TezosOperationType.js +1 -1
- package/v1/types/operations/TezosOperationType.js.map +1 -1
- package/v1/types/protocol.d.ts +3 -3
- package/v1/types/sapling/TezosSaplingExternalMethodProvider.d.ts +1 -0
- package/v1/types/sapling/TezosSaplingStateTree.d.ts +1 -1
- package/v1/types/sapling/TezosSaplingTransaction.d.ts +1 -0
- package/v1/types/staking/TezosDelegatorAction.js +1 -1
- package/v1/types/staking/TezosDelegatorAction.js.map +1 -1
- package/v1/utils/address.js +7 -6
- package/v1/utils/address.js.map +1 -1
- package/v1/utils/bip.d.ts +1 -0
- package/v1/utils/bip.js +7 -6
- package/v1/utils/bip.js.map +1 -1
- package/v1/utils/convert.js +8 -7
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/encoding.d.ts +1 -0
- package/v1/utils/encoding.js +64 -74
- package/v1/utils/encoding.js.map +1 -1
- package/v1/utils/fa.js +3 -2
- package/v1/utils/fa.js.map +1 -1
- package/v1/utils/key.js +12 -9
- package/v1/utils/key.js.map +1 -1
- package/v1/utils/micheline.js +10 -8
- package/v1/utils/micheline.js.map +1 -1
- package/v1/utils/operations.js +22 -21
- package/v1/utils/operations.js.map +1 -1
- package/v1/utils/pack.d.ts +1 -0
- package/v1/utils/pack.js +107 -65
- package/v1/utils/pack.js.map +1 -1
- package/v1/utils/protocol/fa/TezosFA1Accountant.js +52 -24
- package/v1/utils/protocol/fa/TezosFA1Accountant.js.map +1 -1
- package/v1/utils/protocol/fa/TezosFA2Accountant.js +77 -40
- package/v1/utils/protocol/fa/TezosFA2Accountant.js.map +1 -1
- package/v1/utils/protocol/fa/TezosFAAccountant.js +89 -21
- package/v1/utils/protocol/fa/TezosFAAccountant.js.map +1 -1
- package/v1/utils/protocol/instance.js +26 -90
- package/v1/utils/protocol/instance.js.map +1 -1
- package/v1/utils/protocol/sapling/TezosSaplingAccountant.d.ts +1 -0
- package/v1/utils/protocol/sapling/TezosSaplingAccountant.js +539 -221
- package/v1/utils/protocol/sapling/TezosSaplingAccountant.js.map +1 -1
- package/v1/utils/protocol/sapling/TezosSaplingEncoder.d.ts +1 -0
- package/v1/utils/protocol/sapling/TezosSaplingEncoder.js +104 -101
- package/v1/utils/protocol/sapling/TezosSaplingEncoder.js.map +1 -1
- package/v1/utils/protocol/sapling/TezosSaplingForger.d.ts +1 -0
- package/v1/utils/protocol/sapling/TezosSaplingForger.js +266 -107
- package/v1/utils/protocol/sapling/TezosSaplingForger.js.map +1 -1
- package/v1/utils/protocol/sapling/TezosSaplingState.js +239 -110
- package/v1/utils/protocol/sapling/TezosSaplingState.js.map +1 -1
- package/v1/utils/protocol/tezos/TezosAccountant.js +166 -97
- package/v1/utils/protocol/tezos/TezosAccountant.js.map +1 -1
- package/v1/utils/protocol/tezos/TezosForger.js +76 -21
- package/v1/utils/protocol/tezos/TezosForger.js.map +1 -1
- package/v1/utils/signature.js +6 -5
- package/v1/utils/signature.js.map +1 -1
- package/v1/utils/transaction.d.ts +5 -4
- package/v1/utils/transaction.js +3 -3
- package/v1/utils/transaction.js.map +1 -1
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
2
28
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
29
|
if (k2 === undefined) k2 = k;
|
|
4
30
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,984 +41,1525 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
41
|
}) : function(o, v) {
|
|
16
42
|
o["default"] = v;
|
|
17
43
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
return function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod;
|
|
46
|
+
var result = {};
|
|
47
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
52
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
53
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
54
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
55
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
56
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
57
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
61
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
62
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
63
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
64
|
+
function step(op) {
|
|
65
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
66
|
+
while (_) try {
|
|
67
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
68
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
69
|
+
switch (op[0]) {
|
|
70
|
+
case 0: case 1: t = op; break;
|
|
71
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
72
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
73
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
74
|
+
default:
|
|
75
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
76
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
77
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
78
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
79
|
+
if (t[2]) _.ops.pop();
|
|
80
|
+
_.trys.pop(); continue;
|
|
81
|
+
}
|
|
82
|
+
op = body.call(thisArg, _);
|
|
83
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
84
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
85
|
+
}
|
|
86
|
+
};
|
|
35
87
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
88
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
89
|
};
|
|
38
90
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
91
|
exports.TezosProtocol = exports.TezosNetwork = exports.TezosDelegatorAction = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
92
|
+
var taquito_local_forging_1 = require("@airgap/coinlib-core/dependencies/src/@taquito/local-forging-15.0.1/packages/taquito-local-forging/src/taquito-local-forging");
|
|
93
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
94
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
43
95
|
// @ts-ignore
|
|
44
|
-
|
|
96
|
+
var index_2 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0/index");
|
|
45
97
|
// @ts-ignore
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
98
|
+
var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
99
|
+
var index_3 = require("@airgap/coinlib-core/dependencies/src/hd-wallet-js-b216450e56954a6e82ace0aade9474673de5d9d5/src/index");
|
|
100
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
101
|
+
var index_4 = require("@airgap/coinlib-core/errors/index");
|
|
102
|
+
var NonExtendedProtocol_1 = require("@airgap/coinlib-core/protocols/NonExtendedProtocol");
|
|
103
|
+
var assert_1 = require("@airgap/coinlib-core/utils/assert");
|
|
104
|
+
var ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
|
|
105
|
+
var TezosAddress_1 = require("./TezosAddress");
|
|
106
|
+
var TezosCryptoClient_1 = require("./TezosCryptoClient");
|
|
107
|
+
var TezosProtocolOptions_1 = require("./TezosProtocolOptions");
|
|
108
|
+
var TezosUtils_1 = require("./TezosUtils");
|
|
109
|
+
var TezosOperationType_1 = require("./types/TezosOperationType");
|
|
110
|
+
var MAX_OPERATIONS_PER_GROUP = 200;
|
|
111
|
+
var MAX_GAS_PER_BLOCK = 2600000;
|
|
112
|
+
var GAS_LIMIT_PLACEHOLDER = '1040000';
|
|
113
|
+
var STORAGE_LIMIT_PLACEHOLDER = '60000';
|
|
114
|
+
var FEE_PLACEHOLDER = '0';
|
|
115
|
+
var MINIMAL_FEE = 100;
|
|
116
|
+
var MINIMAL_FEE_PER_GAS_UNIT = 0.1;
|
|
117
|
+
var MINIMAL_FEE_PER_BYTE = 1;
|
|
66
118
|
var TezosDelegatorAction;
|
|
67
119
|
(function (TezosDelegatorAction) {
|
|
68
120
|
TezosDelegatorAction["DELEGATE"] = "delegate";
|
|
69
121
|
TezosDelegatorAction["UNDELEGATE"] = "undelegate";
|
|
70
122
|
TezosDelegatorAction["CHANGE_BAKER"] = "change_baker";
|
|
71
|
-
})(TezosDelegatorAction
|
|
123
|
+
})(TezosDelegatorAction = exports.TezosDelegatorAction || (exports.TezosDelegatorAction = {}));
|
|
72
124
|
// 8.25%
|
|
73
|
-
|
|
125
|
+
var SELF_BOND_REQUIREMENT = 0.0825;
|
|
74
126
|
var TezosNetwork;
|
|
75
127
|
(function (TezosNetwork) {
|
|
76
128
|
TezosNetwork["MAINNET"] = "mainnet";
|
|
77
129
|
TezosNetwork["GHOSTNET"] = "ghostnet";
|
|
78
|
-
})(TezosNetwork
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.feeDecimals = 6; // micro tez is the smallest, 1000000 microtez is 1 tez
|
|
93
|
-
this.identifier = ProtocolSymbols_1.MainProtocolSymbols.XTZ;
|
|
130
|
+
})(TezosNetwork = exports.TezosNetwork || (exports.TezosNetwork = {}));
|
|
131
|
+
var TezosProtocol = /** @class */ (function (_super) {
|
|
132
|
+
__extends(TezosProtocol, _super);
|
|
133
|
+
function TezosProtocol(options) {
|
|
134
|
+
if (options === void 0) { options = new TezosProtocolOptions_1.TezosProtocolOptions(); }
|
|
135
|
+
var _this = _super.call(this) || this;
|
|
136
|
+
_this.options = options;
|
|
137
|
+
_this.symbol = 'XTZ';
|
|
138
|
+
_this.name = 'Tezos';
|
|
139
|
+
_this.marketSymbol = 'xtz';
|
|
140
|
+
_this.feeSymbol = 'xtz';
|
|
141
|
+
_this.decimals = 6;
|
|
142
|
+
_this.feeDecimals = 6; // micro tez is the smallest, 1000000 microtez is 1 tez
|
|
143
|
+
_this.identifier = ProtocolSymbols_1.MainProtocolSymbols.XTZ;
|
|
94
144
|
// tezbox default
|
|
95
|
-
|
|
145
|
+
_this.feeDefaults = {
|
|
96
146
|
low: '0.001420',
|
|
97
147
|
medium: '0.001520',
|
|
98
148
|
high: '0.003000'
|
|
99
149
|
};
|
|
100
|
-
|
|
150
|
+
_this.units = [
|
|
101
151
|
{
|
|
102
152
|
unitSymbol: 'XTZ',
|
|
103
153
|
factor: '1'
|
|
104
154
|
}
|
|
105
155
|
];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
156
|
+
_this.supportsHD = false;
|
|
157
|
+
_this.standardDerivationPath = "m/44h/1729h/0h/0h";
|
|
158
|
+
_this.addressIsCaseSensitive = true;
|
|
159
|
+
_this.addressValidationPattern = '^((tz1|tz2|tz3|tz4|KT1)[1-9A-Za-z]{33}|zet1[1-9A-Za-z]{65})$';
|
|
160
|
+
_this.addressPlaceholder = 'tz1...';
|
|
111
161
|
// https://gitlab.com/tezos/tezos/-/blob/master/docs/whitedoc/proof_of_stake.rst
|
|
112
162
|
// cycle has 4096 blocks, which are at least one minute apart
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return this
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return this
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
163
|
+
_this.minCycleDuration = 4096 * 60 * 1000; // ms
|
|
164
|
+
_this.transactionFee = new bignumber_1.default('1400');
|
|
165
|
+
_this.originationSize = new bignumber_1.default('257');
|
|
166
|
+
_this.storageCostPerByte = new bignumber_1.default('1000');
|
|
167
|
+
_this.revealFee = new bignumber_1.default('1300');
|
|
168
|
+
_this.activationBurn = _this.originationSize.times(_this.storageCostPerByte);
|
|
169
|
+
_this.originationBurn = _this.originationSize.times(_this.storageCostPerByte); // https://tezos.stackexchange.com/a/787
|
|
170
|
+
_this.cryptoClient = new TezosCryptoClient_1.TezosCryptoClient(TezosUtils_1.TezosUtils.tezosPrefixes.edsig);
|
|
171
|
+
return _this;
|
|
172
|
+
}
|
|
173
|
+
Object.defineProperty(TezosProtocol.prototype, "jsonRPCAPI", {
|
|
174
|
+
// TODO: Should we remove these getters and replace the calls to `this.options.network...`?
|
|
175
|
+
get: function () {
|
|
176
|
+
return this.options.network.rpcUrl;
|
|
177
|
+
},
|
|
178
|
+
enumerable: false,
|
|
179
|
+
configurable: true
|
|
180
|
+
});
|
|
181
|
+
TezosProtocol.prototype.getSymbol = function () {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
+
return __generator(this, function (_a) {
|
|
184
|
+
return [2 /*return*/, this.symbol];
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
TezosProtocol.prototype.getName = function () {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
return [2 /*return*/, this.name];
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
TezosProtocol.prototype.getMarketSymbol = function () {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
return __generator(this, function (_a) {
|
|
198
|
+
return [2 /*return*/, this.marketSymbol];
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
TezosProtocol.prototype.getAssetSymbol = function () {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
return [2 /*return*/, undefined];
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
TezosProtocol.prototype.getFeeSymbol = function () {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
return __generator(this, function (_a) {
|
|
212
|
+
return [2 /*return*/, this.feeSymbol];
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
TezosProtocol.prototype.getDecimals = function () {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
+
return __generator(this, function (_a) {
|
|
219
|
+
return [2 /*return*/, this.decimals];
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
TezosProtocol.prototype.getFeeDecimals = function () {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
return __generator(this, function (_a) {
|
|
226
|
+
return [2 /*return*/, this.feeDecimals];
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
TezosProtocol.prototype.getIdentifier = function () {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
232
|
+
return __generator(this, function (_a) {
|
|
233
|
+
return [2 /*return*/, this.identifier];
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
TezosProtocol.prototype.getFeeDefaults = function () {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
return [2 /*return*/, this.feeDefaults];
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
TezosProtocol.prototype.getUnits = function () {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
return [2 /*return*/, this.units];
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
TezosProtocol.prototype.getSupportsHD = function () {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
return [2 /*return*/, this.supportsHD];
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
TezosProtocol.prototype.getStandardDerivationPath = function () {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
+
return __generator(this, function (_a) {
|
|
261
|
+
return [2 /*return*/, this.standardDerivationPath];
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
TezosProtocol.prototype.getAddressIsCaseSensitive = function () {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
return [2 /*return*/, this.addressIsCaseSensitive];
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
TezosProtocol.prototype.getAddressValidationPattern = function () {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
+
return __generator(this, function (_a) {
|
|
275
|
+
return [2 /*return*/, this.addressValidationPattern];
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
TezosProtocol.prototype.getAddressPlaceholder = function () {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
+
return __generator(this, function (_a) {
|
|
282
|
+
return [2 /*return*/, this.addressPlaceholder];
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
TezosProtocol.prototype.getOptions = function () {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
return [2 /*return*/, this.options];
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
TezosProtocol.prototype.getBlockExplorerLinkForAddress = function (address) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
295
|
+
return __generator(this, function (_a) {
|
|
296
|
+
return [2 /*return*/, this.options.network.blockExplorer.getAddressLink(address)];
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
TezosProtocol.prototype.getBlockExplorerLinkForTxId = function (txId) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
302
|
+
return __generator(this, function (_a) {
|
|
303
|
+
return [2 /*return*/, this.options.network.blockExplorer.getTransactionLink(txId)];
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
TezosProtocol.prototype.getPublicKeyFromMnemonic = function (mnemonic, derivationPath, password) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
+
var secret;
|
|
310
|
+
return __generator(this, function (_a) {
|
|
311
|
+
secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
312
|
+
return [2 /*return*/, this.getPublicKeyFromHexSecret(secret, derivationPath)];
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
TezosProtocol.prototype.getPrivateKeyFromMnemonic = function (mnemonic, derivationPath, password) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
+
var secret;
|
|
319
|
+
return __generator(this, function (_a) {
|
|
320
|
+
secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
321
|
+
return [2 /*return*/, this.getPrivateKeyFromHexSecret(secret, derivationPath)];
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
};
|
|
184
325
|
/**
|
|
185
326
|
* Returns the PublicKey as String, derived from a supplied hex-string
|
|
186
327
|
* @param secret HEX-Secret from BIP39
|
|
187
328
|
* @param derivationPath DerivationPath for Key
|
|
188
329
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
330
|
+
TezosProtocol.prototype.getPublicKeyFromHexSecret = function (secret, derivationPath) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
var publicKey;
|
|
333
|
+
return __generator(this, function (_a) {
|
|
334
|
+
publicKey = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath) // TODO: Look into typings
|
|
335
|
+
.publicKey;
|
|
336
|
+
return [2 /*return*/, Buffer.from(publicKey).toString('hex')];
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
};
|
|
194
340
|
/**
|
|
195
341
|
* Returns the PrivateKey as Buffer, derived from a supplied hex-string
|
|
196
342
|
* @param secret HEX-Secret from BIP39
|
|
197
343
|
* @param derivationPath DerivationPath for Key
|
|
198
344
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return this
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
345
|
+
TezosProtocol.prototype.getPrivateKeyFromHexSecret = function (secret, derivationPath) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
347
|
+
var secretKey;
|
|
348
|
+
return __generator(this, function (_a) {
|
|
349
|
+
secretKey = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath) // TODO: Look into typings
|
|
350
|
+
.secretKey;
|
|
351
|
+
return [2 /*return*/, Buffer.from(secretKey).toString('hex')];
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
TezosProtocol.prototype.getAddressFromPublicKey = function (publicKey, cursor) {
|
|
356
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
357
|
+
var address;
|
|
358
|
+
return __generator(this, function (_a) {
|
|
359
|
+
switch (_a.label) {
|
|
360
|
+
case 0: return [4 /*yield*/, TezosAddress_1.TezosAddress.fromPublicKey(publicKey)];
|
|
361
|
+
case 1:
|
|
362
|
+
address = _a.sent();
|
|
363
|
+
return [2 /*return*/, {
|
|
364
|
+
address: address.asString(),
|
|
365
|
+
cursor: { hasNext: false }
|
|
366
|
+
}];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
TezosProtocol.prototype.getAddressesFromPublicKey = function (publicKey, cursor) {
|
|
372
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
373
|
+
var address;
|
|
374
|
+
return __generator(this, function (_a) {
|
|
375
|
+
switch (_a.label) {
|
|
376
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey, cursor)];
|
|
377
|
+
case 1:
|
|
378
|
+
address = _a.sent();
|
|
379
|
+
return [2 /*return*/, [address]];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
TezosProtocol.prototype.getTransactionsFromPublicKey = function (publicKey, limit, cursor) {
|
|
385
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
386
|
+
var addresses;
|
|
387
|
+
return __generator(this, function (_a) {
|
|
388
|
+
switch (_a.label) {
|
|
389
|
+
case 0: return [4 /*yield*/, this.getAddressesFromPublicKey(publicKey).then(function (addresses) {
|
|
390
|
+
return addresses.map(function (address) { return address.address; });
|
|
391
|
+
})];
|
|
392
|
+
case 1:
|
|
393
|
+
addresses = _a.sent();
|
|
394
|
+
return [2 /*return*/, this.getTransactionsFromAddresses(addresses, limit, cursor)];
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
TezosProtocol.prototype.getTransactionsFromAddresses = function (addresses, limit, cursor) {
|
|
400
|
+
var _a;
|
|
401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
402
|
+
var address, results;
|
|
403
|
+
var _this = this;
|
|
404
|
+
return __generator(this, function (_b) {
|
|
405
|
+
switch (_b.label) {
|
|
406
|
+
case 0:
|
|
407
|
+
address = addresses[0];
|
|
408
|
+
return [4 /*yield*/, this.options.network.extras.indexerClient.getTransactions(address, limit, cursor === null || cursor === void 0 ? void 0 : cursor.offset)];
|
|
409
|
+
case 1:
|
|
410
|
+
results = _b.sent();
|
|
411
|
+
return [2 /*return*/, {
|
|
412
|
+
transactions: results.map(function (transaction) { return (__assign(__assign({}, transaction), { protocolIdentifier: _this.identifier, network: _this.options.network })); }),
|
|
413
|
+
cursor: { offset: ((_a = cursor === null || cursor === void 0 ? void 0 : cursor.offset) !== null && _a !== void 0 ? _a : 0) + results.length }
|
|
414
|
+
}];
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
TezosProtocol.prototype.signWithPrivateKey = function (privateKey, transaction) {
|
|
420
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
+
var opSignature, signedOpBytes;
|
|
422
|
+
return __generator(this, function (_a) {
|
|
423
|
+
switch (_a.label) {
|
|
424
|
+
case 0: return [4 /*yield*/, this.cryptoClient.operationSignature(Buffer.from(privateKey, 'hex'), transaction)];
|
|
425
|
+
case 1:
|
|
426
|
+
opSignature = _a.sent();
|
|
427
|
+
signedOpBytes = Buffer.concat([Buffer.from(transaction.binaryTransaction, 'hex'), Buffer.from(opSignature)]);
|
|
428
|
+
return [2 /*return*/, signedOpBytes.toString('hex')];
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
TezosProtocol.prototype.getTransactionDetails = function (unsignedTx) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
435
|
+
var binaryTransaction, wrappedOperations;
|
|
436
|
+
return __generator(this, function (_a) {
|
|
437
|
+
switch (_a.label) {
|
|
438
|
+
case 0:
|
|
439
|
+
binaryTransaction = unsignedTx.transaction.binaryTransaction;
|
|
440
|
+
return [4 /*yield*/, this.unforgeUnsignedTezosWrappedOperation(binaryTransaction)];
|
|
441
|
+
case 1:
|
|
442
|
+
wrappedOperations = _a.sent();
|
|
443
|
+
return [2 /*return*/, this.getAirGapTxFromWrappedOperations(wrappedOperations)];
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
TezosProtocol.prototype.getTransactionDetailsFromSigned = function (signedTx) {
|
|
449
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
450
|
+
var binaryTransaction, wrappedOperations;
|
|
451
|
+
return __generator(this, function (_a) {
|
|
452
|
+
switch (_a.label) {
|
|
453
|
+
case 0:
|
|
454
|
+
binaryTransaction = signedTx.transaction;
|
|
455
|
+
return [4 /*yield*/, this.unforgeSignedTezosWrappedOperation(binaryTransaction)];
|
|
456
|
+
case 1:
|
|
457
|
+
wrappedOperations = _a.sent();
|
|
458
|
+
return [2 /*return*/, this.getAirGapTxFromWrappedOperations(wrappedOperations)];
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
TezosProtocol.prototype.getAirGapTxFromWrappedOperations = function (wrappedOperations) {
|
|
464
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
465
|
+
var assertNever;
|
|
466
|
+
var _this = this;
|
|
467
|
+
return __generator(this, function (_a) {
|
|
468
|
+
assertNever = function (_x) { return undefined; };
|
|
469
|
+
return [2 /*return*/, Promise.all(wrappedOperations.contents.map(function (tezosOperation) { return __awaiter(_this, void 0, void 0, function () {
|
|
470
|
+
var operation, partialTxs, _a, tezosSpendOperation_1, tezosOriginationOperation, delegate, delegate;
|
|
471
|
+
var _this = this;
|
|
472
|
+
return __generator(this, function (_b) {
|
|
473
|
+
switch (_b.label) {
|
|
474
|
+
case 0:
|
|
475
|
+
partialTxs = [];
|
|
476
|
+
_a = tezosOperation.kind;
|
|
477
|
+
switch (_a) {
|
|
478
|
+
case TezosOperationType_1.TezosOperationType.REVEAL: return [3 /*break*/, 1];
|
|
479
|
+
case TezosOperationType_1.TezosOperationType.TRANSACTION: return [3 /*break*/, 2];
|
|
480
|
+
case TezosOperationType_1.TezosOperationType.ORIGINATION: return [3 /*break*/, 4];
|
|
481
|
+
case TezosOperationType_1.TezosOperationType.DELEGATION: return [3 /*break*/, 5];
|
|
482
|
+
case TezosOperationType_1.TezosOperationType.ENDORSEMENT: return [3 /*break*/, 6];
|
|
483
|
+
case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION: return [3 /*break*/, 6];
|
|
484
|
+
case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE: return [3 /*break*/, 6];
|
|
485
|
+
case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE: return [3 /*break*/, 6];
|
|
486
|
+
case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT: return [3 /*break*/, 6];
|
|
487
|
+
case TezosOperationType_1.TezosOperationType.PROPOSALS: return [3 /*break*/, 6];
|
|
488
|
+
case TezosOperationType_1.TezosOperationType.BALLOT: return [3 /*break*/, 6];
|
|
489
|
+
}
|
|
490
|
+
return [3 /*break*/, 7];
|
|
491
|
+
case 1:
|
|
492
|
+
operation = tezosOperation;
|
|
493
|
+
partialTxs = [
|
|
494
|
+
{
|
|
495
|
+
from: [operation.source],
|
|
496
|
+
to: ['Reveal']
|
|
497
|
+
}
|
|
498
|
+
];
|
|
499
|
+
return [3 /*break*/, 8];
|
|
500
|
+
case 2:
|
|
501
|
+
tezosSpendOperation_1 = tezosOperation;
|
|
502
|
+
operation = tezosSpendOperation_1;
|
|
503
|
+
return [4 /*yield*/, this.getTransactionOperationDetails(tezosSpendOperation_1)];
|
|
504
|
+
case 3:
|
|
505
|
+
partialTxs = (_b.sent()).map(function (tx) { return (__assign(__assign({}, tx), { extra: __assign(__assign({}, tx.extra), { parameters: tezosSpendOperation_1.parameters }) })); });
|
|
506
|
+
return [3 /*break*/, 8];
|
|
507
|
+
case 4:
|
|
508
|
+
{
|
|
509
|
+
tezosOriginationOperation = tezosOperation;
|
|
510
|
+
operation = tezosOriginationOperation;
|
|
511
|
+
delegate = tezosOriginationOperation.delegate;
|
|
512
|
+
partialTxs = [
|
|
513
|
+
{
|
|
514
|
+
from: [operation.source],
|
|
515
|
+
amount: new bignumber_1.default(tezosOriginationOperation.balance).toFixed(),
|
|
516
|
+
to: [delegate ? "Delegate: ".concat(delegate) : 'Origination']
|
|
517
|
+
}
|
|
518
|
+
];
|
|
519
|
+
}
|
|
520
|
+
return [3 /*break*/, 8];
|
|
521
|
+
case 5:
|
|
522
|
+
{
|
|
523
|
+
operation = tezosOperation;
|
|
524
|
+
delegate = operation.delegate;
|
|
525
|
+
partialTxs = [
|
|
526
|
+
{
|
|
527
|
+
from: [operation.source],
|
|
528
|
+
to: [delegate ? delegate : 'Undelegate']
|
|
529
|
+
}
|
|
530
|
+
];
|
|
531
|
+
}
|
|
532
|
+
return [3 /*break*/, 8];
|
|
533
|
+
case 6: throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, 'operation not supported: ' + JSON.stringify(tezosOperation.kind));
|
|
534
|
+
case 7:
|
|
535
|
+
// Exhaustive switch
|
|
536
|
+
assertNever(tezosOperation.kind);
|
|
537
|
+
throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no operation to unforge found');
|
|
538
|
+
case 8: return [2 /*return*/, partialTxs.map(function (partialTx) {
|
|
539
|
+
return __assign({ amount: '0', fee: operation !== undefined ? new bignumber_1.default(operation.fee).toString(10) : '0', from: [], isInbound: false, protocolIdentifier: _this.identifier, network: _this.options.network, to: [], transactionDetails: tezosOperation }, partialTx);
|
|
540
|
+
})];
|
|
294
541
|
}
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION:
|
|
300
|
-
case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE:
|
|
301
|
-
case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE:
|
|
302
|
-
case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT:
|
|
303
|
-
case TezosOperationType_1.TezosOperationType.PROPOSALS:
|
|
304
|
-
case TezosOperationType_1.TezosOperationType.BALLOT:
|
|
305
|
-
throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, 'operation not supported: ' + JSON.stringify(tezosOperation.kind));
|
|
306
|
-
default:
|
|
307
|
-
// Exhaustive switch
|
|
308
|
-
assertNever(tezosOperation.kind);
|
|
309
|
-
throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no operation to unforge found');
|
|
310
|
-
}
|
|
311
|
-
return partialTxs.map((partialTx) => {
|
|
312
|
-
return {
|
|
313
|
-
amount: '0',
|
|
314
|
-
fee: operation !== undefined ? new bignumber_1.default(operation.fee).toString(10) : '0',
|
|
315
|
-
from: [],
|
|
316
|
-
isInbound: false,
|
|
317
|
-
protocolIdentifier: this.identifier,
|
|
318
|
-
network: this.options.network,
|
|
319
|
-
to: [],
|
|
320
|
-
transactionDetails: tezosOperation,
|
|
321
|
-
...partialTx
|
|
322
|
-
};
|
|
542
|
+
});
|
|
543
|
+
}); })).then(function (airGapTxs) {
|
|
544
|
+
return airGapTxs.reduce(function (flatten, next) { return flatten.concat(next); }, []);
|
|
545
|
+
})];
|
|
323
546
|
});
|
|
324
|
-
})
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
TezosProtocol.prototype.getBalanceOfAddresses = function (addresses, _data) {
|
|
550
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
+
var balance, _i, addresses_1, address, data, error_1;
|
|
552
|
+
return __generator(this, function (_a) {
|
|
553
|
+
switch (_a.label) {
|
|
554
|
+
case 0:
|
|
555
|
+
balance = new bignumber_1.default(0);
|
|
556
|
+
_i = 0, addresses_1 = addresses;
|
|
557
|
+
_a.label = 1;
|
|
558
|
+
case 1:
|
|
559
|
+
if (!(_i < addresses_1.length)) return [3 /*break*/, 6];
|
|
560
|
+
address = addresses_1[_i];
|
|
561
|
+
_a.label = 2;
|
|
562
|
+
case 2:
|
|
563
|
+
_a.trys.push([2, 4, , 5]);
|
|
564
|
+
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address, "/balance"))];
|
|
565
|
+
case 3:
|
|
566
|
+
data = (_a.sent()).data;
|
|
567
|
+
balance = balance.plus(new bignumber_1.default(data));
|
|
568
|
+
return [3 /*break*/, 5];
|
|
569
|
+
case 4:
|
|
570
|
+
error_1 = _a.sent();
|
|
571
|
+
// if node returns 404 (which means 'no account found'), go with 0 balance
|
|
572
|
+
if (error_1.response && error_1.response.status !== 404) {
|
|
573
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error_1);
|
|
574
|
+
}
|
|
575
|
+
return [3 /*break*/, 5];
|
|
576
|
+
case 5:
|
|
577
|
+
_i++;
|
|
578
|
+
return [3 /*break*/, 1];
|
|
579
|
+
case 6: return [2 /*return*/, balance.toString(10)];
|
|
337
580
|
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return this.getBalanceOfAddresses(addresses, data);
|
|
351
|
-
}
|
|
352
|
-
async estimateMaxTransactionValueFromPublicKey(publicKey, recipients, fee) {
|
|
353
|
-
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
354
|
-
const balanceWrapper = new bignumber_1.default(balance).minus(1); // Tezos accounts can never be empty. We must leave at least 1 mutez behind.
|
|
355
|
-
return this.estimateMaxTansactionValueWithBalance(publicKey, balanceWrapper, recipients, fee);
|
|
356
|
-
}
|
|
357
|
-
async estimateMaxTansactionValueWithBalance(publicKey, balance, recipients, fee) {
|
|
358
|
-
let maxFee = new bignumber_1.default(0);
|
|
359
|
-
if (fee !== undefined) {
|
|
360
|
-
maxFee = new bignumber_1.default(fee);
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
try {
|
|
364
|
-
const estimatedFeeDefaults = await this.estimateFeeDefaultsFromPublicKey(publicKey, recipients, [balance.toFixed()]);
|
|
365
|
-
maxFee = new bignumber_1.default(estimatedFeeDefaults.medium).shiftedBy(this.decimals);
|
|
366
|
-
if (maxFee.gte(balance)) {
|
|
367
|
-
maxFee = new bignumber_1.default(0);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
TezosProtocol.prototype.getBalanceOfPublicKey = function (publicKey, data) {
|
|
585
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
586
|
+
var address;
|
|
587
|
+
return __generator(this, function (_a) {
|
|
588
|
+
switch (_a.label) {
|
|
589
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
590
|
+
case 1:
|
|
591
|
+
address = _a.sent();
|
|
592
|
+
return [2 /*return*/, this.getBalanceOfAddresses([address.address], data)];
|
|
368
593
|
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
TezosProtocol.prototype.getBalanceOfPublicKeyForSubProtocols = function (publicKey, subProtocols) {
|
|
598
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
599
|
+
return __generator(this, function (_a) {
|
|
600
|
+
return [2 /*return*/, Promise.all(subProtocols.map(function (subProtocol) { return subProtocol.getBalanceOfPublicKey(publicKey).catch(function () { return '0'; }); }))];
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
TezosProtocol.prototype.getAvailableBalanceOfAddresses = function (addresses, data) {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
+
return __generator(this, function (_a) {
|
|
607
|
+
return [2 /*return*/, this.getBalanceOfAddresses(addresses, data)];
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
};
|
|
611
|
+
TezosProtocol.prototype.estimateMaxTransactionValueFromPublicKey = function (publicKey, recipients, fee) {
|
|
612
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
613
|
+
var balance, balanceWrapper;
|
|
614
|
+
return __generator(this, function (_a) {
|
|
615
|
+
switch (_a.label) {
|
|
616
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
617
|
+
case 1:
|
|
618
|
+
balance = _a.sent();
|
|
619
|
+
balanceWrapper = new bignumber_1.default(balance).minus(1) // Tezos accounts can never be empty. We must leave at least 1 mutez behind.
|
|
620
|
+
;
|
|
621
|
+
return [2 /*return*/, this.estimateMaxTansactionValueWithBalance(publicKey, balanceWrapper, recipients, fee)];
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
};
|
|
626
|
+
TezosProtocol.prototype.estimateMaxTansactionValueWithBalance = function (publicKey, balance, recipients, fee) {
|
|
627
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
628
|
+
var maxFee, estimatedFeeDefaults, error_2, rpcErrors, balanceTooLowError, excess, newMaxBalance, amountWithoutFees;
|
|
629
|
+
return __generator(this, function (_a) {
|
|
630
|
+
switch (_a.label) {
|
|
631
|
+
case 0:
|
|
632
|
+
maxFee = new bignumber_1.default(0);
|
|
633
|
+
if (!(fee !== undefined)) return [3 /*break*/, 1];
|
|
634
|
+
maxFee = new bignumber_1.default(fee);
|
|
635
|
+
return [3 /*break*/, 4];
|
|
636
|
+
case 1:
|
|
637
|
+
_a.trys.push([1, 3, , 4]);
|
|
638
|
+
return [4 /*yield*/, this.estimateFeeDefaultsFromPublicKey(publicKey, recipients, [balance.toFixed()])];
|
|
639
|
+
case 2:
|
|
640
|
+
estimatedFeeDefaults = _a.sent();
|
|
641
|
+
maxFee = new bignumber_1.default(estimatedFeeDefaults.medium).shiftedBy(this.decimals);
|
|
642
|
+
if (maxFee.gte(balance)) {
|
|
643
|
+
maxFee = new bignumber_1.default(0);
|
|
644
|
+
}
|
|
645
|
+
return [3 /*break*/, 4];
|
|
646
|
+
case 3:
|
|
647
|
+
error_2 = _a.sent();
|
|
648
|
+
if (error_2.code !== undefined && error_2.code === index_4.ProtocolErrorType.TRANSACTION_FAILED && Array.isArray(error_2.data)) {
|
|
649
|
+
rpcErrors = error_2.data;
|
|
650
|
+
balanceTooLowError = rpcErrors.find(function (error) { return error.id.endsWith('.contract.balance_too_low'); });
|
|
651
|
+
if (balanceTooLowError !== undefined && balanceTooLowError.amount !== undefined && balanceTooLowError.balance !== undefined) {
|
|
652
|
+
excess = new bignumber_1.default(balanceTooLowError.amount).minus(new bignumber_1.default(balanceTooLowError.balance).minus(1));
|
|
653
|
+
newMaxBalance = balance.minus(excess);
|
|
654
|
+
if (newMaxBalance.gt(0)) {
|
|
655
|
+
return [2 /*return*/, this.estimateMaxTansactionValueWithBalance(publicKey, newMaxBalance, recipients, fee)];
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
throw error_2;
|
|
660
|
+
case 4:
|
|
661
|
+
amountWithoutFees = balance.minus(maxFee);
|
|
662
|
+
if (amountWithoutFees.isNegative()) {
|
|
663
|
+
amountWithoutFees = new bignumber_1.default(0);
|
|
379
664
|
}
|
|
380
|
-
|
|
665
|
+
return [2 /*return*/, amountWithoutFees.toFixed()];
|
|
381
666
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
async estimateFeeDefaultsFromPublicKey(publicKey, recipients, values, _data) {
|
|
392
|
-
if (recipients.length !== values.length) {
|
|
393
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
394
|
-
}
|
|
395
|
-
const operations = [];
|
|
396
|
-
for (let i = 0; i < values.length; ++i) {
|
|
397
|
-
const recipient = recipients[i];
|
|
398
|
-
const transaction = {
|
|
399
|
-
kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
|
|
400
|
-
amount: values[i],
|
|
401
|
-
destination: recipient,
|
|
402
|
-
fee: '0'
|
|
403
|
-
};
|
|
404
|
-
operations.push(transaction);
|
|
405
|
-
}
|
|
406
|
-
if (recipients.length === 0) {
|
|
407
|
-
return this.feeDefaults;
|
|
408
|
-
}
|
|
409
|
-
return this.estimateFeeDefaultsForOperations(publicKey, operations);
|
|
410
|
-
}
|
|
411
|
-
async estimateFeeDefaultsForOperations(publicKey, operations) {
|
|
412
|
-
const estimated = await this.prepareOperations(publicKey, operations);
|
|
413
|
-
const hasReveal = estimated.contents.some((op) => op.kind === TezosOperationType_1.TezosOperationType.REVEAL);
|
|
414
|
-
const estimatedFee = estimated.contents
|
|
415
|
-
.reduce((current, next) => {
|
|
416
|
-
if (next.fee !== undefined) {
|
|
417
|
-
return current.plus(new bignumber_1.default(next.fee));
|
|
418
|
-
}
|
|
419
|
-
return current;
|
|
420
|
-
}, new bignumber_1.default(0))
|
|
421
|
-
.minus(hasReveal ? this.revealFee : 0)
|
|
422
|
-
.div(hasReveal ? estimated.contents.length - 1 : estimated.contents.length);
|
|
423
|
-
const feeStepFactor = new bignumber_1.default(0.2);
|
|
424
|
-
const lowFee = estimatedFee;
|
|
425
|
-
const mediumFee = lowFee.plus(lowFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
|
|
426
|
-
const highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
|
|
427
|
-
return {
|
|
428
|
-
low: lowFee.shiftedBy(-this.feeDecimals).toFixed(),
|
|
429
|
-
medium: mediumFee.shiftedBy(-this.feeDecimals).toFixed(),
|
|
430
|
-
high: highFee.shiftedBy(-this.feeDecimals).toFixed()
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
async prepareTransactionFromPublicKey(publicKey, recipients, values, fee, data) {
|
|
434
|
-
if (recipients.length !== values.length) {
|
|
435
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
436
|
-
}
|
|
437
|
-
if (recipients.length > MAX_OPERATIONS_PER_GROUP) {
|
|
438
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, `this transaction exceeds the maximum allowed number of transactions per operation (${MAX_OPERATIONS_PER_GROUP}). Please use the "prepareTransactionsFromPublicKey" method instead.`);
|
|
439
|
-
}
|
|
440
|
-
const transactions = await this.prepareTransactionsFromPublicKey(publicKey, recipients, values, fee, data);
|
|
441
|
-
if (transactions.length === 1) {
|
|
442
|
-
return transactions[0];
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Transaction could not be prepared. More or less than 1 operations have been generated.');
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
async prepareTransactionsFromPublicKey(publicKey, recipients, values, fee, data, operationsPerGroup = MAX_OPERATIONS_PER_GROUP) {
|
|
449
|
-
const wrappedValues = values.map((value) => new bignumber_1.default(value));
|
|
450
|
-
const wrappedFee = new bignumber_1.default(fee);
|
|
451
|
-
if (recipients.length !== wrappedValues.length) {
|
|
452
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
453
|
-
}
|
|
454
|
-
const operations = [];
|
|
455
|
-
// check if we got an address-index
|
|
456
|
-
const addressIndex = data && data.addressIndex ? data.addressIndex : 0;
|
|
457
|
-
const addresses = await this.getAddressesFromPublicKey(publicKey).then((addresses) => addresses.map((address) => address.address));
|
|
458
|
-
if (!addresses[addressIndex]) {
|
|
459
|
-
throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no kt-address with this index exists');
|
|
460
|
-
}
|
|
461
|
-
const address = addresses[addressIndex];
|
|
462
|
-
const results = await Promise.all([
|
|
463
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}/counter`),
|
|
464
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head~2/hash`),
|
|
465
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}/manager_key`)
|
|
466
|
-
]).catch((error) => {
|
|
467
|
-
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
468
|
-
});
|
|
469
|
-
const currentCounter = new bignumber_1.default(results[0].data);
|
|
470
|
-
let counter = currentCounter.plus(1);
|
|
471
|
-
const branch = results[1].data;
|
|
472
|
-
const accountManager = results[2].data;
|
|
473
|
-
// check if we have revealed the address already
|
|
474
|
-
if (!accountManager) {
|
|
475
|
-
operations.push(await this.createRevealOperation(counter, publicKey, address));
|
|
476
|
-
counter = counter.plus(1);
|
|
477
|
-
}
|
|
478
|
-
const balance = new bignumber_1.default(await this.getBalanceOfPublicKey(publicKey));
|
|
479
|
-
const wrappedOperations = [];
|
|
480
|
-
let allOperations = await this.createTransactionOperations(operations, recipients, wrappedValues, wrappedFee, address, counter, balance);
|
|
481
|
-
allOperations = operations.concat(allOperations); // if we have a reveal in operations, we need to make sure it is present in the allOperations array
|
|
482
|
-
const numberOfGroups = Math.ceil(allOperations.length / operationsPerGroup);
|
|
483
|
-
const startingCounter = numberOfGroups > 1 ? currentCounter.plus(1) : undefined;
|
|
484
|
-
for (let i = 0; i < numberOfGroups; i++) {
|
|
485
|
-
const start = i * operationsPerGroup;
|
|
486
|
-
const end = start + operationsPerGroup;
|
|
487
|
-
const operationsGroup = allOperations.slice(start, end);
|
|
488
|
-
const wrappedOperationWithEstimatedGas = await this.estimateAndReplaceLimitsAndFee({
|
|
489
|
-
branch,
|
|
490
|
-
contents: operationsGroup
|
|
491
|
-
}, false, startingCounter);
|
|
492
|
-
wrappedOperations.push(await this.forgeAndWrapOperations(wrappedOperationWithEstimatedGas));
|
|
493
|
-
}
|
|
494
|
-
return wrappedOperations;
|
|
495
|
-
}
|
|
496
|
-
async getTransactionOperationDetails(transactionOperation) {
|
|
497
|
-
return [
|
|
498
|
-
{
|
|
499
|
-
from: [transactionOperation.source],
|
|
500
|
-
amount: new bignumber_1.default(transactionOperation.amount).toFixed(),
|
|
501
|
-
to: [transactionOperation.destination] // contract destination but should be the address of actual receiver
|
|
502
|
-
}
|
|
503
|
-
];
|
|
504
|
-
}
|
|
505
|
-
async createTransactionOperations(previousOperations, recipients, wrappedValues, wrappedFee, address, counter, balance) {
|
|
506
|
-
const amountUsedByPreviousOperations = this.getAmountUsedByPreviousOperations(previousOperations);
|
|
507
|
-
const operations = [];
|
|
508
|
-
if (!amountUsedByPreviousOperations.isZero()) {
|
|
509
|
-
if (balance.isLessThan(wrappedValues[0].plus(wrappedFee).plus(amountUsedByPreviousOperations))) {
|
|
510
|
-
// if not, make room for the init fee
|
|
511
|
-
wrappedValues[0] = wrappedValues[0].minus(amountUsedByPreviousOperations); // deduct fee from balance
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
// TODO: We currently do not correctly calculate whether we have enough balance to pay the activation burn if there are multiple recipients
|
|
515
|
-
for (let i = 0; i < recipients.length; i++) {
|
|
516
|
-
const receivingBalance = new bignumber_1.default(await this.getBalanceOfAddresses([recipients[i]]));
|
|
517
|
-
// if our receiver has 0 balance, the account is not activated yet.
|
|
518
|
-
if (receivingBalance.isZero() && recipients[i].toLowerCase().startsWith('tz')) {
|
|
519
|
-
// We have to supply an additional 0.257 XTZ fee for storage_limit costs, which gets automatically deducted from the sender so we just have to make sure enough balance is around
|
|
520
|
-
if (balance.isLessThan(this.activationBurn.plus(wrappedFee))) {
|
|
521
|
-
// If we don't have enough funds to pay the activation + fee, we throw an error
|
|
522
|
-
throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'Insufficient balance to pay activation burn!');
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
TezosProtocol.prototype.estimateFeeDefaultsFromPublicKey = function (publicKey, recipients, values, _data) {
|
|
671
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
672
|
+
var operations, i, recipient, transaction;
|
|
673
|
+
return __generator(this, function (_a) {
|
|
674
|
+
if (recipients.length !== values.length) {
|
|
675
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
523
676
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
677
|
+
operations = [];
|
|
678
|
+
for (i = 0; i < values.length; ++i) {
|
|
679
|
+
recipient = recipients[i];
|
|
680
|
+
transaction = {
|
|
681
|
+
kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
|
|
682
|
+
amount: values[i],
|
|
683
|
+
destination: recipient,
|
|
684
|
+
fee: '0'
|
|
685
|
+
};
|
|
686
|
+
operations.push(transaction);
|
|
528
687
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
else if (balance.isLessThan(wrappedValues[i].plus(wrappedFee))) {
|
|
535
|
-
throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'not enough balance');
|
|
536
|
-
}
|
|
537
|
-
const spendOperation = {
|
|
538
|
-
kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
|
|
539
|
-
fee: wrappedFee.toFixed(),
|
|
540
|
-
gas_limit: GAS_LIMIT_PLACEHOLDER,
|
|
541
|
-
storage_limit: STORAGE_LIMIT_PLACEHOLDER,
|
|
542
|
-
amount: wrappedValues[i].toFixed(),
|
|
543
|
-
counter: counter.plus(i).toFixed(),
|
|
544
|
-
destination: recipients[i],
|
|
545
|
-
source: address
|
|
546
|
-
};
|
|
547
|
-
operations.push(spendOperation);
|
|
548
|
-
}
|
|
549
|
-
return operations;
|
|
550
|
-
}
|
|
551
|
-
async forgeAndWrapOperations(tezosWrappedOperation) {
|
|
552
|
-
try {
|
|
553
|
-
const binaryTx = await this.forgeTezosOperation(tezosWrappedOperation);
|
|
554
|
-
return { binaryTransaction: binaryTx };
|
|
555
|
-
}
|
|
556
|
-
catch (error) {
|
|
557
|
-
throw new index_4.OperationFailedError(coinlib_error_1.Domain.TEZOS, `Forging Tezos TX failed with ${JSON.stringify(error.message)}`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
async getDefaultDelegatee() {
|
|
561
|
-
const { data: activeBakers } = await index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/delegates?active`);
|
|
562
|
-
return activeBakers[0] || '';
|
|
563
|
-
}
|
|
564
|
-
async getCurrentDelegateesForPublicKey(publicKey) {
|
|
565
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
566
|
-
return this.getCurrentDelegateesForAddress(address.address);
|
|
567
|
-
}
|
|
568
|
-
async getCurrentDelegateesForAddress(address) {
|
|
569
|
-
const { data } = await index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}`);
|
|
570
|
-
return data.delegate ? [data.delegate] : [];
|
|
571
|
-
}
|
|
572
|
-
async getDelegateeDetails(address) {
|
|
573
|
-
const response = await index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/delegates/${address}/deactivated`);
|
|
574
|
-
const isBakingActive = !response.data;
|
|
575
|
-
return {
|
|
576
|
-
status: isBakingActive ? 'Active' : 'Inactive',
|
|
577
|
-
address
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
async isPublicKeyDelegating(publicKey) {
|
|
581
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
582
|
-
return this.isAddressDelegating(address.address);
|
|
583
|
-
}
|
|
584
|
-
async isAddressDelegating(address) {
|
|
585
|
-
const { data } = await index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}`);
|
|
586
|
-
return !!data.delegate;
|
|
587
|
-
}
|
|
588
|
-
async getDelegatorDetailsFromPublicKey(publicKey) {
|
|
589
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
590
|
-
return this.getDelegatorDetailsFromAddress(address.address);
|
|
591
|
-
}
|
|
592
|
-
async getDelegatorDetailsFromAddress(address) {
|
|
593
|
-
return this.getDelegatorDetails(address);
|
|
594
|
-
}
|
|
595
|
-
async getDelegationDetailsFromPublicKey(publicKey, delegatees) {
|
|
596
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
597
|
-
return this.getDelegationDetailsFromAddress(address.address, delegatees);
|
|
598
|
-
}
|
|
599
|
-
async getDelegationDetailsFromAddress(address, delegatees) {
|
|
600
|
-
if (delegatees.length > 1) {
|
|
601
|
-
return Promise.reject('Multiple delegation is not supported.');
|
|
602
|
-
}
|
|
603
|
-
const bakerAddress = delegatees[0];
|
|
604
|
-
const results = await Promise.all([this.getDelegatorDetails(address, bakerAddress), this.getDelegateeDetails(bakerAddress)]);
|
|
605
|
-
const delegatorDetails = results[0];
|
|
606
|
-
const bakerDetails = results[1];
|
|
607
|
-
return {
|
|
608
|
-
delegator: delegatorDetails,
|
|
609
|
-
delegatees: [bakerDetails]
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
async getDelegatorDetails(address, bakerAddress) {
|
|
613
|
-
const results = await Promise.all([index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}`)]);
|
|
614
|
-
const accountDetails = results[0].data;
|
|
615
|
-
const balance = accountDetails.balance;
|
|
616
|
-
const isDelegating = !!accountDetails.delegate;
|
|
617
|
-
const availableActions = [];
|
|
618
|
-
if (!isDelegating) {
|
|
619
|
-
availableActions.push({
|
|
620
|
-
type: TezosDelegatorAction.DELEGATE,
|
|
621
|
-
args: ['delegate']
|
|
688
|
+
if (recipients.length === 0) {
|
|
689
|
+
return [2 /*return*/, this.feeDefaults];
|
|
690
|
+
}
|
|
691
|
+
return [2 /*return*/, this.estimateFeeDefaultsForOperations(publicKey, operations)];
|
|
622
692
|
});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
TezosProtocol.prototype.estimateFeeDefaultsForOperations = function (publicKey, operations) {
|
|
696
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
697
|
+
var estimated, hasReveal, estimatedFee, feeStepFactor, lowFee, mediumFee, highFee;
|
|
698
|
+
return __generator(this, function (_a) {
|
|
699
|
+
switch (_a.label) {
|
|
700
|
+
case 0: return [4 /*yield*/, this.prepareOperations(publicKey, operations)];
|
|
701
|
+
case 1:
|
|
702
|
+
estimated = _a.sent();
|
|
703
|
+
hasReveal = estimated.contents.some(function (op) { return op.kind === TezosOperationType_1.TezosOperationType.REVEAL; });
|
|
704
|
+
estimatedFee = estimated.contents
|
|
705
|
+
.reduce(function (current, next) {
|
|
706
|
+
if (next.fee !== undefined) {
|
|
707
|
+
return current.plus(new bignumber_1.default(next.fee));
|
|
708
|
+
}
|
|
709
|
+
return current;
|
|
710
|
+
}, new bignumber_1.default(0))
|
|
711
|
+
.minus(hasReveal ? this.revealFee : 0)
|
|
712
|
+
.div(hasReveal ? estimated.contents.length - 1 : estimated.contents.length);
|
|
713
|
+
feeStepFactor = new bignumber_1.default(0.2);
|
|
714
|
+
lowFee = estimatedFee;
|
|
715
|
+
mediumFee = lowFee.plus(lowFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
|
|
716
|
+
highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
|
|
717
|
+
return [2 /*return*/, {
|
|
718
|
+
low: lowFee.shiftedBy(-this.feeDecimals).toFixed(),
|
|
719
|
+
medium: mediumFee.shiftedBy(-this.feeDecimals).toFixed(),
|
|
720
|
+
high: highFee.shiftedBy(-this.feeDecimals).toFixed()
|
|
721
|
+
}];
|
|
722
|
+
}
|
|
627
723
|
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
TezosProtocol.prototype.prepareTransactionFromPublicKey = function (publicKey, recipients, values, fee, data) {
|
|
727
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
728
|
+
var transactions;
|
|
729
|
+
return __generator(this, function (_a) {
|
|
730
|
+
switch (_a.label) {
|
|
731
|
+
case 0:
|
|
732
|
+
if (recipients.length !== values.length) {
|
|
733
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
734
|
+
}
|
|
735
|
+
if (recipients.length > MAX_OPERATIONS_PER_GROUP) {
|
|
736
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "this transaction exceeds the maximum allowed number of transactions per operation (".concat(MAX_OPERATIONS_PER_GROUP, "). Please use the \"prepareTransactionsFromPublicKey\" method instead."));
|
|
737
|
+
}
|
|
738
|
+
return [4 /*yield*/, this.prepareTransactionsFromPublicKey(publicKey, recipients, values, fee, data)];
|
|
739
|
+
case 1:
|
|
740
|
+
transactions = _a.sent();
|
|
741
|
+
if (transactions.length === 1) {
|
|
742
|
+
return [2 /*return*/, transactions[0]];
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Transaction could not be prepared. More or less than 1 operations have been generated.');
|
|
746
|
+
}
|
|
747
|
+
return [2 /*return*/];
|
|
748
|
+
}
|
|
633
749
|
});
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
TezosProtocol.prototype.prepareTransactionsFromPublicKey = function (publicKey, recipients, values, fee, data, operationsPerGroup) {
|
|
753
|
+
if (operationsPerGroup === void 0) { operationsPerGroup = MAX_OPERATIONS_PER_GROUP; }
|
|
754
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
755
|
+
var wrappedValues, wrappedFee, operations, addressIndex, addresses, address, results, currentCounter, counter, branch, accountManager, _a, _b, balance, _c, wrappedOperations, allOperations, numberOfGroups, startingCounter, i, start, end, operationsGroup, wrappedOperationWithEstimatedGas, _d, _e;
|
|
756
|
+
return __generator(this, function (_f) {
|
|
757
|
+
switch (_f.label) {
|
|
758
|
+
case 0:
|
|
759
|
+
wrappedValues = values.map(function (value) { return new bignumber_1.default(value); });
|
|
760
|
+
wrappedFee = new bignumber_1.default(fee);
|
|
761
|
+
if (recipients.length !== wrappedValues.length) {
|
|
762
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
|
|
763
|
+
}
|
|
764
|
+
operations = [];
|
|
765
|
+
addressIndex = data && data.addressIndex ? data.addressIndex : 0;
|
|
766
|
+
return [4 /*yield*/, this.getAddressesFromPublicKey(publicKey).then(function (addresses) {
|
|
767
|
+
return addresses.map(function (address) { return address.address; });
|
|
768
|
+
})];
|
|
769
|
+
case 1:
|
|
770
|
+
addresses = _f.sent();
|
|
771
|
+
if (!addresses[addressIndex]) {
|
|
772
|
+
throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no kt-address with this index exists');
|
|
773
|
+
}
|
|
774
|
+
address = addresses[addressIndex];
|
|
775
|
+
return [4 /*yield*/, Promise.all([
|
|
776
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address, "/counter")),
|
|
777
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head~2/hash")),
|
|
778
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address, "/manager_key"))
|
|
779
|
+
]).catch(function (error) {
|
|
780
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
781
|
+
})];
|
|
782
|
+
case 2:
|
|
783
|
+
results = _f.sent();
|
|
784
|
+
currentCounter = new bignumber_1.default(results[0].data);
|
|
785
|
+
counter = currentCounter.plus(1);
|
|
786
|
+
branch = results[1].data;
|
|
787
|
+
accountManager = results[2].data;
|
|
788
|
+
if (!!accountManager) return [3 /*break*/, 4];
|
|
789
|
+
_b = (_a = operations).push;
|
|
790
|
+
return [4 /*yield*/, this.createRevealOperation(counter, publicKey, address)];
|
|
791
|
+
case 3:
|
|
792
|
+
_b.apply(_a, [_f.sent()]);
|
|
793
|
+
counter = counter.plus(1);
|
|
794
|
+
_f.label = 4;
|
|
795
|
+
case 4:
|
|
796
|
+
_c = bignumber_1.default.bind;
|
|
797
|
+
return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
798
|
+
case 5:
|
|
799
|
+
balance = new (_c.apply(bignumber_1.default, [void 0, _f.sent()]))();
|
|
800
|
+
wrappedOperations = [];
|
|
801
|
+
return [4 /*yield*/, this.createTransactionOperations(operations, recipients, wrappedValues, wrappedFee, address, counter, balance)];
|
|
802
|
+
case 6:
|
|
803
|
+
allOperations = _f.sent();
|
|
804
|
+
allOperations = operations.concat(allOperations); // if we have a reveal in operations, we need to make sure it is present in the allOperations array
|
|
805
|
+
numberOfGroups = Math.ceil(allOperations.length / operationsPerGroup);
|
|
806
|
+
startingCounter = numberOfGroups > 1 ? currentCounter.plus(1) : undefined;
|
|
807
|
+
i = 0;
|
|
808
|
+
_f.label = 7;
|
|
809
|
+
case 7:
|
|
810
|
+
if (!(i < numberOfGroups)) return [3 /*break*/, 11];
|
|
811
|
+
start = i * operationsPerGroup;
|
|
812
|
+
end = start + operationsPerGroup;
|
|
813
|
+
operationsGroup = allOperations.slice(start, end);
|
|
814
|
+
return [4 /*yield*/, this.estimateAndReplaceLimitsAndFee({
|
|
815
|
+
branch: branch,
|
|
816
|
+
contents: operationsGroup
|
|
817
|
+
}, false, startingCounter)];
|
|
818
|
+
case 8:
|
|
819
|
+
wrappedOperationWithEstimatedGas = _f.sent();
|
|
820
|
+
_e = (_d = wrappedOperations).push;
|
|
821
|
+
return [4 /*yield*/, this.forgeAndWrapOperations(wrappedOperationWithEstimatedGas)];
|
|
822
|
+
case 9:
|
|
823
|
+
_e.apply(_d, [_f.sent()]);
|
|
824
|
+
_f.label = 10;
|
|
825
|
+
case 10:
|
|
826
|
+
i++;
|
|
827
|
+
return [3 /*break*/, 7];
|
|
828
|
+
case 11: return [2 /*return*/, wrappedOperations];
|
|
648
829
|
}
|
|
649
|
-
|
|
650
|
-
case TezosDelegatorAction.UNDELEGATE:
|
|
651
|
-
return [await this.undelegate(publicKey)];
|
|
652
|
-
default:
|
|
653
|
-
return Promise.reject('Unsupported delegator action.');
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
async prepareOperations(publicKey, operationRequests, overrideParameters = true) {
|
|
657
|
-
let counter = new bignumber_1.default(1);
|
|
658
|
-
let branch;
|
|
659
|
-
const operations = [];
|
|
660
|
-
const address = await this.getAddressFromPublicKey(publicKey).then((address) => address.address);
|
|
661
|
-
const results = await Promise.all([
|
|
662
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}/counter`),
|
|
663
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head~2/hash`),
|
|
664
|
-
index_1.default.get(`${this.options.network.rpcUrl}/chains/main/blocks/head/context/contracts/${address}/manager_key`)
|
|
665
|
-
]).catch((error) => {
|
|
666
|
-
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
667
|
-
});
|
|
668
|
-
counter = new bignumber_1.default(results[0].data).plus(1);
|
|
669
|
-
branch = results[1].data;
|
|
670
|
-
const accountManager = results[2].data;
|
|
671
|
-
const hasRevealInOperationRequests = operationRequests.some((request) => request.kind === TezosOperationType_1.TezosOperationType.REVEAL);
|
|
672
|
-
// check if we have revealed the address already
|
|
673
|
-
if (!accountManager && !hasRevealInOperationRequests) {
|
|
674
|
-
operations.push(await this.createRevealOperation(counter, publicKey, address));
|
|
675
|
-
counter = counter.plus(1);
|
|
676
|
-
}
|
|
677
|
-
// tslint:disable:cyclomatic-complexity
|
|
678
|
-
const operationPromises = operationRequests.map(async (operationRequest, index) => {
|
|
679
|
-
// TODO: Handle activation burn
|
|
680
|
-
if (!operationRequest.kind) {
|
|
681
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "kind" was not defined');
|
|
682
|
-
}
|
|
683
|
-
const recipient = operationRequest.destination;
|
|
684
|
-
let receivingBalance;
|
|
685
|
-
if (recipient && recipient.toLowerCase().startsWith('tz')) {
|
|
686
|
-
receivingBalance = new bignumber_1.default(await this.getBalanceOfAddresses([recipient]));
|
|
687
|
-
}
|
|
688
|
-
const defaultCounter = counter.plus(index).toFixed(); // TODO: Handle counter if we have some operations without counters in the array
|
|
689
|
-
const defaultFee = FEE_PLACEHOLDER;
|
|
690
|
-
const defaultGasLimit = '10300';
|
|
691
|
-
const defaultStorageLimit = receivingBalance && receivingBalance.isZero() && recipient && recipient.toLowerCase().startsWith('tz') ? '300' : '0'; // taken from eztz
|
|
692
|
-
switch (operationRequest.kind) {
|
|
693
|
-
// TODO: Handle if the dApp already provides a reveal operation
|
|
694
|
-
case TezosOperationType_1.TezosOperationType.REVEAL:
|
|
695
|
-
const revealOperation = operationRequest;
|
|
696
|
-
if (!revealOperation.public_key) {
|
|
697
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "public_key" was not defined');
|
|
698
|
-
}
|
|
699
|
-
revealOperation.source = revealOperation.source ?? address;
|
|
700
|
-
revealOperation.counter = revealOperation.counter ?? defaultCounter;
|
|
701
|
-
revealOperation.fee = revealOperation.fee ?? defaultFee;
|
|
702
|
-
revealOperation.gas_limit = revealOperation.gas_limit ?? defaultGasLimit;
|
|
703
|
-
revealOperation.storage_limit = revealOperation.storage_limit ?? defaultStorageLimit;
|
|
704
|
-
return revealOperation;
|
|
705
|
-
case TezosOperationType_1.TezosOperationType.DELEGATION:
|
|
706
|
-
const delegationOperation = operationRequest;
|
|
707
|
-
// The delegate property is optional, so we don't have any mandatory properties to check for
|
|
708
|
-
delegationOperation.source = delegationOperation.source ?? address;
|
|
709
|
-
delegationOperation.counter = delegationOperation.counter ?? defaultCounter;
|
|
710
|
-
delegationOperation.fee = delegationOperation.fee ?? defaultFee;
|
|
711
|
-
delegationOperation.gas_limit = delegationOperation.gas_limit ?? defaultGasLimit;
|
|
712
|
-
delegationOperation.storage_limit = delegationOperation.storage_limit ?? defaultStorageLimit;
|
|
713
|
-
return delegationOperation;
|
|
714
|
-
case TezosOperationType_1.TezosOperationType.TRANSACTION:
|
|
715
|
-
const transactionOperation = operationRequest;
|
|
716
|
-
if (!transactionOperation.amount) {
|
|
717
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "amount" was not defined');
|
|
718
|
-
}
|
|
719
|
-
if (!transactionOperation.destination) {
|
|
720
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "destination" was not defined');
|
|
721
|
-
}
|
|
722
|
-
transactionOperation.source = transactionOperation.source ?? address;
|
|
723
|
-
transactionOperation.counter = transactionOperation.counter ?? defaultCounter;
|
|
724
|
-
transactionOperation.fee = transactionOperation.fee ?? defaultFee;
|
|
725
|
-
transactionOperation.gas_limit = transactionOperation.gas_limit ?? GAS_LIMIT_PLACEHOLDER;
|
|
726
|
-
transactionOperation.storage_limit = transactionOperation.storage_limit ?? STORAGE_LIMIT_PLACEHOLDER;
|
|
727
|
-
return transactionOperation;
|
|
728
|
-
case TezosOperationType_1.TezosOperationType.ORIGINATION:
|
|
729
|
-
const originationOperation = operationRequest;
|
|
730
|
-
if (!originationOperation.balance) {
|
|
731
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "balance" was not defined');
|
|
732
|
-
}
|
|
733
|
-
if (!originationOperation.script) {
|
|
734
|
-
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "script" was not defined');
|
|
735
|
-
}
|
|
736
|
-
originationOperation.source = originationOperation.source ?? address;
|
|
737
|
-
originationOperation.counter = originationOperation.counter ?? defaultCounter;
|
|
738
|
-
originationOperation.fee = originationOperation.fee ?? defaultFee;
|
|
739
|
-
originationOperation.gas_limit = originationOperation.gas_limit ?? GAS_LIMIT_PLACEHOLDER;
|
|
740
|
-
originationOperation.storage_limit = originationOperation.storage_limit ?? STORAGE_LIMIT_PLACEHOLDER;
|
|
741
|
-
return originationOperation;
|
|
742
|
-
case TezosOperationType_1.TezosOperationType.ENDORSEMENT:
|
|
743
|
-
case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION:
|
|
744
|
-
case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE:
|
|
745
|
-
case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE:
|
|
746
|
-
case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT:
|
|
747
|
-
case TezosOperationType_1.TezosOperationType.PROPOSALS:
|
|
748
|
-
case TezosOperationType_1.TezosOperationType.BALLOT:
|
|
749
|
-
// Do not change anything
|
|
750
|
-
return operationRequest;
|
|
751
|
-
default:
|
|
752
|
-
(0, assert_1.assertNever)(operationRequest.kind);
|
|
753
|
-
throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, `unsupported operation type "${JSON.stringify(operationRequest.kind)}"`);
|
|
754
|
-
}
|
|
830
|
+
});
|
|
755
831
|
});
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
const body = {
|
|
783
|
-
chain_id: block.chain_id,
|
|
784
|
-
operation: {
|
|
785
|
-
branch: tezosWrappedOperation.branch,
|
|
786
|
-
contents: contents,
|
|
787
|
-
signature: fakeSignature // signature will not be checked, so it is ok to always use this one
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
const forgedOperation = await this.forgeTezosOperation(tezosWrappedOperation);
|
|
791
|
-
let gasLimitTotal = 0;
|
|
792
|
-
const response = await index_1.default
|
|
793
|
-
.post(`${this.options.network.rpcUrl}/chains/main/blocks/head/helpers/scripts/run_operation`, body, {
|
|
794
|
-
headers: { 'Content-Type': 'application/json' }
|
|
795
|
-
})
|
|
796
|
-
.catch((runOperationError) => {
|
|
797
|
-
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, runOperationError);
|
|
798
|
-
});
|
|
799
|
-
if (tezosWrappedOperation.contents.length !== response.data.contents.length) {
|
|
800
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, `Run Operation did not return same number of operations. Locally we have ${tezosWrappedOperation.contents.length}, but got back ${response.data.contents.length}`);
|
|
801
|
-
}
|
|
802
|
-
tezosWrappedOperation.contents.forEach((content, i) => {
|
|
803
|
-
const metadata = response.data.contents[i].metadata;
|
|
804
|
-
if (metadata.operation_result) {
|
|
805
|
-
const operation = content;
|
|
806
|
-
const result = metadata.operation_result;
|
|
807
|
-
let gasLimit = 0;
|
|
808
|
-
let storageLimit = 0;
|
|
809
|
-
// If there are internal operations, we first add gas and storage used of internal operations
|
|
810
|
-
if (metadata.internal_operation_results) {
|
|
811
|
-
metadata.internal_operation_results.forEach((internalOperation) => {
|
|
812
|
-
if (internalOperation?.result) {
|
|
813
|
-
if (internalOperation.result.errors) {
|
|
814
|
-
throw new index_4.TransactionError(coinlib_error_1.Domain.TEZOS, 'An internal operation produced an error', internalOperation.result.errors);
|
|
815
|
-
}
|
|
816
|
-
gasLimit += Math.ceil(Number(internalOperation.result.consumed_milligas) / 1000);
|
|
817
|
-
if (internalOperation.result.paid_storage_size_diff) {
|
|
818
|
-
storageLimit += Number(internalOperation.result.paid_storage_size_diff);
|
|
832
|
+
};
|
|
833
|
+
TezosProtocol.prototype.getTransactionOperationDetails = function (transactionOperation) {
|
|
834
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
835
|
+
return __generator(this, function (_a) {
|
|
836
|
+
return [2 /*return*/, [
|
|
837
|
+
{
|
|
838
|
+
from: [transactionOperation.source],
|
|
839
|
+
amount: new bignumber_1.default(transactionOperation.amount).toFixed(),
|
|
840
|
+
to: [transactionOperation.destination] // contract destination but should be the address of actual receiver
|
|
841
|
+
}
|
|
842
|
+
]];
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
};
|
|
846
|
+
TezosProtocol.prototype.createTransactionOperations = function (previousOperations, recipients, wrappedValues, wrappedFee, address, counter, balance) {
|
|
847
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
848
|
+
var amountUsedByPreviousOperations, operations, i, receivingBalance, _a, spendOperation;
|
|
849
|
+
return __generator(this, function (_b) {
|
|
850
|
+
switch (_b.label) {
|
|
851
|
+
case 0:
|
|
852
|
+
amountUsedByPreviousOperations = this.getAmountUsedByPreviousOperations(previousOperations);
|
|
853
|
+
operations = [];
|
|
854
|
+
if (!amountUsedByPreviousOperations.isZero()) {
|
|
855
|
+
if (balance.isLessThan(wrappedValues[0].plus(wrappedFee).plus(amountUsedByPreviousOperations))) {
|
|
856
|
+
// if not, make room for the init fee
|
|
857
|
+
wrappedValues[0] = wrappedValues[0].minus(amountUsedByPreviousOperations); // deduct fee from balance
|
|
819
858
|
}
|
|
820
|
-
|
|
821
|
-
|
|
859
|
+
}
|
|
860
|
+
i = 0;
|
|
861
|
+
_b.label = 1;
|
|
862
|
+
case 1:
|
|
863
|
+
if (!(i < recipients.length)) return [3 /*break*/, 4];
|
|
864
|
+
_a = bignumber_1.default.bind;
|
|
865
|
+
return [4 /*yield*/, this.getBalanceOfAddresses([recipients[i]])];
|
|
866
|
+
case 2:
|
|
867
|
+
receivingBalance = new (_a.apply(bignumber_1.default, [void 0, _b.sent()]))();
|
|
868
|
+
// if our receiver has 0 balance, the account is not activated yet.
|
|
869
|
+
if (receivingBalance.isZero() && recipients[i].toLowerCase().startsWith('tz')) {
|
|
870
|
+
// We have to supply an additional 0.257 XTZ fee for storage_limit costs, which gets automatically deducted from the sender so we just have to make sure enough balance is around
|
|
871
|
+
if (balance.isLessThan(this.activationBurn.plus(wrappedFee))) {
|
|
872
|
+
// If we don't have enough funds to pay the activation + fee, we throw an error
|
|
873
|
+
throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'Insufficient balance to pay activation burn!');
|
|
822
874
|
}
|
|
823
|
-
if (
|
|
824
|
-
|
|
875
|
+
else if (balance.isLessThan(wrappedValues[i].plus(wrappedFee).plus(this.activationBurn))) {
|
|
876
|
+
// Check whether the sender has enough to cover the amount to send + fee + activation
|
|
877
|
+
// If not, we deduct it from amount sent to make room for the activation burn
|
|
878
|
+
wrappedValues[i] = wrappedValues[i].minus(this.activationBurn); // deduct fee from balance
|
|
825
879
|
}
|
|
826
880
|
}
|
|
827
|
-
|
|
881
|
+
if (balance.isEqualTo(wrappedValues[i].plus(wrappedFee))) {
|
|
882
|
+
// Tezos accounts can never be empty. If user tries to send everything, we must leave 1 mutez behind.
|
|
883
|
+
wrappedValues[i] = wrappedValues[i].minus(1);
|
|
884
|
+
}
|
|
885
|
+
else if (balance.isLessThan(wrappedValues[i].plus(wrappedFee))) {
|
|
886
|
+
throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'not enough balance');
|
|
887
|
+
}
|
|
888
|
+
spendOperation = {
|
|
889
|
+
kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
|
|
890
|
+
fee: wrappedFee.toFixed(),
|
|
891
|
+
gas_limit: GAS_LIMIT_PLACEHOLDER,
|
|
892
|
+
storage_limit: STORAGE_LIMIT_PLACEHOLDER,
|
|
893
|
+
amount: wrappedValues[i].toFixed(),
|
|
894
|
+
counter: counter.plus(i).toFixed(),
|
|
895
|
+
destination: recipients[i],
|
|
896
|
+
source: address
|
|
897
|
+
};
|
|
898
|
+
operations.push(spendOperation);
|
|
899
|
+
_b.label = 3;
|
|
900
|
+
case 3:
|
|
901
|
+
i++;
|
|
902
|
+
return [3 /*break*/, 1];
|
|
903
|
+
case 4: return [2 /*return*/, operations];
|
|
828
904
|
}
|
|
829
|
-
|
|
830
|
-
|
|
905
|
+
});
|
|
906
|
+
});
|
|
907
|
+
};
|
|
908
|
+
TezosProtocol.prototype.forgeAndWrapOperations = function (tezosWrappedOperation) {
|
|
909
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
910
|
+
var binaryTx, error_3;
|
|
911
|
+
return __generator(this, function (_a) {
|
|
912
|
+
switch (_a.label) {
|
|
913
|
+
case 0:
|
|
914
|
+
_a.trys.push([0, 2, , 3]);
|
|
915
|
+
return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
|
|
916
|
+
case 1:
|
|
917
|
+
binaryTx = _a.sent();
|
|
918
|
+
return [2 /*return*/, { binaryTransaction: binaryTx }];
|
|
919
|
+
case 2:
|
|
920
|
+
error_3 = _a.sent();
|
|
921
|
+
throw new index_4.OperationFailedError(coinlib_error_1.Domain.TEZOS, "Forging Tezos TX failed with ".concat(JSON.stringify(error_3.message)));
|
|
922
|
+
case 3: return [2 /*return*/];
|
|
831
923
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
};
|
|
927
|
+
TezosProtocol.prototype.getDefaultDelegatee = function () {
|
|
928
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
929
|
+
var activeBakers;
|
|
930
|
+
return __generator(this, function (_a) {
|
|
931
|
+
switch (_a.label) {
|
|
932
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates?active"))];
|
|
933
|
+
case 1:
|
|
934
|
+
activeBakers = (_a.sent()).data;
|
|
935
|
+
return [2 /*return*/, activeBakers[0] || ''];
|
|
836
936
|
}
|
|
837
|
-
|
|
838
|
-
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
TezosProtocol.prototype.getCurrentDelegateesForPublicKey = function (publicKey) {
|
|
941
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
942
|
+
var address;
|
|
943
|
+
return __generator(this, function (_a) {
|
|
944
|
+
switch (_a.label) {
|
|
945
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
946
|
+
case 1:
|
|
947
|
+
address = _a.sent();
|
|
948
|
+
return [2 /*return*/, this.getCurrentDelegateesForAddress(address.address)];
|
|
839
949
|
}
|
|
840
|
-
|
|
841
|
-
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
};
|
|
953
|
+
TezosProtocol.prototype.getCurrentDelegateesForAddress = function (address) {
|
|
954
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
955
|
+
var data;
|
|
956
|
+
return __generator(this, function (_a) {
|
|
957
|
+
switch (_a.label) {
|
|
958
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))];
|
|
959
|
+
case 1:
|
|
960
|
+
data = (_a.sent()).data;
|
|
961
|
+
return [2 /*return*/, data.delegate ? [data.delegate] : []];
|
|
842
962
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
};
|
|
966
|
+
TezosProtocol.prototype.getDelegateeDetails = function (address) {
|
|
967
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
968
|
+
var response, isBakingActive;
|
|
969
|
+
return __generator(this, function (_a) {
|
|
970
|
+
switch (_a.label) {
|
|
971
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/deactivated"))];
|
|
972
|
+
case 1:
|
|
973
|
+
response = _a.sent();
|
|
974
|
+
isBakingActive = !response.data;
|
|
975
|
+
return [2 /*return*/, {
|
|
976
|
+
status: isBakingActive ? 'Active' : 'Inactive',
|
|
977
|
+
address: address
|
|
978
|
+
}];
|
|
847
979
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
};
|
|
983
|
+
TezosProtocol.prototype.isPublicKeyDelegating = function (publicKey) {
|
|
984
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
985
|
+
var address;
|
|
986
|
+
return __generator(this, function (_a) {
|
|
987
|
+
switch (_a.label) {
|
|
988
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
989
|
+
case 1:
|
|
990
|
+
address = _a.sent();
|
|
991
|
+
return [2 /*return*/, this.isAddressDelegating(address.address)];
|
|
851
992
|
}
|
|
852
|
-
|
|
853
|
-
}
|
|
993
|
+
});
|
|
854
994
|
});
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
operation.fee = feePerOperation.toString();
|
|
995
|
+
};
|
|
996
|
+
TezosProtocol.prototype.isAddressDelegating = function (address) {
|
|
997
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
998
|
+
var data;
|
|
999
|
+
return __generator(this, function (_a) {
|
|
1000
|
+
switch (_a.label) {
|
|
1001
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))];
|
|
1002
|
+
case 1:
|
|
1003
|
+
data = (_a.sent()).data;
|
|
1004
|
+
return [2 /*return*/, !!data.delegate];
|
|
866
1005
|
}
|
|
867
1006
|
});
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
};
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1007
|
+
});
|
|
1008
|
+
};
|
|
1009
|
+
TezosProtocol.prototype.getDelegatorDetailsFromPublicKey = function (publicKey) {
|
|
1010
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1011
|
+
var address;
|
|
1012
|
+
return __generator(this, function (_a) {
|
|
1013
|
+
switch (_a.label) {
|
|
1014
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
1015
|
+
case 1:
|
|
1016
|
+
address = _a.sent();
|
|
1017
|
+
return [2 /*return*/, this.getDelegatorDetailsFromAddress(address.address)];
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
};
|
|
1022
|
+
TezosProtocol.prototype.getDelegatorDetailsFromAddress = function (address) {
|
|
1023
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1024
|
+
return __generator(this, function (_a) {
|
|
1025
|
+
return [2 /*return*/, this.getDelegatorDetails(address)];
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
};
|
|
1029
|
+
TezosProtocol.prototype.getDelegationDetailsFromPublicKey = function (publicKey, delegatees) {
|
|
1030
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1031
|
+
var address;
|
|
1032
|
+
return __generator(this, function (_a) {
|
|
1033
|
+
switch (_a.label) {
|
|
1034
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
1035
|
+
case 1:
|
|
1036
|
+
address = _a.sent();
|
|
1037
|
+
return [2 /*return*/, this.getDelegationDetailsFromAddress(address.address, delegatees)];
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
};
|
|
1042
|
+
TezosProtocol.prototype.getDelegationDetailsFromAddress = function (address, delegatees) {
|
|
1043
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1044
|
+
var bakerAddress, results, delegatorDetails, bakerDetails;
|
|
1045
|
+
return __generator(this, function (_a) {
|
|
1046
|
+
switch (_a.label) {
|
|
1047
|
+
case 0:
|
|
1048
|
+
if (delegatees.length > 1) {
|
|
1049
|
+
return [2 /*return*/, Promise.reject('Multiple delegation is not supported.')];
|
|
1050
|
+
}
|
|
1051
|
+
bakerAddress = delegatees[0];
|
|
1052
|
+
return [4 /*yield*/, Promise.all([this.getDelegatorDetails(address, bakerAddress), this.getDelegateeDetails(bakerAddress)])];
|
|
1053
|
+
case 1:
|
|
1054
|
+
results = _a.sent();
|
|
1055
|
+
delegatorDetails = results[0];
|
|
1056
|
+
bakerDetails = results[1];
|
|
1057
|
+
return [2 /*return*/, {
|
|
1058
|
+
delegator: delegatorDetails,
|
|
1059
|
+
delegatees: [bakerDetails]
|
|
1060
|
+
}];
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
TezosProtocol.prototype.getDelegatorDetails = function (address, bakerAddress) {
|
|
1066
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1067
|
+
var results, accountDetails, balance, isDelegating, availableActions;
|
|
1068
|
+
return __generator(this, function (_a) {
|
|
1069
|
+
switch (_a.label) {
|
|
1070
|
+
case 0: return [4 /*yield*/, Promise.all([index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))])];
|
|
1071
|
+
case 1:
|
|
1072
|
+
results = _a.sent();
|
|
1073
|
+
accountDetails = results[0].data;
|
|
1074
|
+
balance = accountDetails.balance;
|
|
1075
|
+
isDelegating = !!accountDetails.delegate;
|
|
1076
|
+
availableActions = [];
|
|
1077
|
+
if (!isDelegating) {
|
|
1078
|
+
availableActions.push({
|
|
1079
|
+
type: TezosDelegatorAction.DELEGATE,
|
|
1080
|
+
args: ['delegate']
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
else if (!bakerAddress || accountDetails.delegate === bakerAddress) {
|
|
1084
|
+
availableActions.push({
|
|
1085
|
+
type: TezosDelegatorAction.UNDELEGATE
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
else {
|
|
1089
|
+
availableActions.push({
|
|
1090
|
+
type: TezosDelegatorAction.CHANGE_BAKER,
|
|
1091
|
+
args: ['delegate']
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
return [2 /*return*/, {
|
|
1095
|
+
address: address,
|
|
1096
|
+
balance: balance,
|
|
1097
|
+
delegatees: [accountDetails.delegate],
|
|
1098
|
+
availableActions: availableActions
|
|
1099
|
+
}];
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
});
|
|
1103
|
+
};
|
|
1104
|
+
TezosProtocol.prototype.prepareDelegatorActionFromPublicKey = function (publicKey, type, data) {
|
|
1105
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1106
|
+
var _a;
|
|
1107
|
+
return __generator(this, function (_b) {
|
|
1108
|
+
switch (_b.label) {
|
|
1109
|
+
case 0:
|
|
1110
|
+
_a = type;
|
|
1111
|
+
switch (_a) {
|
|
1112
|
+
case TezosDelegatorAction.DELEGATE: return [3 /*break*/, 1];
|
|
1113
|
+
case TezosDelegatorAction.CHANGE_BAKER: return [3 /*break*/, 1];
|
|
1114
|
+
case TezosDelegatorAction.UNDELEGATE: return [3 /*break*/, 3];
|
|
1115
|
+
}
|
|
1116
|
+
return [3 /*break*/, 5];
|
|
1117
|
+
case 1:
|
|
1118
|
+
if (!data || !data.delegate) {
|
|
1119
|
+
return [2 /*return*/, Promise.reject("Invalid arguments passed for ".concat(type, " action, delegate is missing."))];
|
|
1120
|
+
}
|
|
1121
|
+
return [4 /*yield*/, this.delegate(publicKey, data.delegate)];
|
|
1122
|
+
case 2: return [2 /*return*/, [_b.sent()]];
|
|
1123
|
+
case 3: return [4 /*yield*/, this.undelegate(publicKey)];
|
|
1124
|
+
case 4: return [2 /*return*/, [_b.sent()]];
|
|
1125
|
+
case 5: return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
TezosProtocol.prototype.prepareOperations = function (publicKey, operationRequests, overrideParameters) {
|
|
1131
|
+
if (overrideParameters === void 0) { overrideParameters = true; }
|
|
1132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1133
|
+
var counter, branch, operations, address, results, accountManager, hasRevealInOperationRequests, _a, _b, operationPromises, _c, _d, _e, tezosWrappedOperation;
|
|
1134
|
+
var _this = this;
|
|
1135
|
+
return __generator(this, function (_f) {
|
|
1136
|
+
switch (_f.label) {
|
|
1137
|
+
case 0:
|
|
1138
|
+
counter = new bignumber_1.default(1);
|
|
1139
|
+
operations = [];
|
|
1140
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(publicKey).then(function (address) { return address.address; })];
|
|
1141
|
+
case 1:
|
|
1142
|
+
address = _f.sent();
|
|
1143
|
+
return [4 /*yield*/, Promise.all([
|
|
1144
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address, "/counter")),
|
|
1145
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head~2/hash")),
|
|
1146
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address, "/manager_key"))
|
|
1147
|
+
]).catch(function (error) {
|
|
1148
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
1149
|
+
})];
|
|
1150
|
+
case 2:
|
|
1151
|
+
results = _f.sent();
|
|
1152
|
+
counter = new bignumber_1.default(results[0].data).plus(1);
|
|
1153
|
+
branch = results[1].data;
|
|
1154
|
+
accountManager = results[2].data;
|
|
1155
|
+
hasRevealInOperationRequests = operationRequests.some(function (request) { return request.kind === TezosOperationType_1.TezosOperationType.REVEAL; });
|
|
1156
|
+
if (!(!accountManager && !hasRevealInOperationRequests)) return [3 /*break*/, 4];
|
|
1157
|
+
_b = (_a = operations).push;
|
|
1158
|
+
return [4 /*yield*/, this.createRevealOperation(counter, publicKey, address)];
|
|
1159
|
+
case 3:
|
|
1160
|
+
_b.apply(_a, [_f.sent()]);
|
|
1161
|
+
counter = counter.plus(1);
|
|
1162
|
+
_f.label = 4;
|
|
1163
|
+
case 4:
|
|
1164
|
+
operationPromises = operationRequests.map(function (operationRequest, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1165
|
+
var recipient, receivingBalance, _a, defaultCounter, defaultFee, defaultGasLimit, defaultStorageLimit, revealOperation, delegationOperation, transactionOperation, originationOperation;
|
|
1166
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1167
|
+
return __generator(this, function (_y) {
|
|
1168
|
+
switch (_y.label) {
|
|
1169
|
+
case 0:
|
|
1170
|
+
// TODO: Handle activation burn
|
|
1171
|
+
if (!operationRequest.kind) {
|
|
1172
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "kind" was not defined');
|
|
1173
|
+
}
|
|
1174
|
+
recipient = operationRequest.destination;
|
|
1175
|
+
if (!(recipient && recipient.toLowerCase().startsWith('tz'))) return [3 /*break*/, 2];
|
|
1176
|
+
_a = bignumber_1.default.bind;
|
|
1177
|
+
return [4 /*yield*/, this.getBalanceOfAddresses([recipient])];
|
|
1178
|
+
case 1:
|
|
1179
|
+
receivingBalance = new (_a.apply(bignumber_1.default, [void 0, _y.sent()]))();
|
|
1180
|
+
_y.label = 2;
|
|
1181
|
+
case 2:
|
|
1182
|
+
defaultCounter = counter.plus(index).toFixed() // TODO: Handle counter if we have some operations without counters in the array
|
|
1183
|
+
;
|
|
1184
|
+
defaultFee = FEE_PLACEHOLDER;
|
|
1185
|
+
defaultGasLimit = '10300';
|
|
1186
|
+
defaultStorageLimit = receivingBalance && receivingBalance.isZero() && recipient && recipient.toLowerCase().startsWith('tz') ? '300' : '0' // taken from eztz
|
|
1187
|
+
;
|
|
1188
|
+
switch (operationRequest.kind) {
|
|
1189
|
+
// TODO: Handle if the dApp already provides a reveal operation
|
|
1190
|
+
case TezosOperationType_1.TezosOperationType.REVEAL:
|
|
1191
|
+
revealOperation = operationRequest;
|
|
1192
|
+
if (!revealOperation.public_key) {
|
|
1193
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "public_key" was not defined');
|
|
1194
|
+
}
|
|
1195
|
+
revealOperation.source = (_b = revealOperation.source) !== null && _b !== void 0 ? _b : address;
|
|
1196
|
+
revealOperation.counter = (_c = revealOperation.counter) !== null && _c !== void 0 ? _c : defaultCounter;
|
|
1197
|
+
revealOperation.fee = (_d = revealOperation.fee) !== null && _d !== void 0 ? _d : defaultFee;
|
|
1198
|
+
revealOperation.gas_limit = (_e = revealOperation.gas_limit) !== null && _e !== void 0 ? _e : defaultGasLimit;
|
|
1199
|
+
revealOperation.storage_limit = (_f = revealOperation.storage_limit) !== null && _f !== void 0 ? _f : defaultStorageLimit;
|
|
1200
|
+
return [2 /*return*/, revealOperation];
|
|
1201
|
+
case TezosOperationType_1.TezosOperationType.DELEGATION:
|
|
1202
|
+
delegationOperation = operationRequest;
|
|
1203
|
+
// The delegate property is optional, so we don't have any mandatory properties to check for
|
|
1204
|
+
delegationOperation.source = (_g = delegationOperation.source) !== null && _g !== void 0 ? _g : address;
|
|
1205
|
+
delegationOperation.counter = (_h = delegationOperation.counter) !== null && _h !== void 0 ? _h : defaultCounter;
|
|
1206
|
+
delegationOperation.fee = (_j = delegationOperation.fee) !== null && _j !== void 0 ? _j : defaultFee;
|
|
1207
|
+
delegationOperation.gas_limit = (_k = delegationOperation.gas_limit) !== null && _k !== void 0 ? _k : defaultGasLimit;
|
|
1208
|
+
delegationOperation.storage_limit = (_l = delegationOperation.storage_limit) !== null && _l !== void 0 ? _l : defaultStorageLimit;
|
|
1209
|
+
return [2 /*return*/, delegationOperation];
|
|
1210
|
+
case TezosOperationType_1.TezosOperationType.TRANSACTION:
|
|
1211
|
+
transactionOperation = operationRequest;
|
|
1212
|
+
if (!transactionOperation.amount) {
|
|
1213
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "amount" was not defined');
|
|
1214
|
+
}
|
|
1215
|
+
if (!transactionOperation.destination) {
|
|
1216
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "destination" was not defined');
|
|
1217
|
+
}
|
|
1218
|
+
transactionOperation.source = (_m = transactionOperation.source) !== null && _m !== void 0 ? _m : address;
|
|
1219
|
+
transactionOperation.counter = (_o = transactionOperation.counter) !== null && _o !== void 0 ? _o : defaultCounter;
|
|
1220
|
+
transactionOperation.fee = (_p = transactionOperation.fee) !== null && _p !== void 0 ? _p : defaultFee;
|
|
1221
|
+
transactionOperation.gas_limit = (_q = transactionOperation.gas_limit) !== null && _q !== void 0 ? _q : GAS_LIMIT_PLACEHOLDER;
|
|
1222
|
+
transactionOperation.storage_limit = (_r = transactionOperation.storage_limit) !== null && _r !== void 0 ? _r : STORAGE_LIMIT_PLACEHOLDER;
|
|
1223
|
+
return [2 /*return*/, transactionOperation];
|
|
1224
|
+
case TezosOperationType_1.TezosOperationType.ORIGINATION:
|
|
1225
|
+
originationOperation = operationRequest;
|
|
1226
|
+
if (!originationOperation.balance) {
|
|
1227
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "balance" was not defined');
|
|
1228
|
+
}
|
|
1229
|
+
if (!originationOperation.script) {
|
|
1230
|
+
throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "script" was not defined');
|
|
1231
|
+
}
|
|
1232
|
+
originationOperation.source = (_s = originationOperation.source) !== null && _s !== void 0 ? _s : address;
|
|
1233
|
+
originationOperation.counter = (_t = originationOperation.counter) !== null && _t !== void 0 ? _t : defaultCounter;
|
|
1234
|
+
originationOperation.fee = (_u = originationOperation.fee) !== null && _u !== void 0 ? _u : defaultFee;
|
|
1235
|
+
originationOperation.gas_limit = (_v = originationOperation.gas_limit) !== null && _v !== void 0 ? _v : GAS_LIMIT_PLACEHOLDER;
|
|
1236
|
+
originationOperation.storage_limit = (_w = originationOperation.storage_limit) !== null && _w !== void 0 ? _w : STORAGE_LIMIT_PLACEHOLDER;
|
|
1237
|
+
return [2 /*return*/, originationOperation];
|
|
1238
|
+
case TezosOperationType_1.TezosOperationType.ENDORSEMENT:
|
|
1239
|
+
case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION:
|
|
1240
|
+
case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE:
|
|
1241
|
+
case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE:
|
|
1242
|
+
case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT:
|
|
1243
|
+
case TezosOperationType_1.TezosOperationType.PROPOSALS:
|
|
1244
|
+
case TezosOperationType_1.TezosOperationType.BALLOT:
|
|
1245
|
+
// Do not change anything
|
|
1246
|
+
return [2 /*return*/, operationRequest];
|
|
1247
|
+
default:
|
|
1248
|
+
(0, assert_1.assertNever)(operationRequest.kind);
|
|
1249
|
+
throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, "unsupported operation type \"".concat(JSON.stringify(operationRequest.kind), "\""));
|
|
1250
|
+
}
|
|
1251
|
+
return [2 /*return*/];
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
}); });
|
|
1255
|
+
_d = (_c = operations.push).apply;
|
|
1256
|
+
_e = [operations];
|
|
1257
|
+
return [4 /*yield*/, Promise.all(operationPromises)];
|
|
1258
|
+
case 5:
|
|
1259
|
+
_d.apply(_c, _e.concat([(_f.sent())]));
|
|
1260
|
+
tezosWrappedOperation = {
|
|
1261
|
+
branch: branch,
|
|
1262
|
+
contents: operations
|
|
1263
|
+
};
|
|
1264
|
+
return [4 /*yield*/, this.estimateAndReplaceLimitsAndFee(tezosWrappedOperation, overrideParameters)];
|
|
1265
|
+
case 6: return [2 /*return*/, _f.sent()];
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
});
|
|
1269
|
+
};
|
|
1270
|
+
TezosProtocol.prototype.estimateAndReplaceLimitsAndFee = function (tezosWrappedOperation, overrideParameters, startingCounter) {
|
|
1271
|
+
if (overrideParameters === void 0) { overrideParameters = true; }
|
|
1272
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1273
|
+
var fakeSignature, opKinds, contents, block, body, forgedOperation, gasLimitTotal, response, fee, nonRevealOperations, feePerOperation_1;
|
|
1274
|
+
return __generator(this, function (_a) {
|
|
1275
|
+
switch (_a.label) {
|
|
1276
|
+
case 0:
|
|
1277
|
+
fakeSignature = 'sigUHx32f9wesZ1n2BWpixXz4AQaZggEtchaQNHYGRCoWNAXx45WGW2ua3apUUUAGMLPwAU41QoaFCzVSL61VaessLg4YbbP';
|
|
1278
|
+
opKinds = [
|
|
1279
|
+
TezosOperationType_1.TezosOperationType.TRANSACTION,
|
|
1280
|
+
TezosOperationType_1.TezosOperationType.REVEAL,
|
|
1281
|
+
TezosOperationType_1.TezosOperationType.ORIGINATION,
|
|
1282
|
+
TezosOperationType_1.TezosOperationType.DELEGATION
|
|
1283
|
+
];
|
|
1284
|
+
contents = tezosWrappedOperation.contents.map(function (operation, i) {
|
|
1285
|
+
if (!opKinds.includes(operation.kind)) {
|
|
1286
|
+
return operation;
|
|
1287
|
+
}
|
|
1288
|
+
var op = operation;
|
|
1289
|
+
var gasValue = new bignumber_1.default(MAX_GAS_PER_BLOCK).dividedToIntegerBy(tezosWrappedOperation.contents.length);
|
|
1290
|
+
var gas_limit = new bignumber_1.default(GAS_LIMIT_PLACEHOLDER).gt(gasValue) ? gasValue : GAS_LIMIT_PLACEHOLDER;
|
|
1291
|
+
var counter = startingCounter ? startingCounter.plus(i).toString() : op.counter;
|
|
1292
|
+
return __assign(__assign({}, operation), { gas_limit: gas_limit, counter: counter });
|
|
1293
|
+
});
|
|
1294
|
+
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/header"))];
|
|
1295
|
+
case 1:
|
|
1296
|
+
block = (_a.sent()).data;
|
|
1297
|
+
body = {
|
|
1298
|
+
chain_id: block.chain_id,
|
|
1299
|
+
operation: {
|
|
1300
|
+
branch: tezosWrappedOperation.branch,
|
|
1301
|
+
contents: contents,
|
|
1302
|
+
signature: fakeSignature // signature will not be checked, so it is ok to always use this one
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
|
|
1306
|
+
case 2:
|
|
1307
|
+
forgedOperation = _a.sent();
|
|
1308
|
+
gasLimitTotal = 0;
|
|
1309
|
+
return [4 /*yield*/, index_1.default
|
|
1310
|
+
.post("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/helpers/scripts/run_operation"), body, {
|
|
1311
|
+
headers: { 'Content-Type': 'application/json' }
|
|
1312
|
+
})
|
|
1313
|
+
.catch(function (runOperationError) {
|
|
1314
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, runOperationError);
|
|
1315
|
+
})];
|
|
1316
|
+
case 3:
|
|
1317
|
+
response = _a.sent();
|
|
1318
|
+
if (tezosWrappedOperation.contents.length !== response.data.contents.length) {
|
|
1319
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "Run Operation did not return same number of operations. Locally we have ".concat(tezosWrappedOperation.contents.length, ", but got back ").concat(response.data.contents.length));
|
|
1320
|
+
}
|
|
1321
|
+
tezosWrappedOperation.contents.forEach(function (content, i) {
|
|
1322
|
+
var metadata = response.data.contents[i].metadata;
|
|
1323
|
+
if (metadata.operation_result) {
|
|
1324
|
+
var operation = content;
|
|
1325
|
+
var result = metadata.operation_result;
|
|
1326
|
+
var gasLimit_1 = 0;
|
|
1327
|
+
var storageLimit_1 = 0;
|
|
1328
|
+
// If there are internal operations, we first add gas and storage used of internal operations
|
|
1329
|
+
if (metadata.internal_operation_results) {
|
|
1330
|
+
metadata.internal_operation_results.forEach(function (internalOperation) {
|
|
1331
|
+
if (internalOperation === null || internalOperation === void 0 ? void 0 : internalOperation.result) {
|
|
1332
|
+
if (internalOperation.result.errors) {
|
|
1333
|
+
throw new index_4.TransactionError(coinlib_error_1.Domain.TEZOS, 'An internal operation produced an error', internalOperation.result.errors);
|
|
1334
|
+
}
|
|
1335
|
+
gasLimit_1 += Math.ceil(Number(internalOperation.result.consumed_milligas) / 1000);
|
|
1336
|
+
if (internalOperation.result.paid_storage_size_diff) {
|
|
1337
|
+
storageLimit_1 += Number(internalOperation.result.paid_storage_size_diff);
|
|
1338
|
+
}
|
|
1339
|
+
if (internalOperation.result.originated_contracts) {
|
|
1340
|
+
storageLimit_1 += internalOperation.result.originated_contracts.length * 257;
|
|
1341
|
+
}
|
|
1342
|
+
if (internalOperation.result.allocated_destination_contract) {
|
|
1343
|
+
storageLimit_1 += 257;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
if (result.errors) {
|
|
1349
|
+
throw new index_4.TransactionError(coinlib_error_1.Domain.TEZOS, 'The operation produced an error', result.errors);
|
|
1350
|
+
}
|
|
1351
|
+
// Add gas and storage used by operation
|
|
1352
|
+
gasLimit_1 += Math.ceil(Number(result.consumed_milligas) / 1000);
|
|
1353
|
+
if (result.paid_storage_size_diff) {
|
|
1354
|
+
storageLimit_1 += Number(result.paid_storage_size_diff);
|
|
1355
|
+
}
|
|
1356
|
+
if (result.originated_contracts) {
|
|
1357
|
+
storageLimit_1 += result.originated_contracts.length * 257;
|
|
1358
|
+
}
|
|
1359
|
+
if (result.allocated_destination_contract) {
|
|
1360
|
+
storageLimit_1 += 257;
|
|
1361
|
+
}
|
|
1362
|
+
// in prepareTransactionsFromPublicKey() we invoke this method with overrideParameters = false
|
|
1363
|
+
if ((operation.gas_limit && overrideParameters) || operation.gas_limit === GAS_LIMIT_PLACEHOLDER) {
|
|
1364
|
+
;
|
|
1365
|
+
operation.gas_limit = gasLimit_1.toString();
|
|
1366
|
+
}
|
|
1367
|
+
if ((operation.storage_limit && overrideParameters) || operation.storage_limit === STORAGE_LIMIT_PLACEHOLDER) {
|
|
1368
|
+
;
|
|
1369
|
+
operation.storage_limit = storageLimit_1.toString();
|
|
1370
|
+
}
|
|
1371
|
+
gasLimitTotal += gasLimit_1;
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
if (overrideParameters || tezosWrappedOperation.contents.some(function (operation) { return (operation === null || operation === void 0 ? void 0 : operation.fee) === FEE_PLACEHOLDER; })) {
|
|
1375
|
+
fee = MINIMAL_FEE +
|
|
1376
|
+
MINIMAL_FEE_PER_BYTE * Math.ceil((forgedOperation.length + 128) / 2) + // 128 is the length of a hex signature
|
|
1377
|
+
MINIMAL_FEE_PER_GAS_UNIT * gasLimitTotal +
|
|
1378
|
+
100 // add 100 for safety
|
|
1379
|
+
;
|
|
1380
|
+
nonRevealOperations = tezosWrappedOperation.contents.filter(function (operation) { return operation.kind !== 'reveal'; });
|
|
1381
|
+
feePerOperation_1 = Math.ceil(fee / nonRevealOperations.length);
|
|
1382
|
+
tezosWrappedOperation.contents.forEach(function (operation) {
|
|
1383
|
+
if (operation.fee && operation.kind !== 'reveal') {
|
|
1384
|
+
;
|
|
1385
|
+
operation.fee = feePerOperation_1.toString();
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
return [2 /*return*/, tezosWrappedOperation];
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
});
|
|
1393
|
+
};
|
|
1394
|
+
TezosProtocol.prototype.getDelegationInfo = function (delegatedAddress, fetchExtraInfo) {
|
|
1395
|
+
if (fetchExtraInfo === void 0) { fetchExtraInfo = true; }
|
|
1396
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1397
|
+
var data, delegatedOpLevel, delegatedDate, recentTransactionData;
|
|
1398
|
+
return __generator(this, function (_a) {
|
|
1399
|
+
switch (_a.label) {
|
|
1400
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(delegatedAddress))];
|
|
1401
|
+
case 1:
|
|
1402
|
+
data = (_a.sent()).data;
|
|
1403
|
+
if (!(data.delegate && fetchExtraInfo)) return [3 /*break*/, 3];
|
|
1404
|
+
return [4 /*yield*/, this.options.network.extras.indexerClient.getDelegationInfo(delegatedAddress)];
|
|
1405
|
+
case 2:
|
|
1406
|
+
recentTransactionData = _a.sent();
|
|
1407
|
+
if (recentTransactionData) {
|
|
1408
|
+
delegatedDate = recentTransactionData.date;
|
|
1409
|
+
delegatedOpLevel = recentTransactionData.level;
|
|
1410
|
+
}
|
|
1411
|
+
_a.label = 3;
|
|
1412
|
+
case 3: return [2 /*return*/, {
|
|
1413
|
+
isDelegated: data.delegate ? true : false,
|
|
1414
|
+
value: data.delegate,
|
|
1415
|
+
delegatedDate: delegatedDate,
|
|
1416
|
+
delegatedOpLevel: delegatedOpLevel
|
|
1417
|
+
}];
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
});
|
|
1421
|
+
};
|
|
1422
|
+
TezosProtocol.prototype.bakerInfo = function (tzAddress) {
|
|
1423
|
+
var _a, _b, _c, _d;
|
|
1424
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1425
|
+
var results, tzBalance, delegatedBalance, stakingBalance, selfBond, stakingCapacity, bakerInfo;
|
|
1426
|
+
return __generator(this, function (_e) {
|
|
1427
|
+
switch (_e.label) {
|
|
1428
|
+
case 0:
|
|
1429
|
+
if (!tzAddress ||
|
|
1430
|
+
!(tzAddress.toLowerCase().startsWith('tz1') ||
|
|
1431
|
+
tzAddress.toLowerCase().startsWith('tz2') ||
|
|
1432
|
+
tzAddress.toLowerCase().startsWith('tz3') ||
|
|
1433
|
+
tzAddress.toLowerCase().startsWith('tz4'))) {
|
|
1434
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'non tz-address supplied');
|
|
1435
|
+
}
|
|
1436
|
+
return [4 /*yield*/, Promise.all([
|
|
1437
|
+
index_1.default
|
|
1438
|
+
.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(tzAddress, "/balance"))
|
|
1439
|
+
.catch(function (_error) { return undefined; }),
|
|
1440
|
+
index_1.default
|
|
1441
|
+
.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(tzAddress, "/full_balance"))
|
|
1442
|
+
.catch(function (_error) { return undefined; }),
|
|
1443
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(tzAddress, "/delegated_balance")),
|
|
1444
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(tzAddress, "/staking_balance"))
|
|
1445
|
+
]).catch(function (error) {
|
|
1446
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
1447
|
+
})];
|
|
1448
|
+
case 1:
|
|
1449
|
+
results = _e.sent();
|
|
1450
|
+
tzBalance = new bignumber_1.default((_b = ((_a = results[0]) !== null && _a !== void 0 ? _a : results[1])) === null || _b === void 0 ? void 0 : _b.data);
|
|
1451
|
+
delegatedBalance = new bignumber_1.default((_c = results[2]) === null || _c === void 0 ? void 0 : _c.data);
|
|
1452
|
+
stakingBalance = new bignumber_1.default((_d = results[3]) === null || _d === void 0 ? void 0 : _d.data);
|
|
1453
|
+
selfBond = stakingBalance.minus(delegatedBalance);
|
|
1454
|
+
stakingCapacity = stakingBalance.div(selfBond.div(SELF_BOND_REQUIREMENT));
|
|
1455
|
+
bakerInfo = {
|
|
1456
|
+
balance: tzBalance,
|
|
1457
|
+
delegatedBalance: delegatedBalance,
|
|
1458
|
+
stakingBalance: stakingBalance,
|
|
1459
|
+
selfBond: selfBond,
|
|
1460
|
+
bakerCapacity: stakingBalance.div(stakingCapacity),
|
|
1461
|
+
bakerUsage: stakingCapacity
|
|
1462
|
+
};
|
|
1463
|
+
return [2 /*return*/, bakerInfo];
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
};
|
|
1468
|
+
TezosProtocol.prototype.undelegate = function (publicKey) {
|
|
1469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1470
|
+
return __generator(this, function (_a) {
|
|
1471
|
+
return [2 /*return*/, this.delegate(publicKey)];
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
};
|
|
1475
|
+
TezosProtocol.prototype.delegate = function (publicKey, delegate) {
|
|
1476
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1477
|
+
var counter, branch, operations, tzAddress, results, accountManager, _a, _b, balance, _c, fee, delegationOperation, tezosWrappedOperation, binaryTx, error_4;
|
|
1478
|
+
return __generator(this, function (_d) {
|
|
1479
|
+
switch (_d.label) {
|
|
1480
|
+
case 0:
|
|
1481
|
+
counter = new bignumber_1.default(1);
|
|
1482
|
+
branch = '';
|
|
1483
|
+
operations = [];
|
|
1484
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(publicKey).then(function (address) { return address.address; })];
|
|
1485
|
+
case 1:
|
|
1486
|
+
tzAddress = _d.sent();
|
|
1487
|
+
return [4 /*yield*/, Promise.all([
|
|
1488
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(tzAddress, "/counter")),
|
|
1489
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head~2/hash")),
|
|
1490
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(tzAddress, "/manager_key"))
|
|
1491
|
+
]).catch(function (error) {
|
|
1492
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
1493
|
+
})];
|
|
1494
|
+
case 2:
|
|
1495
|
+
results = _d.sent();
|
|
1496
|
+
counter = new bignumber_1.default(results[0].data).plus(1);
|
|
1497
|
+
branch = results[1].data;
|
|
1498
|
+
accountManager = results[2].data;
|
|
1499
|
+
if (!!accountManager) return [3 /*break*/, 4];
|
|
1500
|
+
_b = (_a = operations).push;
|
|
1501
|
+
return [4 /*yield*/, this.createRevealOperation(counter, publicKey, tzAddress)];
|
|
1502
|
+
case 3:
|
|
1503
|
+
_b.apply(_a, [_d.sent()]);
|
|
1504
|
+
counter = counter.plus(1);
|
|
1505
|
+
_d.label = 4;
|
|
1506
|
+
case 4:
|
|
1507
|
+
_c = bignumber_1.default.bind;
|
|
1508
|
+
return [4 /*yield*/, this.getBalanceOfAddresses([tzAddress])];
|
|
1509
|
+
case 5:
|
|
1510
|
+
balance = new (_c.apply(bignumber_1.default, [void 0, _d.sent()]))();
|
|
1511
|
+
fee = new bignumber_1.default(1420);
|
|
1512
|
+
if (balance.isLessThan(fee)) {
|
|
1513
|
+
throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'not enough balance');
|
|
1514
|
+
}
|
|
1515
|
+
delegationOperation = {
|
|
1516
|
+
kind: TezosOperationType_1.TezosOperationType.DELEGATION,
|
|
1517
|
+
source: tzAddress,
|
|
1518
|
+
fee: fee.toFixed(),
|
|
1519
|
+
counter: counter.toFixed(),
|
|
1520
|
+
gas_limit: '10000',
|
|
1521
|
+
storage_limit: '0',
|
|
1522
|
+
delegate: Array.isArray(delegate) ? delegate[0] : delegate
|
|
1523
|
+
};
|
|
1524
|
+
operations.push(delegationOperation);
|
|
1525
|
+
_d.label = 6;
|
|
1526
|
+
case 6:
|
|
1527
|
+
_d.trys.push([6, 8, , 9]);
|
|
1528
|
+
tezosWrappedOperation = {
|
|
1529
|
+
branch: branch,
|
|
1530
|
+
contents: operations
|
|
1531
|
+
};
|
|
1532
|
+
return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
|
|
1533
|
+
case 7:
|
|
1534
|
+
binaryTx = _d.sent();
|
|
1535
|
+
return [2 /*return*/, { binaryTransaction: binaryTx }];
|
|
1536
|
+
case 8:
|
|
1537
|
+
error_4 = _d.sent();
|
|
1538
|
+
throw new index_4.OperationFailedError(coinlib_error_1.Domain.TEZOS, "Forging Tezos TX failed with ".concat(JSON.stringify(error_4.message)));
|
|
1539
|
+
case 9: return [2 /*return*/];
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
});
|
|
1543
|
+
};
|
|
1544
|
+
TezosProtocol.prototype.getAmountUsedByPreviousOperations = function (operations) {
|
|
1545
|
+
var amountUsed = new bignumber_1.default(0);
|
|
1546
|
+
operations.forEach(function (operation) {
|
|
980
1547
|
switch (operation.kind) {
|
|
981
1548
|
case TezosOperationType_1.TezosOperationType.REVEAL:
|
|
982
|
-
|
|
1549
|
+
var revealOperation = operation;
|
|
983
1550
|
amountUsed = amountUsed.plus(revealOperation.fee);
|
|
984
1551
|
break;
|
|
985
1552
|
case TezosOperationType_1.TezosOperationType.ORIGINATION:
|
|
986
|
-
|
|
1553
|
+
var originationOperation = operation;
|
|
987
1554
|
amountUsed = amountUsed.plus(originationOperation.fee);
|
|
988
1555
|
amountUsed = amountUsed.plus(originationOperation.balance);
|
|
989
1556
|
break;
|
|
990
1557
|
case TezosOperationType_1.TezosOperationType.DELEGATION:
|
|
991
|
-
|
|
1558
|
+
var delegationOperation = operation;
|
|
992
1559
|
amountUsed = amountUsed.plus(delegationOperation.fee);
|
|
993
1560
|
break;
|
|
994
1561
|
case TezosOperationType_1.TezosOperationType.TRANSACTION:
|
|
995
|
-
|
|
1562
|
+
var spendOperation = operation;
|
|
996
1563
|
amountUsed = amountUsed.plus(spendOperation.fee);
|
|
997
1564
|
amountUsed = amountUsed.plus(spendOperation.amount);
|
|
998
1565
|
break;
|
|
@@ -1007,91 +1574,177 @@ class TezosProtocol extends NonExtendedProtocol_1.NonExtendedProtocol {
|
|
|
1007
1574
|
default:
|
|
1008
1575
|
// Exhaustive switch
|
|
1009
1576
|
(0, assert_1.assertNever)(operation.kind);
|
|
1010
|
-
throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS,
|
|
1577
|
+
throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, "operation type not supported ".concat(JSON.stringify(operation.kind)));
|
|
1011
1578
|
}
|
|
1012
1579
|
});
|
|
1013
1580
|
return amountUsed;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1581
|
+
};
|
|
1582
|
+
TezosProtocol.prototype.broadcastTransaction = function (rawTransaction) {
|
|
1583
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1584
|
+
var payload, injectionResponse;
|
|
1585
|
+
return __generator(this, function (_a) {
|
|
1586
|
+
switch (_a.label) {
|
|
1587
|
+
case 0:
|
|
1588
|
+
payload = rawTransaction;
|
|
1589
|
+
return [4 /*yield*/, index_1.default
|
|
1590
|
+
.post("".concat(this.options.network.rpcUrl, "/injection/operation?chain=main"), JSON.stringify(payload), {
|
|
1591
|
+
headers: { 'content-type': 'application/json' }
|
|
1592
|
+
})
|
|
1593
|
+
.catch(function (error) {
|
|
1594
|
+
throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
|
|
1595
|
+
})
|
|
1596
|
+
// returns hash if successful
|
|
1597
|
+
];
|
|
1598
|
+
case 1:
|
|
1599
|
+
injectionResponse = (_a.sent()).data;
|
|
1600
|
+
// returns hash if successful
|
|
1601
|
+
return [2 /*return*/, injectionResponse];
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
};
|
|
1606
|
+
TezosProtocol.prototype.checkAndRemovePrefixToHex = function (base58CheckEncodedPayload, tezosPrefix) {
|
|
1607
|
+
var prefixHex = Buffer.from(tezosPrefix).toString('hex');
|
|
1608
|
+
var payload = bs58check.decode(base58CheckEncodedPayload).toString('hex');
|
|
1030
1609
|
if (payload.startsWith(prefixHex)) {
|
|
1031
1610
|
return payload.substring(tezosPrefix.length * 2);
|
|
1032
1611
|
}
|
|
1033
1612
|
else {
|
|
1034
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS,
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
async unforgeSignedTezosWrappedOperation(hexString) {
|
|
1038
|
-
if (hexString.length <= 128) {
|
|
1039
|
-
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Not a valid signed transaction');
|
|
1613
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "payload did not match prefix: ".concat(prefixHex));
|
|
1040
1614
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
return
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1615
|
+
};
|
|
1616
|
+
TezosProtocol.prototype.unforgeSignedTezosWrappedOperation = function (hexString) {
|
|
1617
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1618
|
+
return __generator(this, function (_a) {
|
|
1619
|
+
if (hexString.length <= 128) {
|
|
1620
|
+
throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Not a valid signed transaction');
|
|
1621
|
+
}
|
|
1622
|
+
return [2 /*return*/, this.unforgeUnsignedTezosWrappedOperation(hexString.substring(0, hexString.length - 128))];
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1625
|
+
};
|
|
1626
|
+
TezosProtocol.prototype.unforgeUnsignedTezosWrappedOperation = function (hexString) {
|
|
1627
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1628
|
+
return __generator(this, function (_a) {
|
|
1629
|
+
return [2 /*return*/, taquito_local_forging_1.localForger.parse(hexString)];
|
|
1630
|
+
});
|
|
1631
|
+
});
|
|
1632
|
+
};
|
|
1633
|
+
TezosProtocol.prototype.forgeTezosOperation = function (tezosWrappedOperation) {
|
|
1634
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1635
|
+
return __generator(this, function (_a) {
|
|
1636
|
+
return [2 /*return*/, taquito_local_forging_1.localForger.forge(tezosWrappedOperation)];
|
|
1637
|
+
});
|
|
1638
|
+
});
|
|
1639
|
+
};
|
|
1640
|
+
TezosProtocol.prototype.createRevealOperation = function (counter, publicKey, address, fee) {
|
|
1641
|
+
if (fee === void 0) { fee = this.revealFee.toFixed(); }
|
|
1642
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1643
|
+
var operation;
|
|
1644
|
+
return __generator(this, function (_a) {
|
|
1645
|
+
operation = {
|
|
1646
|
+
kind: TezosOperationType_1.TezosOperationType.REVEAL,
|
|
1647
|
+
fee: fee,
|
|
1648
|
+
gas_limit: '10000',
|
|
1649
|
+
storage_limit: '0',
|
|
1650
|
+
counter: counter.toFixed(),
|
|
1651
|
+
public_key: bs58check.encode(Buffer.concat([TezosUtils_1.TezosUtils.tezosPrefixes.edpk, Buffer.from(publicKey, 'hex')])),
|
|
1652
|
+
source: address
|
|
1653
|
+
};
|
|
1654
|
+
return [2 /*return*/, operation];
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
};
|
|
1658
|
+
TezosProtocol.prototype.getTezosVotingInfo = function (blockHash) {
|
|
1659
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1660
|
+
var response;
|
|
1661
|
+
return __generator(this, function (_a) {
|
|
1662
|
+
switch (_a.label) {
|
|
1663
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/").concat(blockHash, "/votes/listings"))];
|
|
1664
|
+
case 1:
|
|
1665
|
+
response = _a.sent();
|
|
1666
|
+
return [2 /*return*/, response.data];
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
};
|
|
1671
|
+
TezosProtocol.prototype.fetchCurrentCycle = function () {
|
|
1672
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1673
|
+
var headMetadata, currentCycle;
|
|
1674
|
+
return __generator(this, function (_a) {
|
|
1675
|
+
switch (_a.label) {
|
|
1676
|
+
case 0: return [4 /*yield*/, this.fetchBlockMetadata('head')];
|
|
1677
|
+
case 1:
|
|
1678
|
+
headMetadata = _a.sent();
|
|
1679
|
+
currentCycle = headMetadata.level_info.cycle;
|
|
1680
|
+
return [2 /*return*/, currentCycle];
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
});
|
|
1684
|
+
};
|
|
1685
|
+
TezosProtocol.prototype.fetchBlockMetadata = function (block) {
|
|
1686
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1687
|
+
var result;
|
|
1688
|
+
return __generator(this, function (_a) {
|
|
1689
|
+
switch (_a.label) {
|
|
1690
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/").concat(block, "/metadata"))];
|
|
1691
|
+
case 1:
|
|
1692
|
+
result = _a.sent();
|
|
1693
|
+
return [2 /*return*/, result.data];
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
});
|
|
1697
|
+
};
|
|
1698
|
+
TezosProtocol.prototype.signMessage = function (message, keypair) {
|
|
1699
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1700
|
+
return __generator(this, function (_a) {
|
|
1701
|
+
return [2 /*return*/, this.cryptoClient.signMessage(message, keypair)];
|
|
1702
|
+
});
|
|
1703
|
+
});
|
|
1704
|
+
};
|
|
1705
|
+
TezosProtocol.prototype.verifyMessage = function (message, signature, publicKey) {
|
|
1706
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1707
|
+
return __generator(this, function (_a) {
|
|
1708
|
+
return [2 /*return*/, this.cryptoClient.verifyMessage(message, signature, publicKey)];
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
TezosProtocol.prototype.encryptAsymmetric = function (message, publicKey) {
|
|
1713
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1714
|
+
return __generator(this, function (_a) {
|
|
1715
|
+
return [2 /*return*/, this.cryptoClient.encryptAsymmetric(message, publicKey)];
|
|
1716
|
+
});
|
|
1717
|
+
});
|
|
1718
|
+
};
|
|
1719
|
+
TezosProtocol.prototype.decryptAsymmetric = function (message, keypair) {
|
|
1720
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1721
|
+
return __generator(this, function (_a) {
|
|
1722
|
+
return [2 /*return*/, this.cryptoClient.decryptAsymmetric(message, keypair)];
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1725
|
+
};
|
|
1726
|
+
TezosProtocol.prototype.encryptAES = function (message, privateKey) {
|
|
1727
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1728
|
+
return __generator(this, function (_a) {
|
|
1729
|
+
return [2 /*return*/, this.cryptoClient.encryptAES(message, privateKey)];
|
|
1730
|
+
});
|
|
1731
|
+
});
|
|
1732
|
+
};
|
|
1733
|
+
TezosProtocol.prototype.decryptAES = function (message, privateKey) {
|
|
1734
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1735
|
+
return __generator(this, function (_a) {
|
|
1736
|
+
return [2 /*return*/, this.cryptoClient.decryptAES(message, privateKey)];
|
|
1737
|
+
});
|
|
1738
|
+
});
|
|
1739
|
+
};
|
|
1740
|
+
TezosProtocol.prototype.getTransactionStatuses = function (transactionHashes) {
|
|
1741
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1742
|
+
return __generator(this, function (_a) {
|
|
1743
|
+
throw new Error('Method not implemented.');
|
|
1744
|
+
});
|
|
1745
|
+
});
|
|
1746
|
+
};
|
|
1747
|
+
return TezosProtocol;
|
|
1748
|
+
}(NonExtendedProtocol_1.NonExtendedProtocol));
|
|
1096
1749
|
exports.TezosProtocol = TezosProtocol;
|
|
1097
1750
|
//# sourceMappingURL=TezosProtocol.js.map
|