@airgap/tezos 0.13.16-beta.1 → 0.13.16-beta.3
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +5 -5
- package/v0/protocol/TezosProtocol.js +4 -1
- package/v0/protocol/TezosProtocol.js.map +1 -1
- package/v1/block-explorer/factory.d.ts +2 -2
- package/v1/block-explorer/factory.js +4 -4
- package/v1/block-explorer/factory.js.map +1 -1
- package/v1/contract/TezosContract.js +1 -1
- package/v1/contract/TezosContract.js.map +1 -1
- package/v1/domains/TezosDomains.d.ts +20 -0
- package/v1/domains/TezosDomains.js +309 -0
- package/v1/domains/TezosDomains.js.map +1 -0
- package/v1/index.d.ts +23 -4
- package/v1/index.js +23 -1
- package/v1/index.js.map +1 -1
- package/v1/indexer/factory.d.ts +2 -2
- package/v1/indexer/factory.js +4 -4
- package/v1/indexer/factory.js.map +1 -1
- package/v1/module/TezosModule.d.ts +6 -3
- package/v1/module/TezosModule.js +10 -6
- package/v1/module/TezosModule.js.map +1 -1
- package/v1/protocol/TezosProtocol.d.ts +32 -7
- package/v1/protocol/TezosProtocol.js +350 -19
- package/v1/protocol/TezosProtocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA1Protocol.d.ts +16 -3
- package/v1/protocol/fa/TezosFA1Protocol.js +19 -6
- package/v1/protocol/fa/TezosFA1Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA1p2Protocol.d.ts +15 -2
- package/v1/protocol/fa/TezosFA1p2Protocol.js +11 -5
- package/v1/protocol/fa/TezosFA1p2Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFA2Protocol.d.ts +21 -6
- package/v1/protocol/fa/TezosFA2Protocol.js +34 -6
- package/v1/protocol/fa/TezosFA2Protocol.js.map +1 -1
- package/v1/protocol/fa/TezosFAProtocol.d.ts +10 -7
- package/v1/protocol/fa/TezosFAProtocol.js +21 -7
- package/v1/protocol/fa/TezosFAProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/BTCTezProtocol.js +1 -1
- package/v1/protocol/fa/tokens/BTCTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/CTezProtocol.js +1 -1
- package/v1/protocol/fa/tokens/CTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/DogamiProtocol.js +1 -1
- package/v1/protocol/fa/tokens/DogamiProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/ETHTezProtocol.js +1 -1
- package/v1/protocol/fa/tokens/ETHTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/KolibriUSDProtocol.js +1 -1
- package/v1/protocol/fa/tokens/KolibriUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/PlentyProtocol.js +1 -1
- package/v1/protocol/fa/tokens/PlentyProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/QuipuswapProtocol.js +1 -1
- package/v1/protocol/fa/tokens/QuipuswapProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/SiriusProtocol.js +1 -1
- package/v1/protocol/fa/tokens/SiriusProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/StakerProtocol.js +1 -1
- package/v1/protocol/fa/tokens/StakerProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/TetherUSDProtocol.js +1 -1
- package/v1/protocol/fa/tokens/TetherUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/TzBTCProtocol.js +1 -1
- package/v1/protocol/fa/tokens/TzBTCProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UBTCProtocol.js +1 -1
- package/v1/protocol/fa/tokens/UBTCProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UDEFIProtocol.js +1 -1
- package/v1/protocol/fa/tokens/UDEFIProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/USDTezProtocol.js +1 -1
- package/v1/protocol/fa/tokens/USDTezProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/UUSDProtocol.js +1 -1
- package/v1/protocol/fa/tokens/UUSDProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/WrapProtocol.js +1 -1
- package/v1/protocol/fa/tokens/WrapProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/WrappedTezosProtocol.js +1 -1
- package/v1/protocol/fa/tokens/WrappedTezosProtocol.js.map +1 -1
- package/v1/protocol/fa/tokens/YouProtocol.js +1 -1
- package/v1/protocol/fa/tokens/YouProtocol.js.map +1 -1
- package/v1/protocol/kt/TezosKtProtocol.js +27 -14
- package/v1/protocol/kt/TezosKtProtocol.js.map +1 -1
- package/v1/protocol/sapling/TezosSaplingProtocol.d.ts +16 -13
- package/v1/protocol/sapling/TezosSaplingProtocol.js +12 -1
- package/v1/protocol/sapling/TezosSaplingProtocol.js.map +1 -1
- package/v1/protocol/sapling/TezosShieldedTezProtocol.js +2 -2
- package/v1/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +42 -146
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/types/block-explorer.d.ts +1 -6
- package/v1/types/domains/TezosDomainsRecord.d.ts +8 -0
- package/v1/types/domains/TezosDomainsRecord.js +3 -0
- package/v1/types/domains/TezosDomainsRecord.js.map +1 -0
- package/v1/types/domains/TezosDomainsReverseRecord.d.ts +5 -0
- package/v1/types/domains/TezosDomainsReverseRecord.js +3 -0
- package/v1/types/domains/TezosDomainsReverseRecord.js.map +1 -0
- package/v1/types/indexer.d.ts +1 -6
- package/v1/types/protocol.d.ts +11 -5
- package/v1/types/staking/BakerDetails.d.ts +10 -0
- package/v1/types/staking/BakerDetails.js +3 -0
- package/v1/types/staking/BakerDetails.js.map +1 -0
- package/v1/types/staking/TezosDelegatorAction.d.ts +5 -0
- package/v1/types/staking/TezosDelegatorAction.js +10 -0
- package/v1/types/staking/TezosDelegatorAction.js.map +1 -0
- package/v1/utils/pack.js +3 -4
- package/v1/utils/pack.js.map +1 -1
- package/v1/utils/protocol/instance.d.ts +19 -0
- package/v1/utils/protocol/instance.js +49 -0
- package/v1/utils/protocol/instance.js.map +1 -0
- package/v1/utils/protocol/tezos/TezosAccountant.d.ts +2 -1
- package/v1/utils/protocol/tezos/TezosAccountant.js.map +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DelegateeDetails, DelegationDetails, DelegatorDetails } from '@airgap/coinlib-core';
|
|
2
|
+
import { Address, AirGapProtocol, AirGapTransaction, AirGapTransactionsWithCursor, Amount, Balance, CryptoDerivative, FeeDefaults, KeyPair, ProtocolAccountMetadata, ProtocolMetadata, ProtocolUnitsMetadata, PublicKey, RecursivePartial, SecretKey, Signature, TransactionFullConfiguration, TransactionDetails, TransactionSimpleConfiguration } from '@airgap/module-kit';
|
|
3
|
+
import { AirGapDelegateProtocol } from '@airgap/module-kit/internal';
|
|
2
4
|
import { TezosCryptoConfiguration } from '../types/crypto';
|
|
3
5
|
import { TezosOperation } from '../types/operations/kinds/TezosOperation';
|
|
4
6
|
import { TezosWrappedOperation } from '../types/operations/TezosWrappedOperation';
|
|
5
7
|
import { TezosProtocolNetwork, TezosProtocolOptions, TezosUnits } from '../types/protocol';
|
|
8
|
+
import { BakerDetails } from '../types/staking/BakerDetails';
|
|
6
9
|
import { TezosSignedTransaction, TezosTransactionCursor, TezosUnsignedTransaction } from '../types/transaction';
|
|
7
10
|
export interface TezosProtocol extends AirGapProtocol<{
|
|
8
11
|
AddressResult: Address;
|
|
@@ -13,19 +16,24 @@ export interface TezosProtocol extends AirGapProtocol<{
|
|
|
13
16
|
UnsignedTransaction: TezosUnsignedTransaction;
|
|
14
17
|
SignedTransaction: TezosSignedTransaction;
|
|
15
18
|
TransactionCursor: TezosTransactionCursor;
|
|
16
|
-
}, 'Crypto', 'FetchDataForAddress'
|
|
19
|
+
}, 'Crypto', 'FetchDataForAddress'>, AirGapDelegateProtocol {
|
|
20
|
+
isTezosProtocol: true;
|
|
21
|
+
getMinCycleDuration(): Promise<number>;
|
|
22
|
+
getDetailsFromWrappedOperation(wrappedOperation: TezosWrappedOperation): Promise<AirGapTransaction<TezosUnits, TezosUnits>[]>;
|
|
17
23
|
forgeOperation(wrappedOperation: TezosWrappedOperation): Promise<string>;
|
|
18
24
|
unforgeOperation(forged: string, type?: (TezosSignedTransaction | TezosUnsignedTransaction)['type']): Promise<TezosWrappedOperation>;
|
|
19
25
|
getOperationFeeDefaults(publicKey: PublicKey, operations: TezosOperation[]): Promise<FeeDefaults<TezosUnits>>;
|
|
20
26
|
prepareOperations(publicKey: PublicKey, operationRequests: TezosOperation[], overrideParameters?: boolean): Promise<TezosWrappedOperation>;
|
|
21
|
-
prepareTransactionsWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?:
|
|
27
|
+
prepareTransactionsWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?: TransactionFullConfiguration<TezosUnits> & {
|
|
22
28
|
operationsPerGroup?: number;
|
|
23
29
|
}): Promise<TezosUnsignedTransaction[]>;
|
|
30
|
+
bakerDetails(address: string | undefined): Promise<BakerDetails>;
|
|
24
31
|
}
|
|
25
32
|
export declare const TEZOS_UNITS: ProtocolUnitsMetadata<TezosUnits>;
|
|
26
33
|
export declare const TEZOS_DERIVATION_PATH: string;
|
|
27
34
|
export declare const TEZOS_ACCOUNT_METADATA: ProtocolAccountMetadata;
|
|
28
35
|
export declare class TezosProtocolImpl implements TezosProtocol {
|
|
36
|
+
readonly isTezosProtocol: true;
|
|
29
37
|
private readonly options;
|
|
30
38
|
private readonly forger;
|
|
31
39
|
private readonly accountant;
|
|
@@ -53,20 +61,37 @@ export declare class TezosProtocolImpl implements TezosProtocol {
|
|
|
53
61
|
getTransactionsForAddress(address: string, limit: number, cursor?: TezosTransactionCursor): Promise<AirGapTransactionsWithCursor<TezosTransactionCursor, TezosUnits, TezosUnits>>;
|
|
54
62
|
getBalanceOfPublicKey(publicKey: PublicKey): Promise<Balance<TezosUnits>>;
|
|
55
63
|
getBalanceOfAddress(address: string): Promise<Balance<TezosUnits>>;
|
|
56
|
-
getTransactionMaxAmountWithPublicKey(publicKey: PublicKey, to: string[], configuration?:
|
|
64
|
+
getTransactionMaxAmountWithPublicKey(publicKey: PublicKey, to: string[], configuration?: TransactionFullConfiguration<TezosUnits>): Promise<Amount<TezosUnits>>;
|
|
57
65
|
private getTansactionMaxAmountWithBalance;
|
|
58
|
-
getTransactionFeeWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[]): Promise<FeeDefaults<TezosUnits>>;
|
|
66
|
+
getTransactionFeeWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], _configuration?: TransactionSimpleConfiguration): Promise<FeeDefaults<TezosUnits>>;
|
|
59
67
|
getOperationFeeDefaults(publicKey: PublicKey, operations: TezosOperation[]): Promise<FeeDefaults<TezosUnits>>;
|
|
60
|
-
prepareTransactionWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?:
|
|
68
|
+
prepareTransactionWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?: TransactionFullConfiguration<TezosUnits>): Promise<TezosUnsignedTransaction>;
|
|
61
69
|
broadcastTransaction(transaction: TezosSignedTransaction): Promise<string>;
|
|
70
|
+
getDefaultDelegatee(): Promise<string>;
|
|
71
|
+
getCurrentDelegateesForPublicKey(publicKey: PublicKey): Promise<string[]>;
|
|
72
|
+
getCurrentDelegateesForAddress(address: string): Promise<string[]>;
|
|
73
|
+
getDelegateeDetails(address: string): Promise<DelegateeDetails>;
|
|
74
|
+
isPublicKeyDelegating(publicKey: PublicKey): Promise<boolean>;
|
|
75
|
+
isAddressDelegating(address: string): Promise<boolean>;
|
|
76
|
+
getDelegatorDetailsFromPublicKey(publicKey: PublicKey): Promise<DelegatorDetails>;
|
|
77
|
+
getDelegatorDetailsFromAddress(address: string): Promise<DelegatorDetails>;
|
|
78
|
+
getDelegationDetailsFromPublicKey(publicKey: PublicKey, delegatees: string[]): Promise<DelegationDetails>;
|
|
79
|
+
getDelegationDetailsFromAddress(address: string, delegatees: string[]): Promise<DelegationDetails>;
|
|
80
|
+
private getDelegatorDetails;
|
|
81
|
+
prepareDelegatorActionFromPublicKey(publicKey: PublicKey, type: any, data?: any): Promise<any[]>;
|
|
82
|
+
undelegate(publicKey: PublicKey): Promise<TezosUnsignedTransaction>;
|
|
83
|
+
delegate(publicKey: PublicKey, delegate?: string | string[]): Promise<TezosUnsignedTransaction>;
|
|
84
|
+
getMinCycleDuration(): Promise<number>;
|
|
85
|
+
getDetailsFromWrappedOperation(wrappedOperation: TezosWrappedOperation): Promise<AirGapTransaction<TezosUnits, TezosUnits>[]>;
|
|
62
86
|
forgeOperation(wrappedOperation: TezosWrappedOperation): Promise<string>;
|
|
63
87
|
unforgeOperation(forged: string, type?: (TezosSignedTransaction | TezosUnsignedTransaction)['type']): Promise<TezosWrappedOperation>;
|
|
64
|
-
prepareTransactionsWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?:
|
|
88
|
+
prepareTransactionsWithPublicKey(publicKey: PublicKey, details: TransactionDetails<TezosUnits>[], configuration?: TransactionFullConfiguration<TezosUnits> & {
|
|
65
89
|
operationsPerGroup?: number;
|
|
66
90
|
}): Promise<TezosUnsignedTransaction[]>;
|
|
67
91
|
prepareOperations(publicKey: PublicKey, operationRequests: TezosOperation[], overrideParameters?: boolean): Promise<TezosWrappedOperation>;
|
|
68
92
|
private estimateAndReplaceLimitsAndFee;
|
|
69
93
|
private createTransactionOperations;
|
|
94
|
+
bakerDetails(address: string | undefined): Promise<BakerDetails>;
|
|
70
95
|
}
|
|
71
96
|
export declare function createTezosProtocol(options?: RecursivePartial<TezosProtocolOptions>): TezosProtocol;
|
|
72
97
|
export declare const TEZOS_MAINNET_PROTOCOL_NETWORK: TezosProtocolNetwork;
|
|
@@ -61,6 +61,7 @@ var TezosAddress_1 = require("../data/TezosAddress");
|
|
|
61
61
|
var factory_1 = require("../indexer/factory");
|
|
62
62
|
var network_1 = require("../types/network");
|
|
63
63
|
var TezosOperationType_1 = require("../types/operations/TezosOperationType");
|
|
64
|
+
var TezosDelegatorAction_1 = require("../types/staking/TezosDelegatorAction");
|
|
64
65
|
var key_1 = require("../utils/key");
|
|
65
66
|
var operations_1 = require("../utils/operations");
|
|
66
67
|
var TezosAccountant_1 = require("../utils/protocol/tezos/TezosAccountant");
|
|
@@ -69,12 +70,14 @@ var signature_1 = require("../utils/signature");
|
|
|
69
70
|
// Implementation
|
|
70
71
|
var MAX_OPERATIONS_PER_GROUP = 200;
|
|
71
72
|
var MAX_GAS_PER_BLOCK = 5200000;
|
|
73
|
+
var MIN_CYCLE_DURATION = 4096 * 60 * 1000; // ms
|
|
72
74
|
var GAS_LIMIT_PLACEHOLDER = '1040000';
|
|
73
75
|
var STORAGE_LIMIT_PLACEHOLDER = '60000';
|
|
74
76
|
var FEE_PLACEHOLDER = '0';
|
|
75
77
|
var MINIMAL_FEE = 100;
|
|
76
78
|
var MINIMAL_FEE_PER_GAS_UNIT = 0.1;
|
|
77
79
|
var MINIMAL_FEE_PER_BYTE = 1;
|
|
80
|
+
var SELF_BOND_REQUIREMENT = 0.0825; // 8.25%
|
|
78
81
|
exports.TEZOS_UNITS = {
|
|
79
82
|
tez: {
|
|
80
83
|
symbol: { value: 'XTZ', market: 'xtz' },
|
|
@@ -100,6 +103,7 @@ exports.TEZOS_ACCOUNT_METADATA = {
|
|
|
100
103
|
};
|
|
101
104
|
var TezosProtocolImpl = /** @class */ (function () {
|
|
102
105
|
function TezosProtocolImpl(options) {
|
|
106
|
+
this.isTezosProtocol = true;
|
|
103
107
|
// Common
|
|
104
108
|
this.units = exports.TEZOS_UNITS;
|
|
105
109
|
this.feeDefaults = {
|
|
@@ -124,7 +128,7 @@ var TezosProtocolImpl = /** @class */ (function () {
|
|
|
124
128
|
this.options = createTezosProtocolOptions(options.network);
|
|
125
129
|
this.forger = new TezosForger_1.TezosForger();
|
|
126
130
|
this.accountant = new TezosAccountant_1.TezosAccountant(this.forger, this.options.network);
|
|
127
|
-
this.indexerClient = (0, factory_1.createTezosIndexerClient)(this.options.network.
|
|
131
|
+
this.indexerClient = (0, factory_1.createTezosIndexerClient)(this.options.network.indexerType, this.options.network.indexerApi);
|
|
128
132
|
this.cryptoClient = new TezosCryptoClient_1.TezosCryptoClient();
|
|
129
133
|
}
|
|
130
134
|
TezosProtocolImpl.prototype.getMetadata = function () {
|
|
@@ -384,7 +388,7 @@ var TezosProtocolImpl = /** @class */ (function () {
|
|
|
384
388
|
});
|
|
385
389
|
});
|
|
386
390
|
};
|
|
387
|
-
TezosProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details) {
|
|
391
|
+
TezosProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, _configuration) {
|
|
388
392
|
return __awaiter(this, void 0, void 0, function () {
|
|
389
393
|
var operations, i, recipient, transaction;
|
|
390
394
|
return __generator(this, function (_a) {
|
|
@@ -482,7 +486,298 @@ var TezosProtocolImpl = /** @class */ (function () {
|
|
|
482
486
|
});
|
|
483
487
|
});
|
|
484
488
|
};
|
|
489
|
+
// Staking
|
|
490
|
+
TezosProtocolImpl.prototype.getDefaultDelegatee = function () {
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
var activeBakers;
|
|
493
|
+
return __generator(this, function (_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates?active"))];
|
|
496
|
+
case 1:
|
|
497
|
+
activeBakers = (_a.sent()).data;
|
|
498
|
+
return [2 /*return*/, activeBakers[0] || ''];
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
TezosProtocolImpl.prototype.getCurrentDelegateesForPublicKey = function (publicKey) {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
+
var address;
|
|
506
|
+
return __generator(this, function (_a) {
|
|
507
|
+
switch (_a.label) {
|
|
508
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
509
|
+
case 1:
|
|
510
|
+
address = _a.sent();
|
|
511
|
+
return [2 /*return*/, this.getCurrentDelegateesForAddress(address)];
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
TezosProtocolImpl.prototype.getCurrentDelegateesForAddress = function (address) {
|
|
517
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
518
|
+
var data;
|
|
519
|
+
return __generator(this, function (_a) {
|
|
520
|
+
switch (_a.label) {
|
|
521
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))];
|
|
522
|
+
case 1:
|
|
523
|
+
data = (_a.sent()).data;
|
|
524
|
+
return [2 /*return*/, data.delegate ? [data.delegate] : []];
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
TezosProtocolImpl.prototype.getDelegateeDetails = function (address) {
|
|
530
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
531
|
+
var response, isBakingActive;
|
|
532
|
+
return __generator(this, function (_a) {
|
|
533
|
+
switch (_a.label) {
|
|
534
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/deactivated"))];
|
|
535
|
+
case 1:
|
|
536
|
+
response = _a.sent();
|
|
537
|
+
isBakingActive = !response.data;
|
|
538
|
+
return [2 /*return*/, {
|
|
539
|
+
status: isBakingActive ? 'Active' : 'Inactive',
|
|
540
|
+
address: address
|
|
541
|
+
}];
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
TezosProtocolImpl.prototype.isPublicKeyDelegating = function (publicKey) {
|
|
547
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
548
|
+
var address;
|
|
549
|
+
return __generator(this, function (_a) {
|
|
550
|
+
switch (_a.label) {
|
|
551
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
552
|
+
case 1:
|
|
553
|
+
address = _a.sent();
|
|
554
|
+
return [2 /*return*/, this.isAddressDelegating(address)];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
};
|
|
559
|
+
TezosProtocolImpl.prototype.isAddressDelegating = function (address) {
|
|
560
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
561
|
+
var data;
|
|
562
|
+
return __generator(this, function (_a) {
|
|
563
|
+
switch (_a.label) {
|
|
564
|
+
case 0: return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))];
|
|
565
|
+
case 1:
|
|
566
|
+
data = (_a.sent()).data;
|
|
567
|
+
return [2 /*return*/, !!data.delegate];
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
TezosProtocolImpl.prototype.getDelegatorDetailsFromPublicKey = function (publicKey) {
|
|
573
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
574
|
+
var address;
|
|
575
|
+
return __generator(this, function (_a) {
|
|
576
|
+
switch (_a.label) {
|
|
577
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
578
|
+
case 1:
|
|
579
|
+
address = _a.sent();
|
|
580
|
+
return [2 /*return*/, this.getDelegatorDetailsFromAddress(address)];
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
TezosProtocolImpl.prototype.getDelegatorDetailsFromAddress = function (address) {
|
|
586
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
587
|
+
return __generator(this, function (_a) {
|
|
588
|
+
return [2 /*return*/, this.getDelegatorDetails(address)];
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
TezosProtocolImpl.prototype.getDelegationDetailsFromPublicKey = function (publicKey, delegatees) {
|
|
593
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
594
|
+
var address;
|
|
595
|
+
return __generator(this, function (_a) {
|
|
596
|
+
switch (_a.label) {
|
|
597
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
598
|
+
case 1:
|
|
599
|
+
address = _a.sent();
|
|
600
|
+
return [2 /*return*/, this.getDelegationDetailsFromAddress(address, delegatees)];
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
TezosProtocolImpl.prototype.getDelegationDetailsFromAddress = function (address, delegatees) {
|
|
606
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
607
|
+
var bakerAddress, results, delegatorDetails, bakerDetails;
|
|
608
|
+
return __generator(this, function (_a) {
|
|
609
|
+
switch (_a.label) {
|
|
610
|
+
case 0:
|
|
611
|
+
if (delegatees.length > 1) {
|
|
612
|
+
return [2 /*return*/, Promise.reject('Multiple delegation is not supported.')];
|
|
613
|
+
}
|
|
614
|
+
bakerAddress = delegatees[0];
|
|
615
|
+
return [4 /*yield*/, Promise.all([this.getDelegatorDetails(address, bakerAddress), this.getDelegateeDetails(bakerAddress)])];
|
|
616
|
+
case 1:
|
|
617
|
+
results = _a.sent();
|
|
618
|
+
delegatorDetails = results[0];
|
|
619
|
+
bakerDetails = results[1];
|
|
620
|
+
return [2 /*return*/, {
|
|
621
|
+
delegator: delegatorDetails,
|
|
622
|
+
delegatees: [bakerDetails]
|
|
623
|
+
}];
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
TezosProtocolImpl.prototype.getDelegatorDetails = function (address, bakerAddress) {
|
|
629
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
630
|
+
var results, accountDetails, balance, isDelegating, availableActions;
|
|
631
|
+
return __generator(this, function (_a) {
|
|
632
|
+
switch (_a.label) {
|
|
633
|
+
case 0: return [4 /*yield*/, Promise.all([index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(address))])];
|
|
634
|
+
case 1:
|
|
635
|
+
results = _a.sent();
|
|
636
|
+
accountDetails = results[0].data;
|
|
637
|
+
balance = accountDetails.balance;
|
|
638
|
+
isDelegating = !!accountDetails.delegate;
|
|
639
|
+
availableActions = [];
|
|
640
|
+
if (!isDelegating) {
|
|
641
|
+
availableActions.push({
|
|
642
|
+
type: TezosDelegatorAction_1.TezosDelegatorAction.DELEGATE,
|
|
643
|
+
args: ['delegate']
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
else if (!bakerAddress || accountDetails.delegate === bakerAddress) {
|
|
647
|
+
availableActions.push({
|
|
648
|
+
type: TezosDelegatorAction_1.TezosDelegatorAction.UNDELEGATE
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
availableActions.push({
|
|
653
|
+
type: TezosDelegatorAction_1.TezosDelegatorAction.CHANGE_BAKER,
|
|
654
|
+
args: ['delegate']
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
return [2 /*return*/, {
|
|
658
|
+
address: address,
|
|
659
|
+
balance: balance,
|
|
660
|
+
delegatees: [accountDetails.delegate],
|
|
661
|
+
availableActions: availableActions
|
|
662
|
+
}];
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
};
|
|
667
|
+
TezosProtocolImpl.prototype.prepareDelegatorActionFromPublicKey = function (publicKey, type, data) {
|
|
668
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
669
|
+
var _a;
|
|
670
|
+
return __generator(this, function (_b) {
|
|
671
|
+
switch (_b.label) {
|
|
672
|
+
case 0:
|
|
673
|
+
_a = type;
|
|
674
|
+
switch (_a) {
|
|
675
|
+
case TezosDelegatorAction_1.TezosDelegatorAction.DELEGATE: return [3 /*break*/, 1];
|
|
676
|
+
case TezosDelegatorAction_1.TezosDelegatorAction.CHANGE_BAKER: return [3 /*break*/, 1];
|
|
677
|
+
case TezosDelegatorAction_1.TezosDelegatorAction.UNDELEGATE: return [3 /*break*/, 3];
|
|
678
|
+
}
|
|
679
|
+
return [3 /*break*/, 5];
|
|
680
|
+
case 1:
|
|
681
|
+
if (!data || !data.delegate) {
|
|
682
|
+
return [2 /*return*/, Promise.reject("Invalid arguments passed for ".concat(type, " action, delegate is missing."))];
|
|
683
|
+
}
|
|
684
|
+
return [4 /*yield*/, this.delegate(publicKey, data.delegate)];
|
|
685
|
+
case 2: return [2 /*return*/, [_b.sent()]];
|
|
686
|
+
case 3: return [4 /*yield*/, this.undelegate(publicKey)];
|
|
687
|
+
case 4: return [2 /*return*/, [_b.sent()]];
|
|
688
|
+
case 5: return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
};
|
|
693
|
+
TezosProtocolImpl.prototype.undelegate = function (publicKey) {
|
|
694
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
695
|
+
return __generator(this, function (_a) {
|
|
696
|
+
return [2 /*return*/, this.delegate(publicKey)];
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
TezosProtocolImpl.prototype.delegate = function (publicKey, delegate) {
|
|
701
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
702
|
+
var counter, branch, operations, tzAddress, results, accountManager, balance, totalBalance, fee, delegationOperation, tezosWrappedOperation, binary, error_3;
|
|
703
|
+
return __generator(this, function (_a) {
|
|
704
|
+
switch (_a.label) {
|
|
705
|
+
case 0:
|
|
706
|
+
counter = new bignumber_1.default(1);
|
|
707
|
+
branch = '';
|
|
708
|
+
operations = [];
|
|
709
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
710
|
+
case 1:
|
|
711
|
+
tzAddress = _a.sent();
|
|
712
|
+
return [4 /*yield*/, Promise.all([
|
|
713
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(tzAddress, "/counter")),
|
|
714
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head~2/hash")),
|
|
715
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/contracts/").concat(tzAddress, "/manager_key"))
|
|
716
|
+
]).catch(function (error) {
|
|
717
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.TEZOS, error);
|
|
718
|
+
})];
|
|
719
|
+
case 2:
|
|
720
|
+
results = _a.sent();
|
|
721
|
+
counter = new bignumber_1.default(results[0].data).plus(1);
|
|
722
|
+
branch = results[1].data;
|
|
723
|
+
accountManager = results[2].data;
|
|
724
|
+
// check if we have revealed the address already
|
|
725
|
+
if (!accountManager) {
|
|
726
|
+
operations.push((0, operations_1.createRevealOperation)(counter, publicKey, tzAddress));
|
|
727
|
+
counter = counter.plus(1);
|
|
728
|
+
}
|
|
729
|
+
return [4 /*yield*/, this.getBalanceOfAddress(tzAddress)];
|
|
730
|
+
case 3:
|
|
731
|
+
balance = _a.sent();
|
|
732
|
+
totalBalance = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.units).value);
|
|
733
|
+
fee = new bignumber_1.default(1420);
|
|
734
|
+
if (totalBalance.isLessThan(fee)) {
|
|
735
|
+
throw new errors_1.BalanceError(coinlib_core_1.Domain.TEZOS, 'not enough balance');
|
|
736
|
+
}
|
|
737
|
+
delegationOperation = {
|
|
738
|
+
kind: TezosOperationType_1.TezosOperationType.DELEGATION,
|
|
739
|
+
source: tzAddress,
|
|
740
|
+
fee: fee.toFixed(),
|
|
741
|
+
counter: counter.toFixed(),
|
|
742
|
+
gas_limit: '10000',
|
|
743
|
+
storage_limit: '0',
|
|
744
|
+
delegate: Array.isArray(delegate) ? delegate[0] : delegate
|
|
745
|
+
};
|
|
746
|
+
operations.push(delegationOperation);
|
|
747
|
+
_a.label = 4;
|
|
748
|
+
case 4:
|
|
749
|
+
_a.trys.push([4, 6, , 7]);
|
|
750
|
+
tezosWrappedOperation = {
|
|
751
|
+
branch: branch,
|
|
752
|
+
contents: operations
|
|
753
|
+
};
|
|
754
|
+
return [4 /*yield*/, this.forgeOperation(tezosWrappedOperation)];
|
|
755
|
+
case 5:
|
|
756
|
+
binary = _a.sent();
|
|
757
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({ binary: binary })];
|
|
758
|
+
case 6:
|
|
759
|
+
error_3 = _a.sent();
|
|
760
|
+
throw new errors_1.OperationFailedError(coinlib_core_1.Domain.TEZOS, "Forging Tezos TX failed with ".concat(JSON.stringify(error_3.message)));
|
|
761
|
+
case 7: return [2 /*return*/];
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
};
|
|
485
766
|
// Custom
|
|
767
|
+
TezosProtocolImpl.prototype.getMinCycleDuration = function () {
|
|
768
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
769
|
+
return __generator(this, function (_a) {
|
|
770
|
+
return [2 /*return*/, MIN_CYCLE_DURATION];
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
};
|
|
774
|
+
TezosProtocolImpl.prototype.getDetailsFromWrappedOperation = function (wrappedOperation) {
|
|
775
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
776
|
+
return __generator(this, function (_a) {
|
|
777
|
+
return [2 /*return*/, this.accountant.getDetailsFromWrappedOperation(wrappedOperation)];
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
};
|
|
486
781
|
TezosProtocolImpl.prototype.forgeOperation = function (wrappedOperation) {
|
|
487
782
|
return __awaiter(this, void 0, void 0, function () {
|
|
488
783
|
return __generator(this, function (_a) {
|
|
@@ -900,6 +1195,50 @@ var TezosProtocolImpl = /** @class */ (function () {
|
|
|
900
1195
|
});
|
|
901
1196
|
});
|
|
902
1197
|
};
|
|
1198
|
+
TezosProtocolImpl.prototype.bakerDetails = function (address) {
|
|
1199
|
+
var _a, _b, _c, _d;
|
|
1200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1201
|
+
var results, tzBalance, delegatedBalance, stakingBalance, selfBond, stakingCapacity, bakerDetails;
|
|
1202
|
+
return __generator(this, function (_e) {
|
|
1203
|
+
switch (_e.label) {
|
|
1204
|
+
case 0:
|
|
1205
|
+
if (!address ||
|
|
1206
|
+
!(address.toLowerCase().startsWith('tz1') ||
|
|
1207
|
+
address.toLowerCase().startsWith('tz2') ||
|
|
1208
|
+
address.toLowerCase().startsWith('tz3') ||
|
|
1209
|
+
address.toLowerCase().startsWith('tz4'))) {
|
|
1210
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.TEZOS, 'non tz-address supplied');
|
|
1211
|
+
}
|
|
1212
|
+
return [4 /*yield*/, Promise.all([
|
|
1213
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/balance")).catch(function (_error) { return undefined; }),
|
|
1214
|
+
index_1.default
|
|
1215
|
+
.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/full_balance"))
|
|
1216
|
+
.catch(function (_error) { return undefined; }),
|
|
1217
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/delegated_balance")),
|
|
1218
|
+
index_1.default.get("".concat(this.options.network.rpcUrl, "/chains/main/blocks/head/context/delegates/").concat(address, "/staking_balance"))
|
|
1219
|
+
]).catch(function (error) {
|
|
1220
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.TEZOS, error);
|
|
1221
|
+
})];
|
|
1222
|
+
case 1:
|
|
1223
|
+
results = _e.sent();
|
|
1224
|
+
tzBalance = new bignumber_1.default((_b = ((_a = results[0]) !== null && _a !== void 0 ? _a : results[1])) === null || _b === void 0 ? void 0 : _b.data);
|
|
1225
|
+
delegatedBalance = new bignumber_1.default((_c = results[2]) === null || _c === void 0 ? void 0 : _c.data);
|
|
1226
|
+
stakingBalance = new bignumber_1.default((_d = results[3]) === null || _d === void 0 ? void 0 : _d.data);
|
|
1227
|
+
selfBond = stakingBalance.minus(delegatedBalance);
|
|
1228
|
+
stakingCapacity = stakingBalance.div(selfBond.div(SELF_BOND_REQUIREMENT));
|
|
1229
|
+
bakerDetails = {
|
|
1230
|
+
balance: (0, module_kit_1.newAmount)(tzBalance, 'blockchain'),
|
|
1231
|
+
delegatedBalance: (0, module_kit_1.newAmount)(delegatedBalance, 'blockchain'),
|
|
1232
|
+
stakingBalance: (0, module_kit_1.newAmount)(stakingBalance, 'blockchain'),
|
|
1233
|
+
selfBond: (0, module_kit_1.newAmount)(selfBond, 'blockchain'),
|
|
1234
|
+
bakerCapacity: stakingBalance.div(stakingCapacity).toString(),
|
|
1235
|
+
bakerUsage: stakingCapacity.toString()
|
|
1236
|
+
};
|
|
1237
|
+
return [2 /*return*/, bakerDetails];
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
});
|
|
1241
|
+
};
|
|
903
1242
|
return TezosProtocolImpl;
|
|
904
1243
|
}());
|
|
905
1244
|
exports.TezosProtocolImpl = TezosProtocolImpl;
|
|
@@ -914,34 +1253,26 @@ exports.TEZOS_MAINNET_PROTOCOL_NETWORK = {
|
|
|
914
1253
|
type: 'mainnet',
|
|
915
1254
|
rpcUrl: 'https://tezos-node.prod.gke.papers.tech',
|
|
916
1255
|
network: network_1.TezosNetwork.MAINNET,
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
indexer: {
|
|
922
|
-
type: 'tzkt',
|
|
923
|
-
apiUrl: 'https://tezos-mainnet-indexer.prod.gke.papers.tech'
|
|
924
|
-
}
|
|
1256
|
+
blockExplorerUrl: 'https://tzkt.io',
|
|
1257
|
+
blockExplorerType: 'tzkt',
|
|
1258
|
+
indexerApi: 'https://tezos-mainnet-indexer.prod.gke.papers.tech',
|
|
1259
|
+
indexerType: 'tzkt'
|
|
925
1260
|
};
|
|
926
1261
|
exports.TEZOS_GHOSTNET_PROTOCOL_NETWORK = {
|
|
927
1262
|
name: 'Ghostnet',
|
|
928
1263
|
type: 'testnet',
|
|
929
1264
|
rpcUrl: 'https://tezos-ghostnet-node.prod.gke.papers.tech',
|
|
930
1265
|
network: network_1.TezosNetwork.GHOSTNET,
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
indexer: {
|
|
936
|
-
type: 'tzkt',
|
|
937
|
-
apiUrl: 'https://tezos-ghostnet-indexer.prod.gke.papers.tech'
|
|
938
|
-
}
|
|
1266
|
+
blockExplorerUrl: 'https://ghostnet.tzkt.io',
|
|
1267
|
+
blockExplorerType: 'tzkt',
|
|
1268
|
+
indexerApi: 'https://tezos-ghostnet-indexer.prod.gke.papers.tech',
|
|
1269
|
+
indexerType: 'tzkt'
|
|
939
1270
|
};
|
|
940
1271
|
var DEFAULT_TEZOS_PROTOCOL_NETWORK = exports.TEZOS_MAINNET_PROTOCOL_NETWORK;
|
|
941
1272
|
function createTezosProtocolOptions(network) {
|
|
942
1273
|
if (network === void 0) { network = {}; }
|
|
943
1274
|
return {
|
|
944
|
-
network: __assign(__assign(
|
|
1275
|
+
network: __assign(__assign({}, DEFAULT_TEZOS_PROTOCOL_NETWORK), network)
|
|
945
1276
|
};
|
|
946
1277
|
}
|
|
947
1278
|
exports.createTezosProtocolOptions = createTezosProtocolOptions;
|