@airgap/coinlib-core 0.13.6-beta.6 → 0.13.6-beta.7
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/airgap-coinlib-core.min.js +1126 -2542
- package/index.d.ts +2 -1
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/protocols/tezos/TezosProtocol.d.ts +0 -15
- package/protocols/tezos/TezosProtocol.js +17 -354
- package/protocols/tezos/TezosProtocol.js.map +1 -1
- package/protocols/tezos/TezosProtocolOptions.d.ts +4 -6
- package/protocols/tezos/TezosProtocolOptions.js +4 -18
- package/protocols/tezos/TezosProtocolOptions.js.map +1 -1
- package/protocols/tezos/contract/TezosContract.d.ts +9 -7
- package/protocols/tezos/contract/TezosContract.js +63 -84
- package/protocols/tezos/contract/TezosContract.js.map +1 -1
- package/protocols/tezos/contract/TezosContractEntrypoint.js +1 -1
- package/protocols/tezos/contract/TezosContractEntrypoint.js.map +1 -1
- package/protocols/tezos/domains/TezosDomains.d.ts +2 -2
- package/protocols/tezos/domains/TezosDomains.js +36 -27
- package/protocols/tezos/domains/TezosDomains.js.map +1 -1
- package/protocols/tezos/fa/TezosBTC.d.ts +0 -1
- package/protocols/tezos/fa/TezosBTC.js +1 -43
- package/protocols/tezos/fa/TezosBTC.js.map +1 -1
- package/protocols/tezos/fa/TezosETHtz.d.ts +0 -1
- package/protocols/tezos/fa/TezosETHtz.js +1 -40
- package/protocols/tezos/fa/TezosETHtz.js.map +1 -1
- package/protocols/tezos/fa/TezosFA2Protocol.d.ts +0 -3
- package/protocols/tezos/fa/TezosFA2Protocol.js +28 -102
- package/protocols/tezos/fa/TezosFA2Protocol.js.map +1 -1
- package/protocols/tezos/fa/TezosFAProtocol.d.ts +2 -6
- package/protocols/tezos/fa/TezosFAProtocol.js +29 -167
- package/protocols/tezos/fa/TezosFAProtocol.js.map +1 -1
- package/protocols/tezos/fa/TezosKolibriUSD.d.ts +0 -1
- package/protocols/tezos/fa/TezosKolibriUSD.js +1 -40
- package/protocols/tezos/fa/TezosKolibriUSD.js.map +1 -1
- package/protocols/tezos/fa/TezosStaker.js +1 -15
- package/protocols/tezos/fa/TezosStaker.js.map +1 -1
- package/protocols/tezos/fa/TezosUSD.d.ts +0 -1
- package/protocols/tezos/fa/TezosUSD.js +1 -38
- package/protocols/tezos/fa/TezosUSD.js.map +1 -1
- package/protocols/tezos/fa/TezosWrapped.js +1 -36
- package/protocols/tezos/fa/TezosWrapped.js.map +1 -1
- package/protocols/tezos/indexerClient/TezosIndexerClient.d.ts +25 -0
- package/protocols/tezos/indexerClient/TezosIndexerClient.js +245 -0
- package/protocols/tezos/indexerClient/TezosIndexerClient.js.map +1 -0
- package/protocols/tezos/indexerClient/TezosProtocolIndexerClient.d.ts +26 -0
- package/protocols/tezos/indexerClient/TezosProtocolIndexerClient.js +3 -0
- package/protocols/tezos/indexerClient/TezosProtocolIndexerClient.js.map +1 -0
- package/protocols/tezos/kt/TezosKtProtocol.js +3 -33
- package/protocols/tezos/kt/TezosKtProtocol.js.map +1 -1
- package/protocols/tezos/sapling/TezosSaplingProtocolOptions.js +5 -1
- package/protocols/tezos/sapling/TezosSaplingProtocolOptions.js.map +1 -1
- package/protocols/tezos/types/TezosTransactionCursor.d.ts +1 -1
- package/protocols/tezos/types/contract/BigMap.d.ts +7 -0
- package/protocols/tezos/types/contract/{BigMapResult.js → BigMap.js} +1 -1
- package/protocols/tezos/types/contract/BigMap.js.map +1 -0
- package/protocols/tezos/types/contract/BigMapEnrtyFilter.d.ts +5 -0
- package/protocols/tezos/types/contract/{ConseilPredicate.js → BigMapEnrtyFilter.js} +1 -1
- package/protocols/tezos/types/contract/BigMapEnrtyFilter.js.map +1 -0
- package/protocols/tezos/types/contract/BigMapEntry.d.ts +7 -0
- package/protocols/tezos/types/contract/{BigMapPredicate.js → BigMapEntry.js} +1 -1
- package/protocols/tezos/types/contract/BigMapEntry.js.map +1 -0
- package/protocols/tezos/types/contract/BigMapRequest.d.ts +5 -4
- package/protocols/tezos/types/micheline/MichelineNodeUtils.js +1 -1
- package/protocols/tezos/types/micheline/MichelineNodeUtils.js.map +1 -1
- package/protocols/tezos/types/michelson/MichelsonTypeMeta.js +2 -2
- package/protocols/tezos/types/michelson/MichelsonTypeMeta.js.map +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonMap.js +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonMap.js.map +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonOption.js +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonOption.js.map +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonOr.js +2 -2
- package/protocols/tezos/types/michelson/generics/MichelsonOr.js.map +1 -1
- package/protocols/tezos/types/michelson/generics/MichelsonPair.js +2 -2
- package/protocols/tezos/types/michelson/generics/MichelsonPair.js.map +1 -1
- package/protocols/tezos/types/michelson/primitives/MichelsonBool.js +1 -1
- package/protocols/tezos/types/michelson/primitives/MichelsonBool.js.map +1 -1
- package/protocols/tezos/types/michelson/primitives/MichelsonUnit.js +1 -1
- package/protocols/tezos/types/michelson/primitives/MichelsonUnit.js.map +1 -1
- package/protocols/tezos/types/utils.d.ts +4 -1
- package/protocols/tezos/types/utils.js +7 -3
- package/protocols/tezos/types/utils.js.map +1 -1
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation005.d.ts +0 -14
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation005.js +0 -164
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation005.js.map +0 -1
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation006.d.ts +0 -9
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation006.js +0 -51
- package/protocols/tezos/rewardcalculation/TezosRewardCalculation006.js.map +0 -1
- package/protocols/tezos/rewardcalculation/TezosRewardCalculationDefault.d.ts +0 -36
- package/protocols/tezos/rewardcalculation/TezosRewardCalculationDefault.js +0 -642
- package/protocols/tezos/rewardcalculation/TezosRewardCalculationDefault.js.map +0 -1
- package/protocols/tezos/types/contract/BigMapPredicate.d.ts +0 -4
- package/protocols/tezos/types/contract/BigMapPredicate.js.map +0 -1
- package/protocols/tezos/types/contract/BigMapResult.d.ts +0 -6
- package/protocols/tezos/types/contract/BigMapResult.js.map +0 -1
- package/protocols/tezos/types/contract/ConseilPredicate.d.ts +0 -7
- package/protocols/tezos/types/contract/ConseilPredicate.js.map +0 -1
|
@@ -1,642 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.TezosRewardsCalculationDefault = void 0;
|
|
43
|
-
var index_1 = __importDefault(require("../../../dependencies/src/axios-0.19.0/index"));
|
|
44
|
-
var bignumber_1 = __importDefault(require("../../../dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
45
|
-
var errors_1 = require("../../../errors");
|
|
46
|
-
var coinlib_error_1 = require("../../../errors/coinlib-error");
|
|
47
|
-
var TezosRewardsCalculationDefault = /** @class */ (function () {
|
|
48
|
-
function TezosRewardsCalculationDefault(protocol) {
|
|
49
|
-
this.protocol = protocol;
|
|
50
|
-
this.blockLevelFieldNameMap = new Map();
|
|
51
|
-
this.tezosNodeConstants = {};
|
|
52
|
-
}
|
|
53
|
-
TezosRewardsCalculationDefault.prototype.getConstants = function (currentLevel, useHead) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var _a;
|
|
56
|
-
return __generator(this, function (_b) {
|
|
57
|
-
switch (_b.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
_a = this;
|
|
60
|
-
return [4 /*yield*/, index_1.default.get(this.protocol.jsonRPCAPI + "/chains/main/blocks/" + (useHead ? 'head' : currentLevel) + "/context/constants")];
|
|
61
|
-
case 1:
|
|
62
|
-
_a.tezosNodeConstants = (_b.sent()).data;
|
|
63
|
-
return [2 /*return*/];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
TezosRewardsCalculationDefault.prototype.calculateRewards = function (bakerAddress, cycle, breakdownRewards, currentCycleIn) {
|
|
69
|
-
if (breakdownRewards === void 0) { breakdownRewards = true; }
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var currentCycle, _a, calculatingLevel, computedRewards, snapshotLevel, bakerInfo, stakingBalance;
|
|
72
|
-
return __generator(this, function (_b) {
|
|
73
|
-
switch (_b.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
if (!(currentCycleIn !== null && currentCycleIn !== void 0)) return [3 /*break*/, 1];
|
|
76
|
-
_a = currentCycleIn;
|
|
77
|
-
return [3 /*break*/, 3];
|
|
78
|
-
case 1: return [4 /*yield*/, this.protocol.fetchCurrentCycle()];
|
|
79
|
-
case 2:
|
|
80
|
-
_a = (_b.sent());
|
|
81
|
-
_b.label = 3;
|
|
82
|
-
case 3:
|
|
83
|
-
currentCycle = _a;
|
|
84
|
-
calculatingLevel = this.protocol.cycleToBlockLevel(cycle);
|
|
85
|
-
return [4 /*yield*/, this.getConstants(calculatingLevel, currentCycle < cycle)];
|
|
86
|
-
case 4:
|
|
87
|
-
_b.sent();
|
|
88
|
-
if (!(cycle < currentCycle)) return [3 /*break*/, 6];
|
|
89
|
-
return [4 /*yield*/, this.calculatePastRewards(bakerAddress, cycle, breakdownRewards)];
|
|
90
|
-
case 5:
|
|
91
|
-
computedRewards = _b.sent();
|
|
92
|
-
return [3 /*break*/, 8];
|
|
93
|
-
case 6: return [4 /*yield*/, this.calculateFutureRewards(bakerAddress, cycle, currentCycle, breakdownRewards)];
|
|
94
|
-
case 7:
|
|
95
|
-
computedRewards = _b.sent();
|
|
96
|
-
_b.label = 8;
|
|
97
|
-
case 8: return [4 /*yield*/, this.computeSnapshotBlockLevel(Math.min(cycle, currentCycle))];
|
|
98
|
-
case 9:
|
|
99
|
-
snapshotLevel = _b.sent();
|
|
100
|
-
return [4 /*yield*/, this.fetchBakerInfo(bakerAddress, snapshotLevel).catch(function () {
|
|
101
|
-
return { staking_balance: '0', delegated_contracts: [] };
|
|
102
|
-
})];
|
|
103
|
-
case 10:
|
|
104
|
-
bakerInfo = _b.sent();
|
|
105
|
-
stakingBalance = new bignumber_1.default(bakerInfo.staking_balance);
|
|
106
|
-
return [2 /*return*/, {
|
|
107
|
-
baker: bakerAddress,
|
|
108
|
-
stakingBalance: stakingBalance.toFixed(),
|
|
109
|
-
bakingRewards: computedRewards.bakingRewards,
|
|
110
|
-
endorsingRewards: computedRewards.endorsingRewards,
|
|
111
|
-
bakingDeposits: computedRewards.bakingRewardsDetails
|
|
112
|
-
.map(function (detail) { return (detail && detail.deposit ? (detail.deposit ? parseInt(detail.deposit) : 0) : 0); })
|
|
113
|
-
.reduce(function (a, b) { return a + b; }, 0)
|
|
114
|
-
.toString(),
|
|
115
|
-
endorsingDeposits: computedRewards.endorsingRewardsDetails
|
|
116
|
-
.map(function (detail) { return (detail && detail.deposit ? (detail.deposit ? parseInt(detail.deposit) : 0) : 0); })
|
|
117
|
-
.reduce(function (a, b) { return a + b; }, 0)
|
|
118
|
-
.toString(),
|
|
119
|
-
cycle: cycle,
|
|
120
|
-
fees: computedRewards.fees,
|
|
121
|
-
totalRewards: computedRewards.totalRewards,
|
|
122
|
-
snapshotBlockLevel: snapshotLevel,
|
|
123
|
-
delegatedContracts: bakerInfo.delegated_contracts,
|
|
124
|
-
bakingRewardsDetails: computedRewards.bakingRewardsDetails,
|
|
125
|
-
endorsingRewardsDetails: computedRewards.endorsingRewardsDetails,
|
|
126
|
-
deposit: computedRewards.deposit,
|
|
127
|
-
endorsingRightsCount: computedRewards.endorsingRightsCount
|
|
128
|
-
}];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
TezosRewardsCalculationDefault.prototype.calculatePastRewards = function (bakerAddress, cycle, breakdownRewards) {
|
|
134
|
-
var _a;
|
|
135
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var computedBakingRewards, computedEndorsingRewards, fees, totalRewards, deposit, endorsingRightsCount, bakedBlocks, endorsingOperations, frozenBalance;
|
|
137
|
-
return __generator(this, function (_b) {
|
|
138
|
-
switch (_b.label) {
|
|
139
|
-
case 0:
|
|
140
|
-
computedBakingRewards = {
|
|
141
|
-
totalBakingRewards: '0',
|
|
142
|
-
rewardsDetails: []
|
|
143
|
-
};
|
|
144
|
-
computedEndorsingRewards = {
|
|
145
|
-
totalEndorsingRewards: '0',
|
|
146
|
-
rewardsDetails: []
|
|
147
|
-
};
|
|
148
|
-
fees = '0';
|
|
149
|
-
totalRewards = '0';
|
|
150
|
-
deposit = '0';
|
|
151
|
-
endorsingRightsCount = 0;
|
|
152
|
-
if (!breakdownRewards) return [3 /*break*/, 6];
|
|
153
|
-
return [4 /*yield*/, this.fetchBlocksForBaker(bakerAddress, cycle)];
|
|
154
|
-
case 1:
|
|
155
|
-
bakedBlocks = _b.sent();
|
|
156
|
-
if (!(bakedBlocks.length > 0)) return [3 /*break*/, 3];
|
|
157
|
-
return [4 /*yield*/, this.computeBakingRewards(bakedBlocks, false)];
|
|
158
|
-
case 2:
|
|
159
|
-
computedBakingRewards = _b.sent();
|
|
160
|
-
_b.label = 3;
|
|
161
|
-
case 3: return [4 /*yield*/, this.fetchEndorsementOperations(cycle, bakerAddress)];
|
|
162
|
-
case 4:
|
|
163
|
-
endorsingOperations = _b.sent();
|
|
164
|
-
return [4 /*yield*/, this.computeEndorsingRewards(endorsingOperations, false)];
|
|
165
|
-
case 5:
|
|
166
|
-
computedEndorsingRewards = _b.sent();
|
|
167
|
-
endorsingRightsCount = endorsingOperations.reduce(function (current, next) { return current + next.number_of_slots; }, 0);
|
|
168
|
-
_b.label = 6;
|
|
169
|
-
case 6: return [4 /*yield*/, this.fetchFrozenBalances(this.protocol.cycleToBlockLevel(cycle + 1), bakerAddress)];
|
|
170
|
-
case 7:
|
|
171
|
-
frozenBalance = (_b.sent()).find(function (fb) { return fb.cycle == cycle; });
|
|
172
|
-
if (frozenBalance) {
|
|
173
|
-
fees = frozenBalance.fees;
|
|
174
|
-
totalRewards = frozenBalance.rewards;
|
|
175
|
-
deposit = (_a = frozenBalance.deposit) !== null && _a !== void 0 ? _a : frozenBalance.deposits;
|
|
176
|
-
}
|
|
177
|
-
return [2 /*return*/, {
|
|
178
|
-
bakingRewards: computedBakingRewards.totalBakingRewards,
|
|
179
|
-
endorsingRewards: computedEndorsingRewards.totalEndorsingRewards,
|
|
180
|
-
totalRewards: totalRewards,
|
|
181
|
-
fees: fees,
|
|
182
|
-
bakingRewardsDetails: computedBakingRewards.rewardsDetails,
|
|
183
|
-
endorsingRewardsDetails: computedEndorsingRewards.rewardsDetails,
|
|
184
|
-
endorsingRightsCount: endorsingRightsCount,
|
|
185
|
-
deposit: deposit
|
|
186
|
-
}];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
TezosRewardsCalculationDefault.prototype.calculateFutureRewards = function (bakerAddress, cycle, currentCycle, breakdownRewards) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
var computedBakingRewards, computedEndorsingRewards, fees, totalRewards, endorsingRightsCount, bakingRights, endorsingRights, frozenBalances, lastFrozenBalance;
|
|
194
|
-
return __generator(this, function (_a) {
|
|
195
|
-
switch (_a.label) {
|
|
196
|
-
case 0:
|
|
197
|
-
computedBakingRewards = {
|
|
198
|
-
totalBakingRewards: '0',
|
|
199
|
-
rewardsDetails: []
|
|
200
|
-
};
|
|
201
|
-
computedEndorsingRewards = {
|
|
202
|
-
totalEndorsingRewards: '0',
|
|
203
|
-
rewardsDetails: []
|
|
204
|
-
};
|
|
205
|
-
fees = '0';
|
|
206
|
-
totalRewards = '0';
|
|
207
|
-
endorsingRightsCount = 0;
|
|
208
|
-
if (cycle - currentCycle > 5) {
|
|
209
|
-
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.TEZOS, "Provided cycle " + cycle + " is invalid");
|
|
210
|
-
}
|
|
211
|
-
if (!breakdownRewards) return [3 /*break*/, 5];
|
|
212
|
-
return [4 /*yield*/, this.fetchBakingRights(bakerAddress, cycle)];
|
|
213
|
-
case 1:
|
|
214
|
-
bakingRights = _a.sent();
|
|
215
|
-
return [4 /*yield*/, this.computeBakingRewards(bakingRights, true)];
|
|
216
|
-
case 2:
|
|
217
|
-
computedBakingRewards = _a.sent();
|
|
218
|
-
return [4 /*yield*/, this.fetchEndorsingRights(bakerAddress, cycle)];
|
|
219
|
-
case 3:
|
|
220
|
-
endorsingRights = _a.sent();
|
|
221
|
-
return [4 /*yield*/, this.computeEndorsingRewards(endorsingRights, true)];
|
|
222
|
-
case 4:
|
|
223
|
-
computedEndorsingRewards = _a.sent();
|
|
224
|
-
endorsingRightsCount = endorsingRights.reduce(function (current, next) { return current + next.number_of_slots; }, 0);
|
|
225
|
-
_a.label = 5;
|
|
226
|
-
case 5:
|
|
227
|
-
totalRewards = new bignumber_1.default(computedBakingRewards.totalBakingRewards)
|
|
228
|
-
.plus(new bignumber_1.default(computedEndorsingRewards.totalEndorsingRewards))
|
|
229
|
-
.toFixed();
|
|
230
|
-
return [4 /*yield*/, this.fetchFrozenBalances('head', bakerAddress)];
|
|
231
|
-
case 6:
|
|
232
|
-
frozenBalances = _a.sent();
|
|
233
|
-
if (frozenBalances.length > 0) {
|
|
234
|
-
lastFrozenBalance = frozenBalances[frozenBalances.length - 1];
|
|
235
|
-
fees = lastFrozenBalance.fees;
|
|
236
|
-
}
|
|
237
|
-
return [2 /*return*/, {
|
|
238
|
-
bakingRewards: computedBakingRewards.totalBakingRewards,
|
|
239
|
-
endorsingRewards: computedEndorsingRewards.totalEndorsingRewards,
|
|
240
|
-
totalRewards: totalRewards,
|
|
241
|
-
fees: fees,
|
|
242
|
-
bakingRewardsDetails: computedBakingRewards.rewardsDetails,
|
|
243
|
-
endorsingRewardsDetails: computedEndorsingRewards.rewardsDetails,
|
|
244
|
-
endorsingRightsCount: endorsingRightsCount,
|
|
245
|
-
deposit: '0'
|
|
246
|
-
}];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
TezosRewardsCalculationDefault.prototype.fetchEndorsementOperations = function (cycle, bakerAddress) {
|
|
252
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var cycleStartLevel, cycleEndLevel, query, result;
|
|
254
|
-
return __generator(this, function (_a) {
|
|
255
|
-
switch (_a.label) {
|
|
256
|
-
case 0:
|
|
257
|
-
cycleStartLevel = this.protocol.cycleToBlockLevel(cycle);
|
|
258
|
-
cycleEndLevel = cycleStartLevel + this.tezosNodeConstants.blocks_per_cycle - 1;
|
|
259
|
-
query = {
|
|
260
|
-
fields: ['level', 'delegate', 'number_of_slots', 'block_level'],
|
|
261
|
-
predicates: [
|
|
262
|
-
{
|
|
263
|
-
field: 'kind',
|
|
264
|
-
operation: 'in',
|
|
265
|
-
set: ['endorsement', 'endorsement_with_slot'],
|
|
266
|
-
inverse: false
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
field: 'level',
|
|
270
|
-
operation: 'between',
|
|
271
|
-
set: [cycleStartLevel, cycleEndLevel],
|
|
272
|
-
inverse: false
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
field: 'delegate',
|
|
276
|
-
operation: 'eq',
|
|
277
|
-
set: [bakerAddress]
|
|
278
|
-
}
|
|
279
|
-
]
|
|
280
|
-
};
|
|
281
|
-
return [4 /*yield*/, index_1.default.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/operations", query, {
|
|
282
|
-
headers: this.protocol.headers
|
|
283
|
-
})];
|
|
284
|
-
case 1:
|
|
285
|
-
result = _a.sent();
|
|
286
|
-
return [2 /*return*/, result.data];
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
TezosRewardsCalculationDefault.prototype.fetchFrozenBalances = function (blockLevel, bakerAddress) {
|
|
292
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
293
|
-
var result;
|
|
294
|
-
return __generator(this, function (_a) {
|
|
295
|
-
switch (_a.label) {
|
|
296
|
-
case 0: return [4 /*yield*/, index_1.default.get(this.protocol.jsonRPCAPI + "/chains/main/blocks/" + blockLevel + "/context/delegates/" + bakerAddress + "/frozen_balance_by_cycle")];
|
|
297
|
-
case 1:
|
|
298
|
-
result = _a.sent();
|
|
299
|
-
return [2 /*return*/, result.data];
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
};
|
|
304
|
-
TezosRewardsCalculationDefault.prototype.computeBakingRewards = function (bakingRights, isFutureCycle) {
|
|
305
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var result, rewardsByLevel;
|
|
307
|
-
return __generator(this, function (_a) {
|
|
308
|
-
result = new bignumber_1.default(0);
|
|
309
|
-
rewardsByLevel = [];
|
|
310
|
-
result = new bignumber_1.default(bakingRights.length * this.tezosNodeConstants.block_reward);
|
|
311
|
-
return [2 /*return*/, { totalBakingRewards: result.toFixed(), rewardsDetails: rewardsByLevel }];
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
// be aware this function IS NOT identical to the one in TezosRewardCalculation005
|
|
316
|
-
TezosRewardsCalculationDefault.prototype.computeEndorsingRewards = function (endorsingRights, isFutureCycle) {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
-
var priorities, rewardsByLevel, levels, result;
|
|
319
|
-
var _this = this;
|
|
320
|
-
return __generator(this, function (_a) {
|
|
321
|
-
switch (_a.label) {
|
|
322
|
-
case 0:
|
|
323
|
-
priorities = [];
|
|
324
|
-
rewardsByLevel = [];
|
|
325
|
-
if (!!isFutureCycle) return [3 /*break*/, 2];
|
|
326
|
-
levels = endorsingRights.map(function (er) {
|
|
327
|
-
return er.level;
|
|
328
|
-
});
|
|
329
|
-
if (!(levels.length > 0)) return [3 /*break*/, 2];
|
|
330
|
-
return [4 /*yield*/, this.fetchBlockPriorities(levels)];
|
|
331
|
-
case 1:
|
|
332
|
-
priorities = _a.sent();
|
|
333
|
-
_a.label = 2;
|
|
334
|
-
case 2:
|
|
335
|
-
result = endorsingRights.reduce(function (current, next) {
|
|
336
|
-
var priority = 0;
|
|
337
|
-
if (!isFutureCycle) {
|
|
338
|
-
var block = priorities.find(function (p) { return p.level === next.level; });
|
|
339
|
-
if (block === undefined) {
|
|
340
|
-
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.TEZOS, 'Cannot find block priority');
|
|
341
|
-
}
|
|
342
|
-
priority = block.priority;
|
|
343
|
-
}
|
|
344
|
-
var reward = _this.specificEndorsingCalculation(priority, next.number_of_slots);
|
|
345
|
-
rewardsByLevel.push({
|
|
346
|
-
level: next.level,
|
|
347
|
-
amount: reward.toFixed(),
|
|
348
|
-
deposit: _this.tezosNodeConstants.endorsement_security_deposit
|
|
349
|
-
});
|
|
350
|
-
return current.plus(reward);
|
|
351
|
-
}, new bignumber_1.default(0));
|
|
352
|
-
return [2 /*return*/, { totalEndorsingRewards: result.toFixed(), rewardsDetails: rewardsByLevel }];
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
};
|
|
357
|
-
TezosRewardsCalculationDefault.prototype.specificEndorsingCalculation = function (priority, number_of_slots) {
|
|
358
|
-
var multiplier = new bignumber_1.default(this.tezosNodeConstants.endorsement_reward).div(new bignumber_1.default(priority + 1));
|
|
359
|
-
var reward = new bignumber_1.default(number_of_slots).times(multiplier);
|
|
360
|
-
return reward;
|
|
361
|
-
};
|
|
362
|
-
TezosRewardsCalculationDefault.prototype.computeSnapshotBlockLevel = function (cycle, blockLevel) {
|
|
363
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
364
|
-
var level, snapshotNumberResult, snapshotNumber, delegationCycle, firstDelegationCycleBlocklLevel, numberOfSnapshotsBeforeDelegationCycle, totalSnapshotNumber, snapshotBlockLevel;
|
|
365
|
-
return __generator(this, function (_a) {
|
|
366
|
-
switch (_a.label) {
|
|
367
|
-
case 0:
|
|
368
|
-
level = blockLevel === undefined ? this.protocol.cycleToBlockLevel(cycle) : blockLevel;
|
|
369
|
-
return [4 /*yield*/, index_1.default.get(this.protocol.jsonRPCAPI + "/chains/main/blocks/" + level + "/context/raw/json/cycle/" + cycle + "/roll_snapshot")];
|
|
370
|
-
case 1:
|
|
371
|
-
snapshotNumberResult = _a.sent();
|
|
372
|
-
snapshotNumber = snapshotNumberResult.data;
|
|
373
|
-
delegationCycle = cycle - 7;
|
|
374
|
-
firstDelegationCycleBlocklLevel = this.protocol.cycleToBlockLevel(delegationCycle);
|
|
375
|
-
numberOfSnapshotsBeforeDelegationCycle = firstDelegationCycleBlocklLevel / this.tezosNodeConstants.blocks_per_roll_snapshot;
|
|
376
|
-
totalSnapshotNumber = numberOfSnapshotsBeforeDelegationCycle + snapshotNumber + 1;
|
|
377
|
-
snapshotBlockLevel = totalSnapshotNumber * this.tezosNodeConstants.blocks_per_roll_snapshot;
|
|
378
|
-
return [2 /*return*/, snapshotBlockLevel];
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
TezosRewardsCalculationDefault.prototype.fetchBakerInfo = function (bakerAddress, blockLevel) {
|
|
384
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
385
|
-
var bakerInfoResult;
|
|
386
|
-
return __generator(this, function (_a) {
|
|
387
|
-
switch (_a.label) {
|
|
388
|
-
case 0: return [4 /*yield*/, index_1.default.get(this.protocol.jsonRPCAPI + "/chains/main/blocks/" + blockLevel + "/context/delegates/" + bakerAddress)];
|
|
389
|
-
case 1:
|
|
390
|
-
bakerInfoResult = _a.sent();
|
|
391
|
-
return [2 /*return*/, bakerInfoResult.data];
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
TezosRewardsCalculationDefault.prototype.fetchBlocksForBaker = function (bakerAddress, cycle) {
|
|
397
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
-
var query, result;
|
|
399
|
-
return __generator(this, function (_a) {
|
|
400
|
-
switch (_a.label) {
|
|
401
|
-
case 0:
|
|
402
|
-
query = {
|
|
403
|
-
fields: ['level', 'priority'],
|
|
404
|
-
predicates: [
|
|
405
|
-
{
|
|
406
|
-
field: 'baker',
|
|
407
|
-
operation: 'eq',
|
|
408
|
-
set: [bakerAddress],
|
|
409
|
-
inverse: false
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
field: 'meta_cycle',
|
|
413
|
-
operation: 'eq',
|
|
414
|
-
set: [cycle],
|
|
415
|
-
inverse: false
|
|
416
|
-
}
|
|
417
|
-
]
|
|
418
|
-
};
|
|
419
|
-
return [4 /*yield*/, index_1.default.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/blocks", query, {
|
|
420
|
-
headers: this.protocol.headers
|
|
421
|
-
})];
|
|
422
|
-
case 1:
|
|
423
|
-
result = _a.sent();
|
|
424
|
-
return [2 /*return*/, result.data];
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
|
-
};
|
|
429
|
-
TezosRewardsCalculationDefault.prototype.fetchBlockLevelFieldName = function (entity) {
|
|
430
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
431
|
-
var result;
|
|
432
|
-
var _this = this;
|
|
433
|
-
return __generator(this, function (_a) {
|
|
434
|
-
result = this.blockLevelFieldNameMap.get(entity);
|
|
435
|
-
if (result) {
|
|
436
|
-
return [2 /*return*/, result];
|
|
437
|
-
}
|
|
438
|
-
if (this.fetchBlockLevelFieldPromise) {
|
|
439
|
-
return [2 /*return*/, this.fetchBlockLevelFieldPromise];
|
|
440
|
-
}
|
|
441
|
-
this.fetchBlockLevelFieldPromise = index_1.default
|
|
442
|
-
.get(this.protocol.baseApiUrl + "/v2/metadata/tezos/" + this.protocol.baseApiNetwork + "/" + entity + "/attributes", {
|
|
443
|
-
headers: this.protocol.headers
|
|
444
|
-
})
|
|
445
|
-
.then(function (response) {
|
|
446
|
-
var name = 'block_level';
|
|
447
|
-
var fieldNames = response.data.map(function (metadata) { return metadata.name; });
|
|
448
|
-
if (fieldNames.includes('level')) {
|
|
449
|
-
name = 'level';
|
|
450
|
-
}
|
|
451
|
-
_this.blockLevelFieldNameMap.set(entity, name);
|
|
452
|
-
return name;
|
|
453
|
-
})
|
|
454
|
-
.finally(function () {
|
|
455
|
-
_this.fetchBlockLevelFieldPromise = undefined;
|
|
456
|
-
});
|
|
457
|
-
return [2 /*return*/, this.fetchBlockLevelFieldPromise];
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
};
|
|
461
|
-
TezosRewardsCalculationDefault.prototype.fetchBakingRights = function (bakerAddress, cycle) {
|
|
462
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
463
|
-
var startLevel, endLevel, blockLevelFieldName, query, result;
|
|
464
|
-
return __generator(this, function (_a) {
|
|
465
|
-
switch (_a.label) {
|
|
466
|
-
case 0:
|
|
467
|
-
startLevel = this.protocol.cycleToBlockLevel(cycle);
|
|
468
|
-
endLevel = startLevel + this.tezosNodeConstants.blocks_per_cycle;
|
|
469
|
-
return [4 /*yield*/, this.fetchBlockLevelFieldName('baking_rights')];
|
|
470
|
-
case 1:
|
|
471
|
-
blockLevelFieldName = _a.sent();
|
|
472
|
-
query = {
|
|
473
|
-
fields: ['priority', blockLevelFieldName],
|
|
474
|
-
predicates: [
|
|
475
|
-
{
|
|
476
|
-
field: 'delegate',
|
|
477
|
-
operation: 'eq',
|
|
478
|
-
set: [bakerAddress]
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
field: 'priority',
|
|
482
|
-
operation: 'eq',
|
|
483
|
-
set: [0]
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
field: blockLevelFieldName,
|
|
487
|
-
operation: 'between',
|
|
488
|
-
set: [startLevel, endLevel]
|
|
489
|
-
}
|
|
490
|
-
],
|
|
491
|
-
orderBy: [
|
|
492
|
-
{
|
|
493
|
-
field: blockLevelFieldName,
|
|
494
|
-
direction: 'desc'
|
|
495
|
-
}
|
|
496
|
-
],
|
|
497
|
-
limit: 10000
|
|
498
|
-
};
|
|
499
|
-
return [4 /*yield*/, index_1.default
|
|
500
|
-
.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/baking_rights", query, {
|
|
501
|
-
headers: this.protocol.headers
|
|
502
|
-
})
|
|
503
|
-
.then(function (result) { return result.data; })
|
|
504
|
-
.catch(function (error) { return []; })];
|
|
505
|
-
case 2:
|
|
506
|
-
result = _a.sent();
|
|
507
|
-
return [2 /*return*/, result.map(function (bakingRight) {
|
|
508
|
-
return {
|
|
509
|
-
level: bakingRight[blockLevelFieldName],
|
|
510
|
-
priority: bakingRight.priority,
|
|
511
|
-
delegate: bakerAddress
|
|
512
|
-
};
|
|
513
|
-
})];
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
};
|
|
518
|
-
TezosRewardsCalculationDefault.prototype.fetchEndorsingRights = function (bakerAddress, cycle) {
|
|
519
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
520
|
-
var startLevel, endLevel, blockLevelFieldName, query, result;
|
|
521
|
-
return __generator(this, function (_a) {
|
|
522
|
-
switch (_a.label) {
|
|
523
|
-
case 0:
|
|
524
|
-
startLevel = this.protocol.cycleToBlockLevel(cycle);
|
|
525
|
-
endLevel = startLevel + this.tezosNodeConstants.blocks_per_cycle - 1;
|
|
526
|
-
return [4 /*yield*/, this.fetchBlockLevelFieldName('endorsing_rights')];
|
|
527
|
-
case 1:
|
|
528
|
-
blockLevelFieldName = _a.sent();
|
|
529
|
-
query = {
|
|
530
|
-
fields: [blockLevelFieldName],
|
|
531
|
-
predicates: [
|
|
532
|
-
{
|
|
533
|
-
field: 'delegate',
|
|
534
|
-
operation: 'eq',
|
|
535
|
-
set: [bakerAddress]
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
field: blockLevelFieldName,
|
|
539
|
-
operation: 'between',
|
|
540
|
-
set: [startLevel, endLevel]
|
|
541
|
-
}
|
|
542
|
-
],
|
|
543
|
-
aggregation: [
|
|
544
|
-
{
|
|
545
|
-
field: 'slot',
|
|
546
|
-
function: 'count'
|
|
547
|
-
}
|
|
548
|
-
],
|
|
549
|
-
limit: 100000
|
|
550
|
-
};
|
|
551
|
-
return [4 /*yield*/, index_1.default
|
|
552
|
-
.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/endorsing_rights", query, {
|
|
553
|
-
headers: this.protocol.headers
|
|
554
|
-
})
|
|
555
|
-
.then(function (result) { return result.data; })
|
|
556
|
-
.catch(function (error) { return []; })];
|
|
557
|
-
case 2:
|
|
558
|
-
result = _a.sent();
|
|
559
|
-
return [2 /*return*/, result.map(function (endorsingRight) {
|
|
560
|
-
return {
|
|
561
|
-
level: endorsingRight[blockLevelFieldName],
|
|
562
|
-
delegate: bakerAddress,
|
|
563
|
-
number_of_slots: Number(endorsingRight.count_slot)
|
|
564
|
-
};
|
|
565
|
-
})];
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
};
|
|
570
|
-
TezosRewardsCalculationDefault.prototype.fetchEndorsementOperationCountAndTotalFees = function (blockLevels) {
|
|
571
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
-
var query, result, map, _i, _a, op;
|
|
573
|
-
return __generator(this, function (_b) {
|
|
574
|
-
switch (_b.label) {
|
|
575
|
-
case 0:
|
|
576
|
-
query = {
|
|
577
|
-
fields: ['block_level'],
|
|
578
|
-
predicates: [
|
|
579
|
-
{
|
|
580
|
-
field: 'block_level',
|
|
581
|
-
operation: 'in',
|
|
582
|
-
set: blockLevels,
|
|
583
|
-
inverse: false
|
|
584
|
-
}
|
|
585
|
-
],
|
|
586
|
-
aggregation: [
|
|
587
|
-
{
|
|
588
|
-
field: 'fee',
|
|
589
|
-
function: 'sum'
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
field: 'number_of_slots',
|
|
593
|
-
function: 'sum'
|
|
594
|
-
}
|
|
595
|
-
]
|
|
596
|
-
};
|
|
597
|
-
return [4 /*yield*/, index_1.default.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/operations", query, {
|
|
598
|
-
headers: this.protocol.headers
|
|
599
|
-
})];
|
|
600
|
-
case 1:
|
|
601
|
-
result = _b.sent();
|
|
602
|
-
map = new Map();
|
|
603
|
-
for (_i = 0, _a = result.data; _i < _a.length; _i++) {
|
|
604
|
-
op = _a[_i];
|
|
605
|
-
map.set(op.block_level, op);
|
|
606
|
-
}
|
|
607
|
-
return [2 /*return*/, map];
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
};
|
|
612
|
-
TezosRewardsCalculationDefault.prototype.fetchBlockPriorities = function (blockLevels) {
|
|
613
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
614
|
-
var query, result;
|
|
615
|
-
return __generator(this, function (_a) {
|
|
616
|
-
switch (_a.label) {
|
|
617
|
-
case 0:
|
|
618
|
-
query = {
|
|
619
|
-
fields: ['priority', 'level'],
|
|
620
|
-
predicates: [
|
|
621
|
-
{
|
|
622
|
-
field: 'level',
|
|
623
|
-
operation: 'in',
|
|
624
|
-
set: blockLevels,
|
|
625
|
-
inverse: false
|
|
626
|
-
}
|
|
627
|
-
]
|
|
628
|
-
};
|
|
629
|
-
return [4 /*yield*/, index_1.default.post(this.protocol.baseApiUrl + "/v2/data/tezos/" + this.protocol.baseApiNetwork + "/blocks", query, {
|
|
630
|
-
headers: this.protocol.headers
|
|
631
|
-
})];
|
|
632
|
-
case 1:
|
|
633
|
-
result = _a.sent();
|
|
634
|
-
return [2 /*return*/, result.data];
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
return TezosRewardsCalculationDefault;
|
|
640
|
-
}());
|
|
641
|
-
exports.TezosRewardsCalculationDefault = TezosRewardsCalculationDefault;
|
|
642
|
-
//# sourceMappingURL=TezosRewardCalculationDefault.js.map
|