@argonprotocol/mainchain 1.3.2 → 1.3.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/browser/index.d.ts +11990 -0
- package/browser/index.js +2721 -0
- package/browser/index.js.map +1 -0
- package/lib/{chunk-CGXT6XF7.js → chunk-FCT7GMFN.js} +287 -315
- package/lib/chunk-FCT7GMFN.js.map +1 -0
- package/lib/{chunk-NU36V3JQ.cjs → chunk-IQ3TNLS7.cjs} +55 -53
- package/lib/chunk-IQ3TNLS7.cjs.map +1 -0
- package/lib/{chunk-SHAEHPI5.cjs → chunk-OFYVHBKG.cjs} +323 -351
- package/lib/chunk-OFYVHBKG.cjs.map +1 -0
- package/lib/{chunk-FNSFV3MO.js → chunk-UZCZ347U.js} +7 -5
- package/lib/chunk-UZCZ347U.js.map +1 -0
- package/lib/cli.cjs +11 -6
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.js +8 -3
- package/lib/cli.js.map +1 -1
- package/lib/clis/index.cjs +3 -3
- package/lib/clis/index.d.cts +2 -0
- package/lib/clis/index.d.ts +2 -0
- package/lib/clis/index.js +2 -2
- package/lib/index.cjs +60 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +68 -108
- package/lib/index.d.ts +68 -108
- package/lib/index.js +61 -3
- package/package.json +8 -3
- package/lib/chunk-CGXT6XF7.js.map +0 -1
- package/lib/chunk-FNSFV3MO.js.map +0 -1
- package/lib/chunk-NU36V3JQ.cjs.map +0 -1
- package/lib/chunk-SHAEHPI5.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11;// src/interfaces/augment-api-consts.ts
|
|
2
2
|
require('@polkadot/api-base/types/consts');
|
|
3
3
|
|
|
4
4
|
// src/interfaces/augment-api-errors.ts
|
|
@@ -56,7 +56,7 @@ var WageProtector = class _WageProtector {
|
|
|
56
56
|
new _WageProtector({
|
|
57
57
|
argonUsdTargetPrice: cpi.value.argonUsdTargetPrice.toBigInt(),
|
|
58
58
|
argonUsdPrice: cpi.value.argonUsdPrice.toBigInt(),
|
|
59
|
-
finalizedBlock:
|
|
59
|
+
finalizedBlock: new Uint8Array(finalizedBlock),
|
|
60
60
|
tick: cpi.value.tick.toBigInt()
|
|
61
61
|
})
|
|
62
62
|
);
|
|
@@ -81,9 +81,29 @@ var WageProtector = class _WageProtector {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
// src/config.ts
|
|
85
|
+
var config = {};
|
|
86
|
+
function getEnvVar(key) {
|
|
87
|
+
if (typeof process !== "undefined" && process.env) {
|
|
88
|
+
return process.env[key];
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
function setConfig(newConfig) {
|
|
93
|
+
config = { ...config, ...newConfig };
|
|
94
|
+
}
|
|
95
|
+
function getConfig() {
|
|
96
|
+
return {
|
|
97
|
+
debug: _nullishCoalesce(config.debug, () => ( getEnvVar("DEBUG") === "true")),
|
|
98
|
+
keysVersion: _nullishCoalesce(config.keysVersion, () => ( (getEnvVar("KEYS_VERSION") ? parseInt(getEnvVar("KEYS_VERSION")) : void 0))),
|
|
99
|
+
keysMnemonic: _nullishCoalesce(config.keysMnemonic, () => ( getEnvVar("KEYS_MNEMONIC"))),
|
|
100
|
+
subaccountRange: _nullishCoalesce(_nullishCoalesce(config.subaccountRange, () => ( getEnvVar("SUBACCOUNT_RANGE"))), () => ( "0-9"))
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
// src/TxSubmitter.ts
|
|
85
105
|
function logExtrinsicResult(result) {
|
|
86
|
-
if (
|
|
106
|
+
if (getConfig().debug) {
|
|
87
107
|
const json = result.status.toJSON();
|
|
88
108
|
const status = Object.keys(json)[0];
|
|
89
109
|
console.debug('Transaction update: "%s"', status, json[status]);
|
|
@@ -113,8 +133,10 @@ var TxSubmitter = class {
|
|
|
113
133
|
return { canAfford, availableBalance, txFee: fees };
|
|
114
134
|
}
|
|
115
135
|
async submit(options = {}) {
|
|
116
|
-
const { logResults } = options;
|
|
136
|
+
const { logResults, waitForBlock, useLatestNonce, ...apiOptions } = options;
|
|
137
|
+
await waitForLoad();
|
|
117
138
|
const result = new TxResult(this.client, logResults);
|
|
139
|
+
result.onResultCallback = options.onResultCallback;
|
|
118
140
|
let toHuman = this.tx.toHuman().method;
|
|
119
141
|
let txString = [];
|
|
120
142
|
let api = formatCall(toHuman);
|
|
@@ -132,12 +154,12 @@ var TxSubmitter = class {
|
|
|
132
154
|
args.push(toHuman.args);
|
|
133
155
|
}
|
|
134
156
|
args.unshift(txString.join("->"));
|
|
135
|
-
if (
|
|
136
|
-
|
|
157
|
+
if (useLatestNonce && !apiOptions.nonce) {
|
|
158
|
+
apiOptions.nonce = await this.client.rpc.system.accountNextIndex(this.pair.address);
|
|
137
159
|
}
|
|
138
|
-
console.log("Submitting transaction:", ...args);
|
|
139
|
-
await this.tx.signAndSend(this.pair,
|
|
140
|
-
if (
|
|
160
|
+
console.log("Submitting transaction from %s:", this.pair.address, ...args);
|
|
161
|
+
await this.tx.signAndSend(this.pair, apiOptions, result.onResult.bind(result));
|
|
162
|
+
if (waitForBlock) {
|
|
141
163
|
await result.inBlockPromise;
|
|
142
164
|
}
|
|
143
165
|
return result;
|
|
@@ -184,6 +206,7 @@ var TxResult = (_class = class {
|
|
|
184
206
|
|
|
185
207
|
|
|
186
208
|
|
|
209
|
+
|
|
187
210
|
onResult(result) {
|
|
188
211
|
this.status = result.status;
|
|
189
212
|
if (this.shouldLog) {
|
|
@@ -191,7 +214,7 @@ var TxResult = (_class = class {
|
|
|
191
214
|
}
|
|
192
215
|
const { events, status, dispatchError, isFinalized } = result;
|
|
193
216
|
if (status.isInBlock) {
|
|
194
|
-
this.includedInBlock =
|
|
217
|
+
this.includedInBlock = new Uint8Array(status.asInBlock);
|
|
195
218
|
let encounteredError = dispatchError;
|
|
196
219
|
let batchErrorIndex;
|
|
197
220
|
for (const event of events) {
|
|
@@ -211,12 +234,13 @@ var TxResult = (_class = class {
|
|
|
211
234
|
const error = dispatchErrorToExtrinsicError(this.client, encounteredError, batchErrorIndex);
|
|
212
235
|
this.reject(error);
|
|
213
236
|
} else {
|
|
214
|
-
this.inBlockResolve(
|
|
237
|
+
this.inBlockResolve(new Uint8Array(status.asInBlock));
|
|
215
238
|
}
|
|
216
239
|
}
|
|
217
240
|
if (isFinalized) {
|
|
218
241
|
this.finalizedResolve(status.asFinalized);
|
|
219
242
|
}
|
|
243
|
+
_optionalChain([this, 'access', _2 => _2.onResultCallback, 'optionalCall', _3 => _3(result)]);
|
|
220
244
|
}
|
|
221
245
|
reject(error) {
|
|
222
246
|
this.inBlockReject(error);
|
|
@@ -226,6 +250,7 @@ var TxResult = (_class = class {
|
|
|
226
250
|
|
|
227
251
|
// src/utils.ts
|
|
228
252
|
var _bignumberjs = require('bignumber.js'); var BN = _interopRequireWildcard(_bignumberjs); var BN2 = _interopRequireWildcard(_bignumberjs);
|
|
253
|
+
var _util = require('@polkadot/util');
|
|
229
254
|
var { ROUND_FLOOR } = BN;
|
|
230
255
|
var MICROGONS_PER_ARGON = 1e6;
|
|
231
256
|
function formatArgons(x) {
|
|
@@ -271,10 +296,11 @@ async function gettersToObject(obj) {
|
|
|
271
296
|
}
|
|
272
297
|
return result;
|
|
273
298
|
}
|
|
274
|
-
function toFixedNumber(value,
|
|
275
|
-
const
|
|
276
|
-
const
|
|
277
|
-
|
|
299
|
+
function toFixedNumber(value, decimals) {
|
|
300
|
+
const factor = new (0, BN.default)(10).pow(decimals);
|
|
301
|
+
const bn = new (0, BN.default)(value);
|
|
302
|
+
const int = bn.times(factor).integerValue(BN.default.ROUND_DOWN);
|
|
303
|
+
return BigInt(int.toFixed(0));
|
|
278
304
|
}
|
|
279
305
|
function convertNumberToFixedU128(value) {
|
|
280
306
|
return toFixedNumber(value, 18);
|
|
@@ -295,7 +321,7 @@ function convertNumberToPermill(value) {
|
|
|
295
321
|
function eventDataToJson(event) {
|
|
296
322
|
const obj = {};
|
|
297
323
|
event.data.forEach((data, index) => {
|
|
298
|
-
const name = _optionalChain([event, 'access',
|
|
324
|
+
const name = _optionalChain([event, 'access', _4 => _4.data, 'access', _5 => _5.names, 'optionalAccess', _6 => _6[index]]);
|
|
299
325
|
obj[_nullishCoalesce(name, () => ( `${index}`))] = data.toJSON();
|
|
300
326
|
});
|
|
301
327
|
return obj;
|
|
@@ -356,8 +382,12 @@ var JsonExt = class {
|
|
|
356
382
|
if (typeof v === "bigint") {
|
|
357
383
|
return `${v}n`;
|
|
358
384
|
}
|
|
359
|
-
if (
|
|
360
|
-
return
|
|
385
|
+
if (v instanceof Uint8Array) {
|
|
386
|
+
return {
|
|
387
|
+
type: "Buffer",
|
|
388
|
+
data: Array.from(v)
|
|
389
|
+
// Convert Uint8Array to an array of numbers
|
|
390
|
+
};
|
|
361
391
|
}
|
|
362
392
|
return v;
|
|
363
393
|
},
|
|
@@ -370,7 +400,7 @@ var JsonExt = class {
|
|
|
370
400
|
return BigInt(v.slice(0, -1));
|
|
371
401
|
}
|
|
372
402
|
if (typeof v === "object" && v !== null && v.type === "Buffer" && Array.isArray(v.data)) {
|
|
373
|
-
return
|
|
403
|
+
return _util.hexToU8a.call(void 0, v.data);
|
|
374
404
|
}
|
|
375
405
|
return v;
|
|
376
406
|
});
|
|
@@ -389,7 +419,7 @@ var TypedEmitter = (_class2 = class {constructor() { _class2.prototype.__init2.c
|
|
|
389
419
|
on(event, cb) {
|
|
390
420
|
(this.events[event] ||= []).push(cb);
|
|
391
421
|
return () => {
|
|
392
|
-
this.events[event] = _optionalChain([this, 'access',
|
|
422
|
+
this.events[event] = _optionalChain([this, 'access', _7 => _7.events, 'access', _8 => _8[event], 'optionalAccess', _9 => _9.filter, 'call', _10 => _10((i) => cb !== i)]);
|
|
393
423
|
};
|
|
394
424
|
}
|
|
395
425
|
}, _class2);
|
|
@@ -412,9 +442,6 @@ var AccountRegistry = (_class3 = class _AccountRegistry {
|
|
|
412
442
|
static __initStatic() {this.factory = (name) => new _AccountRegistry(name)}
|
|
413
443
|
}, _class3.__initStatic(), _class3);
|
|
414
444
|
|
|
415
|
-
// src/Accountset.ts
|
|
416
|
-
var _process = require('process'); var process2 = _interopRequireWildcard(_process);
|
|
417
|
-
|
|
418
445
|
// src/BlockWatch.ts
|
|
419
446
|
function getTickFromHeader(client, header) {
|
|
420
447
|
for (const x of header.digest.logs) {
|
|
@@ -562,7 +589,7 @@ BLOCK #${header.number}, ${header.hash.toHuman()}`);
|
|
|
562
589
|
if (this.options.shouldLog) {
|
|
563
590
|
console.log(
|
|
564
591
|
`> [Failed Tx] ${section}.${name} -> ${ext.method.section}.${ext.method.method} (nonce=${ext.nonce})`,
|
|
565
|
-
_optionalChain([ext, 'access',
|
|
592
|
+
_optionalChain([ext, 'access', _11 => _11.toHuman, 'call', _12 => _12(), 'optionalAccess', _13 => _13.method, 'optionalAccess', _14 => _14.args])
|
|
566
593
|
);
|
|
567
594
|
}
|
|
568
595
|
} else {
|
|
@@ -628,13 +655,13 @@ var FrameCalculator = class {
|
|
|
628
655
|
slotBiddingStartAfterTicks: x.slotBiddingStartAfterTicks.toNumber()
|
|
629
656
|
}));
|
|
630
657
|
this.genesisTick ??= await client.query.ticks.genesisTick().then((x) => x.toNumber());
|
|
631
|
-
const
|
|
658
|
+
const config2 = this.miningConfig;
|
|
632
659
|
const genesisTick = this.genesisTick;
|
|
633
660
|
return {
|
|
634
|
-
ticksBetweenFrames:
|
|
635
|
-
slotBiddingStartAfterTicks:
|
|
661
|
+
ticksBetweenFrames: config2.ticksBetweenSlots,
|
|
662
|
+
slotBiddingStartAfterTicks: config2.slotBiddingStartAfterTicks,
|
|
636
663
|
genesisTick,
|
|
637
|
-
biddingStartTick: genesisTick +
|
|
664
|
+
biddingStartTick: genesisTick + config2.slotBiddingStartAfterTicks
|
|
638
665
|
};
|
|
639
666
|
}
|
|
640
667
|
};
|
|
@@ -645,10 +672,10 @@ var AccountMiners = (_class5 = class _AccountMiners {
|
|
|
645
672
|
this.accountset = accountset;
|
|
646
673
|
this.options = options;
|
|
647
674
|
this.frameCalculator = new FrameCalculator();
|
|
648
|
-
for (const
|
|
649
|
-
this.trackedAccountsByAddress[
|
|
650
|
-
startingFrameId: seat.startingFrameId,
|
|
651
|
-
subaccountIndex:
|
|
675
|
+
for (const miner of registeredMiners) {
|
|
676
|
+
this.trackedAccountsByAddress[miner.address] = {
|
|
677
|
+
startingFrameId: miner.seat.startingFrameId,
|
|
678
|
+
subaccountIndex: miner.subaccountIndex
|
|
652
679
|
};
|
|
653
680
|
}
|
|
654
681
|
}
|
|
@@ -760,6 +787,7 @@ var AccountMiners = (_class5 = class _AccountMiners {
|
|
|
760
787
|
}, _class5);
|
|
761
788
|
|
|
762
789
|
// src/Accountset.ts
|
|
790
|
+
|
|
763
791
|
var Accountset = (_class6 = class {
|
|
764
792
|
|
|
765
793
|
__init9() {this.isProxy = false}
|
|
@@ -817,7 +845,7 @@ var Accountset = (_class6 = class {
|
|
|
817
845
|
return {
|
|
818
846
|
address,
|
|
819
847
|
amount: account.data.free.toBigInt(),
|
|
820
|
-
index: _nullishCoalesce(_optionalChain([this, 'access',
|
|
848
|
+
index: _nullishCoalesce(_optionalChain([this, 'access', _15 => _15.subAccountsByAddress, 'access', _16 => _16[address], 'optionalAccess', _17 => _17.index]), () => ( Number.NaN))
|
|
821
849
|
};
|
|
822
850
|
});
|
|
823
851
|
}
|
|
@@ -831,7 +859,7 @@ var Accountset = (_class6 = class {
|
|
|
831
859
|
return {
|
|
832
860
|
address,
|
|
833
861
|
amount: account.free.toBigInt(),
|
|
834
|
-
index: _nullishCoalesce(_optionalChain([this, 'access',
|
|
862
|
+
index: _nullishCoalesce(_optionalChain([this, 'access', _18 => _18.subAccountsByAddress, 'access', _19 => _19[address], 'optionalAccess', _20 => _20.index]), () => ( Number.NaN))
|
|
835
863
|
};
|
|
836
864
|
});
|
|
837
865
|
}
|
|
@@ -880,9 +908,9 @@ var Accountset = (_class6 = class {
|
|
|
880
908
|
const [frameIdRaw, indexRaw] = rawIndices[i].value;
|
|
881
909
|
const frameId = frameIdRaw.toNumber();
|
|
882
910
|
const index = indexRaw.toNumber();
|
|
883
|
-
const bidAmount = _optionalChain([bidAmountsByFrame, 'access',
|
|
911
|
+
const bidAmount = _optionalChain([bidAmountsByFrame, 'access', _21 => _21[frameId], 'optionalAccess', _22 => _22[index]]);
|
|
884
912
|
addressToMiningIndex[address] = {
|
|
885
|
-
frameId,
|
|
913
|
+
startingFrameId: frameId,
|
|
886
914
|
index,
|
|
887
915
|
bidAmount: _nullishCoalesce(bidAmount, () => ( 0n))
|
|
888
916
|
};
|
|
@@ -892,13 +920,13 @@ var Accountset = (_class6 = class {
|
|
|
892
920
|
const cohort = addressToMiningIndex[address];
|
|
893
921
|
let isLastDay = false;
|
|
894
922
|
if (cohort !== void 0) {
|
|
895
|
-
isLastDay = nextFrameId.toNumber() - cohort.
|
|
923
|
+
isLastDay = nextFrameId.toNumber() - cohort.startingFrameId === 10;
|
|
896
924
|
}
|
|
897
925
|
return {
|
|
898
926
|
address,
|
|
899
927
|
seat: cohort,
|
|
900
928
|
isLastDay,
|
|
901
|
-
subaccountIndex: _nullishCoalesce(_optionalChain([this, 'access',
|
|
929
|
+
subaccountIndex: _nullishCoalesce(_optionalChain([this, 'access', _23 => _23.subAccountsByAddress, 'access', _24 => _24[address], 'optionalAccess', _25 => _25.index]), () => ( Number.NaN))
|
|
902
930
|
};
|
|
903
931
|
});
|
|
904
932
|
}
|
|
@@ -912,7 +940,7 @@ var Accountset = (_class6 = class {
|
|
|
912
940
|
return {
|
|
913
941
|
...miner,
|
|
914
942
|
hasWinningBid: !!bid,
|
|
915
|
-
bidAmount: _nullishCoalesce(_nullishCoalesce(_optionalChain([bid, 'optionalAccess',
|
|
943
|
+
bidAmount: _nullishCoalesce(_nullishCoalesce(_optionalChain([bid, 'optionalAccess', _26 => _26.bid, 'access', _27 => _27.toBigInt, 'call', _28 => _28()]), () => ( _optionalChain([miner, 'access', _29 => _29.seat, 'optionalAccess', _30 => _30.bidAmount]))), () => ( 0n))
|
|
916
944
|
};
|
|
917
945
|
});
|
|
918
946
|
}
|
|
@@ -928,9 +956,9 @@ var Accountset = (_class6 = class {
|
|
|
928
956
|
const entry = registrationsByAddress[address];
|
|
929
957
|
return {
|
|
930
958
|
address,
|
|
931
|
-
bidPlace: _optionalChain([entry, 'optionalAccess',
|
|
932
|
-
bidAmount: _optionalChain([entry, 'optionalAccess',
|
|
933
|
-
index: _nullishCoalesce(_optionalChain([this, 'access',
|
|
959
|
+
bidPlace: _optionalChain([entry, 'optionalAccess', _31 => _31.index]),
|
|
960
|
+
bidAmount: _optionalChain([entry, 'optionalAccess', _32 => _32.bid, 'optionalAccess', _33 => _33.toBigInt, 'call', _34 => _34()]),
|
|
961
|
+
index: _nullishCoalesce(_optionalChain([this, 'access', _35 => _35.subAccountsByAddress, 'access', _36 => _36[address], 'optionalAccess', _37 => _37.index]), () => ( Number.NaN))
|
|
934
962
|
};
|
|
935
963
|
});
|
|
936
964
|
}
|
|
@@ -980,23 +1008,23 @@ var Accountset = (_class6 = class {
|
|
|
980
1008
|
{
|
|
981
1009
|
index: "main",
|
|
982
1010
|
address: this.seedAddress,
|
|
983
|
-
argons: formatArgons(_nullishCoalesce(_optionalChain([argons, 'access',
|
|
984
|
-
argonots: formatArgons(_nullishCoalesce(_optionalChain([argonots, 'access',
|
|
1011
|
+
argons: formatArgons(_nullishCoalesce(_optionalChain([argons, 'access', _38 => _38.find, 'call', _39 => _39((x) => x.address === this.seedAddress), 'optionalAccess', _40 => _40.amount]), () => ( 0n))),
|
|
1012
|
+
argonots: formatArgons(_nullishCoalesce(_optionalChain([argonots, 'access', _41 => _41.find, 'call', _42 => _42((x) => x.address === this.seedAddress), 'optionalAccess', _43 => _43.amount]), () => ( 0n)))
|
|
985
1013
|
}
|
|
986
1014
|
];
|
|
987
1015
|
for (const [address, { index }] of Object.entries(this.subAccountsByAddress)) {
|
|
988
|
-
const argonAmount = _nullishCoalesce(_optionalChain([argons, 'access',
|
|
989
|
-
const argonotAmount = _nullishCoalesce(_optionalChain([argonots, 'access',
|
|
1016
|
+
const argonAmount = _nullishCoalesce(_optionalChain([argons, 'access', _44 => _44.find, 'call', _45 => _45((x) => x.address === address), 'optionalAccess', _46 => _46.amount]), () => ( 0n));
|
|
1017
|
+
const argonotAmount = _nullishCoalesce(_optionalChain([argonots, 'access', _47 => _47.find, 'call', _48 => _48((x) => x.address === address), 'optionalAccess', _49 => _49.amount]), () => ( 0n));
|
|
990
1018
|
const bid = bids.find((x) => x.address === address);
|
|
991
|
-
const seat = _optionalChain([seats, 'access',
|
|
1019
|
+
const seat = _optionalChain([seats, 'access', _50 => _50.find, 'call', _51 => _51((x) => x.address === address), 'optionalAccess', _52 => _52.seat]);
|
|
992
1020
|
const entry = {
|
|
993
1021
|
index: ` //${index}`,
|
|
994
1022
|
address,
|
|
995
1023
|
argons: formatArgons(argonAmount),
|
|
996
1024
|
argonots: formatArgons(argonotAmount),
|
|
997
1025
|
seat,
|
|
998
|
-
bidPlace: _optionalChain([bid, 'optionalAccess',
|
|
999
|
-
bidAmount: _nullishCoalesce(_optionalChain([bid, 'optionalAccess',
|
|
1026
|
+
bidPlace: _optionalChain([bid, 'optionalAccess', _53 => _53.bidPlace]),
|
|
1027
|
+
bidAmount: _nullishCoalesce(_optionalChain([bid, 'optionalAccess', _54 => _54.bidAmount]), () => ( 0n))
|
|
1000
1028
|
};
|
|
1001
1029
|
if (accountSubset) {
|
|
1002
1030
|
entry.isWorkingOn = accountSubset.some((x) => x.address === address);
|
|
@@ -1021,11 +1049,9 @@ var Accountset = (_class6 = class {
|
|
|
1021
1049
|
await client.disconnect();
|
|
1022
1050
|
}
|
|
1023
1051
|
keys(keysVersion) {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
const seedMnemonic = _nullishCoalesce(this.sessionKeyMnemonic, () => ( process2.env.KEYS_MNEMONIC));
|
|
1052
|
+
const config2 = getConfig();
|
|
1053
|
+
let version = _nullishCoalesce(_nullishCoalesce(keysVersion, () => ( config2.keysVersion)), () => ( 0));
|
|
1054
|
+
const seedMnemonic = _nullishCoalesce(this.sessionKeyMnemonic, () => ( config2.keysMnemonic));
|
|
1029
1055
|
if (!seedMnemonic) {
|
|
1030
1056
|
throw new Error("KEYS_MNEMONIC environment variable not set. Cannot derive keys.");
|
|
1031
1057
|
}
|
|
@@ -1040,12 +1066,12 @@ var Accountset = (_class6 = class {
|
|
|
1040
1066
|
return {
|
|
1041
1067
|
seal: {
|
|
1042
1068
|
privateKey: blockSealKey,
|
|
1043
|
-
publicKey:
|
|
1069
|
+
publicKey: _util.u8aToHex.call(void 0, blockSealAccount.publicKey),
|
|
1044
1070
|
rawPublicKey: blockSealAccount.publicKey
|
|
1045
1071
|
},
|
|
1046
1072
|
gran: {
|
|
1047
1073
|
privateKey: granKey,
|
|
1048
|
-
publicKey:
|
|
1074
|
+
publicKey: _util.u8aToHex.call(void 0, grandpaAccount.publicKey),
|
|
1049
1075
|
rawPublicKey: grandpaAccount.publicKey
|
|
1050
1076
|
}
|
|
1051
1077
|
};
|
|
@@ -1148,10 +1174,11 @@ var Accountset = (_class6 = class {
|
|
|
1148
1174
|
}, _class6);
|
|
1149
1175
|
function getDefaultSubaccountRange() {
|
|
1150
1176
|
try {
|
|
1151
|
-
|
|
1177
|
+
const config2 = getConfig();
|
|
1178
|
+
return parseSubaccountRange(_nullishCoalesce(config2.subaccountRange, () => ( "0-9")));
|
|
1152
1179
|
} catch (e2) {
|
|
1153
1180
|
console.error(
|
|
1154
|
-
"Failed to parse SUBACCOUNT_RANGE
|
|
1181
|
+
"Failed to parse SUBACCOUNT_RANGE configuration. Defaulting to 0-9. Please check the format of the subaccountRange config value."
|
|
1155
1182
|
);
|
|
1156
1183
|
return Array.from({ length: 10 }, (_, i) => i);
|
|
1157
1184
|
}
|
|
@@ -1190,7 +1217,7 @@ var MiningBids = (_class7 = class {
|
|
|
1190
1217
|
__init11() {this.nextCohort = []}
|
|
1191
1218
|
async maxCohortSize() {
|
|
1192
1219
|
const client = await this.client;
|
|
1193
|
-
return client.
|
|
1220
|
+
return client.query.miningSlot.nextCohortSize().then((x) => x.toNumber());
|
|
1194
1221
|
}
|
|
1195
1222
|
async onCohortChange(options) {
|
|
1196
1223
|
const { onBiddingStart, onBiddingEnd } = options;
|
|
@@ -1205,12 +1232,12 @@ var MiningBids = (_class7 = class {
|
|
|
1205
1232
|
const nextFrameId = rawNextCohortStartingFrameId.toNumber();
|
|
1206
1233
|
if (isBiddingOpen.isTrue) {
|
|
1207
1234
|
if (openCohortStartingFrameId !== 0) {
|
|
1208
|
-
await _optionalChain([onBiddingEnd, 'optionalCall',
|
|
1235
|
+
await _optionalChain([onBiddingEnd, 'optionalCall', _55 => _55(openCohortStartingFrameId)]);
|
|
1209
1236
|
}
|
|
1210
1237
|
openCohortStartingFrameId = nextFrameId;
|
|
1211
|
-
await _optionalChain([onBiddingStart, 'optionalCall',
|
|
1238
|
+
await _optionalChain([onBiddingStart, 'optionalCall', _56 => _56(nextFrameId)]);
|
|
1212
1239
|
} else {
|
|
1213
|
-
await _optionalChain([onBiddingEnd, 'optionalCall',
|
|
1240
|
+
await _optionalChain([onBiddingEnd, 'optionalCall', _57 => _57(nextFrameId)]);
|
|
1214
1241
|
openCohortStartingFrameId = 0;
|
|
1215
1242
|
}
|
|
1216
1243
|
}
|
|
@@ -1265,10 +1292,30 @@ var MiningBids = (_class7 = class {
|
|
|
1265
1292
|
// src/Vault.ts
|
|
1266
1293
|
|
|
1267
1294
|
var _bs58check = require('bs58check'); var _bs58check2 = _interopRequireDefault(_bs58check);
|
|
1295
|
+
|
|
1268
1296
|
var { ROUND_FLOOR: ROUND_FLOOR2 } = BN2;
|
|
1269
1297
|
var Vault = (_class8 = class _Vault {
|
|
1270
1298
|
constructor(id, vault, tickDuration) {;_class8.prototype.__init12.call(this);
|
|
1271
1299
|
this.tickDuration = tickDuration;
|
|
1300
|
+
this.vaultId = id;
|
|
1301
|
+
this.load(vault);
|
|
1302
|
+
this.openedTick = vault.openedTick.toNumber();
|
|
1303
|
+
this.openedDate = new Date(this.openedTick * this.tickDuration);
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
__init12() {this.argonsScheduledForRelease = /* @__PURE__ */ new Map()}
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
load(vault) {
|
|
1272
1319
|
this.securitization = vault.securitization.toBigInt();
|
|
1273
1320
|
this.securitizationRatio = convertFixedU128ToBigNumber(vault.securitizationRatio.toBigInt());
|
|
1274
1321
|
this.argonsLocked = vault.argonsLocked.toBigInt();
|
|
@@ -1290,7 +1337,6 @@ var Vault = (_class8 = class _Vault {
|
|
|
1290
1337
|
};
|
|
1291
1338
|
this.operatorAccountId = vault.operatorAccountId.toString();
|
|
1292
1339
|
this.isClosed = vault.isClosed.valueOf();
|
|
1293
|
-
this.vaultId = id;
|
|
1294
1340
|
if (vault.pendingTerms.isSome) {
|
|
1295
1341
|
const [tickApply, terms] = vault.pendingTerms.value;
|
|
1296
1342
|
this.pendingTermsChangeTick = tickApply.toNumber();
|
|
@@ -1304,22 +1350,7 @@ var Vault = (_class8 = class _Vault {
|
|
|
1304
1350
|
)
|
|
1305
1351
|
};
|
|
1306
1352
|
}
|
|
1307
|
-
this.openedTick = vault.openedTick.toNumber();
|
|
1308
|
-
this.openedDate = new Date(this.openedTick * tickDuration);
|
|
1309
1353
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
__init12() {this.argonsScheduledForRelease = /* @__PURE__ */ new Map()}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
1354
|
availableBitcoinSpace() {
|
|
1324
1355
|
const recoverySecuritization = this.recoverySecuritization();
|
|
1325
1356
|
const reLockable = this.getRelockCapacity();
|
|
@@ -1356,48 +1387,83 @@ var Vault = (_class8 = class _Vault {
|
|
|
1356
1387
|
const fee = this.terms.bitcoinAnnualPercentRate.multipliedBy(Number(amount)).integerValue(BN.default.ROUND_CEIL);
|
|
1357
1388
|
return BigInt(fee.toString()) + this.terms.bitcoinBaseFee;
|
|
1358
1389
|
}
|
|
1359
|
-
static async get(client, vaultId) {
|
|
1390
|
+
static async get(client, vaultId, tickDurationMillis) {
|
|
1360
1391
|
const rawVault = await client.query.vaults.vaultsById(vaultId);
|
|
1361
1392
|
if (rawVault.isNone) {
|
|
1362
1393
|
throw new Error(`Vault with id ${vaultId} not found`);
|
|
1363
1394
|
}
|
|
1364
|
-
const tickDuration = await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber());
|
|
1395
|
+
const tickDuration = await _asyncNullishCoalesce(tickDurationMillis, async () => ( await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber())));
|
|
1365
1396
|
return new _Vault(vaultId, rawVault.unwrap(), tickDuration);
|
|
1366
1397
|
}
|
|
1367
|
-
static async create(client, keypair, args,
|
|
1368
|
-
const {
|
|
1369
|
-
|
|
1398
|
+
static async create(client, keypair, args, config2 = {}) {
|
|
1399
|
+
const {
|
|
1400
|
+
securitization,
|
|
1401
|
+
securitizationRatio,
|
|
1402
|
+
annualPercentRate,
|
|
1403
|
+
baseFee,
|
|
1404
|
+
bitcoinXpub,
|
|
1405
|
+
tip,
|
|
1406
|
+
doNotExceedBalance,
|
|
1407
|
+
progressCallback
|
|
1408
|
+
} = args;
|
|
1409
|
+
let xpubBytes = _util.hexToU8a.call(void 0, bitcoinXpub);
|
|
1370
1410
|
if (xpubBytes.length !== 78) {
|
|
1371
1411
|
if (bitcoinXpub.startsWith("xpub") || bitcoinXpub.startsWith("tpub") || bitcoinXpub.startsWith("zpub")) {
|
|
1372
1412
|
const bytes = _bs58check2.default.decode(bitcoinXpub);
|
|
1373
1413
|
if (bytes.length !== 78) {
|
|
1374
1414
|
throw new Error("Invalid Bitcoin xpub key length, must be 78 bytes");
|
|
1375
1415
|
}
|
|
1376
|
-
xpubBytes =
|
|
1416
|
+
xpubBytes = bytes;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
let vaultParams = {
|
|
1420
|
+
terms: {
|
|
1421
|
+
// convert to fixed u128
|
|
1422
|
+
bitcoinAnnualPercentRate: toFixedNumber(annualPercentRate, 18),
|
|
1423
|
+
bitcoinBaseFee: BigInt(baseFee),
|
|
1424
|
+
liquidityPoolProfitSharing: toFixedNumber(args.liquidityPoolProfitSharing, 6)
|
|
1425
|
+
},
|
|
1426
|
+
securitizationRatio: toFixedNumber(securitizationRatio, 18),
|
|
1427
|
+
securitization: BigInt(securitization),
|
|
1428
|
+
bitcoinXpubkey: xpubBytes
|
|
1429
|
+
};
|
|
1430
|
+
let tx = new TxSubmitter(client, client.tx.vaults.create(vaultParams), keypair);
|
|
1431
|
+
if (doNotExceedBalance) {
|
|
1432
|
+
const finalTip = _nullishCoalesce(tip, () => ( 0n));
|
|
1433
|
+
let txFee = await tx.feeEstimate(finalTip);
|
|
1434
|
+
while (txFee + finalTip + vaultParams.securitization > doNotExceedBalance) {
|
|
1435
|
+
vaultParams.securitization = doNotExceedBalance - txFee - finalTip;
|
|
1436
|
+
tx.tx = client.tx.vaults.create(vaultParams);
|
|
1437
|
+
txFee = await tx.feeEstimate(finalTip);
|
|
1377
1438
|
}
|
|
1378
1439
|
}
|
|
1379
|
-
const tx = new TxSubmitter(
|
|
1380
|
-
client,
|
|
1381
|
-
client.tx.vaults.create({
|
|
1382
|
-
terms: {
|
|
1383
|
-
// convert to fixed u128
|
|
1384
|
-
bitcoinAnnualPercentRate: toFixedNumber(annualPercentRate, 18),
|
|
1385
|
-
bitcoinBaseFee: BigInt(baseFee),
|
|
1386
|
-
liquidityPoolProfitSharing: toFixedNumber(args.liquidityPoolProfitSharing, 6)
|
|
1387
|
-
},
|
|
1388
|
-
securitizationRatio: toFixedNumber(securitizationRatio, 18),
|
|
1389
|
-
securitization: BigInt(securitization),
|
|
1390
|
-
bitcoinXpubkey: xpubBytes
|
|
1391
|
-
}),
|
|
1392
|
-
keypair
|
|
1393
|
-
);
|
|
1394
1440
|
const canAfford = await tx.canAfford({ tip, unavailableBalance: BigInt(securitization) });
|
|
1395
1441
|
if (!canAfford.canAfford) {
|
|
1396
1442
|
throw new Error(
|
|
1397
1443
|
`Insufficient balance to create vault. Required: ${formatArgons(securitization)}, Available: ${formatArgons(canAfford.availableBalance)}`
|
|
1398
1444
|
);
|
|
1399
1445
|
}
|
|
1400
|
-
const result = await tx.submit({
|
|
1446
|
+
const result = await tx.submit({
|
|
1447
|
+
tip,
|
|
1448
|
+
useLatestNonce: true,
|
|
1449
|
+
waitForBlock: true,
|
|
1450
|
+
onResultCallback(result2) {
|
|
1451
|
+
let percent = 0;
|
|
1452
|
+
if (result2.status.isInvalid || result2.status.isDropped || result2.status.isUsurped || result2.status.isRetracted) {
|
|
1453
|
+
percent = 1;
|
|
1454
|
+
} else if (result2.status.isReady) {
|
|
1455
|
+
percent = 0;
|
|
1456
|
+
} else if (result2.status.isBroadcast) {
|
|
1457
|
+
percent = 0.5;
|
|
1458
|
+
} else if (result2.status.isInBlock) {
|
|
1459
|
+
percent = 1;
|
|
1460
|
+
} else if (result2.status.isFinalized) {
|
|
1461
|
+
percent = 1.1;
|
|
1462
|
+
}
|
|
1463
|
+
_optionalChain([progressCallback, 'optionalCall', _58 => _58(percent, result2.status)]);
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
await result.inBlockPromise;
|
|
1401
1467
|
let vaultId;
|
|
1402
1468
|
for (const event of result.events) {
|
|
1403
1469
|
if (client.events.vaults.VaultCreated.is(event)) {
|
|
@@ -1412,8 +1478,9 @@ var Vault = (_class8 = class _Vault {
|
|
|
1412
1478
|
if (rawVault.isNone) {
|
|
1413
1479
|
throw new Error("Vault creation failed, vault not found");
|
|
1414
1480
|
}
|
|
1415
|
-
const tickDuration = await _asyncNullishCoalesce(
|
|
1416
|
-
|
|
1481
|
+
const tickDuration = await _asyncNullishCoalesce(config2.tickDurationMillis, async () => ( await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber())));
|
|
1482
|
+
const vault = new _Vault(vaultId, rawVault.unwrap(), tickDuration);
|
|
1483
|
+
return { vault, txResult: result };
|
|
1417
1484
|
}
|
|
1418
1485
|
}, _class8);
|
|
1419
1486
|
|
|
@@ -1465,7 +1532,7 @@ var VaultMonitor = (_class9 = class {
|
|
|
1465
1532
|
const client = await this.mainchain;
|
|
1466
1533
|
this.tickDuration = (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();
|
|
1467
1534
|
const blockHeader = await client.rpc.chain.getHeader();
|
|
1468
|
-
const blockHash =
|
|
1535
|
+
const blockHash = new Uint8Array(blockHeader.hash);
|
|
1469
1536
|
console.log(
|
|
1470
1537
|
`${justPrint ? "Run" : "Started"} at block ${blockHeader.number} - ${blockHeader.hash.toHuman()}`
|
|
1471
1538
|
);
|
|
@@ -1590,151 +1657,13 @@ var VaultMonitor = (_class9 = class {
|
|
|
1590
1657
|
}
|
|
1591
1658
|
}, _class9);
|
|
1592
1659
|
|
|
1593
|
-
// src/CohortBidderHistory.ts
|
|
1594
|
-
var CohortBidderHistory = (_class10 = class _CohortBidderHistory {
|
|
1595
|
-
constructor(cohortStartingFrameId, subaccounts) {;_class10.prototype.__init19.call(this);_class10.prototype.__init20.call(this);_class10.prototype.__init21.call(this);_class10.prototype.__init22.call(this);_class10.prototype.__init23.call(this);
|
|
1596
|
-
this.cohortStartingFrameId = cohortStartingFrameId;
|
|
1597
|
-
this.subaccounts = subaccounts;
|
|
1598
|
-
this.maxSeatsInPlay = this.subaccounts.length;
|
|
1599
|
-
this.subaccounts.forEach((x) => {
|
|
1600
|
-
this.myAddresses.add(x.address);
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
__init19() {this.bidHistory = []}
|
|
1604
|
-
__init20() {this.stats = {
|
|
1605
|
-
// number of seats won
|
|
1606
|
-
seatsWon: 0,
|
|
1607
|
-
// sum of argons bid in successful bids
|
|
1608
|
-
totalArgonsBid: 0n,
|
|
1609
|
-
// total number of bids placed (includes 1 per seat)
|
|
1610
|
-
bidsAttempted: 0,
|
|
1611
|
-
// fees including the tip
|
|
1612
|
-
fees: 0n,
|
|
1613
|
-
// Max bid per seat
|
|
1614
|
-
maxBidPerSeat: 0n,
|
|
1615
|
-
// The cost in argonots of each seat
|
|
1616
|
-
argonotsPerSeat: 0n,
|
|
1617
|
-
// The argonot price in USD for cost basis
|
|
1618
|
-
argonotUsdPrice: 0,
|
|
1619
|
-
// The cohort expected argons per block
|
|
1620
|
-
cohortArgonsPerBlock: 0n,
|
|
1621
|
-
// The last block that bids are synced to
|
|
1622
|
-
lastBlockNumber: 0
|
|
1623
|
-
}}
|
|
1624
|
-
__init21() {this.lastBids = []}
|
|
1625
|
-
__init22() {this.myAddresses = /* @__PURE__ */ new Set()}
|
|
1626
|
-
__init23() {this.maxSeatsInPlay = 0}
|
|
1627
|
-
async init(client) {
|
|
1628
|
-
if (!this.stats.argonotsPerSeat) {
|
|
1629
|
-
const startingStats = await _CohortBidderHistory.getStartingData(client);
|
|
1630
|
-
Object.assign(this.stats, startingStats);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
maybeReducingSeats(maxSeats, reason, historyEntry) {
|
|
1634
|
-
if (this.maxSeatsInPlay > maxSeats) {
|
|
1635
|
-
historyEntry.maxSeatsReductionReason = reason;
|
|
1636
|
-
}
|
|
1637
|
-
this.maxSeatsInPlay = maxSeats;
|
|
1638
|
-
historyEntry.maxSeatsInPlay = maxSeats;
|
|
1639
|
-
}
|
|
1640
|
-
trackChange(next, blockNumber, tick, isLastEntry = false) {
|
|
1641
|
-
let winningBids = 0;
|
|
1642
|
-
let totalArgonsBid = 0n;
|
|
1643
|
-
const nextEntrants = [];
|
|
1644
|
-
for (const x of next) {
|
|
1645
|
-
const bid = x.bid.toBigInt();
|
|
1646
|
-
const address = x.accountId.toHuman();
|
|
1647
|
-
nextEntrants.push({ address, bid });
|
|
1648
|
-
if (this.myAddresses.has(address)) {
|
|
1649
|
-
winningBids++;
|
|
1650
|
-
totalArgonsBid += bid;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
this.stats.seatsWon = winningBids;
|
|
1654
|
-
this.stats.totalArgonsBid = totalArgonsBid;
|
|
1655
|
-
this.stats.lastBlockNumber = Math.max(blockNumber, this.stats.lastBlockNumber);
|
|
1656
|
-
const historyEntry = {
|
|
1657
|
-
cohortStartingFrameId: this.cohortStartingFrameId,
|
|
1658
|
-
blockNumber,
|
|
1659
|
-
tick,
|
|
1660
|
-
bidChanges: [],
|
|
1661
|
-
winningSeats: winningBids,
|
|
1662
|
-
maxSeatsInPlay: this.maxSeatsInPlay
|
|
1663
|
-
};
|
|
1664
|
-
const hasDiffs = JsonExt.stringify(nextEntrants) !== JsonExt.stringify(this.lastBids);
|
|
1665
|
-
if (!isLastEntry || hasDiffs) {
|
|
1666
|
-
this.bidHistory.unshift(historyEntry);
|
|
1667
|
-
}
|
|
1668
|
-
if (hasDiffs) {
|
|
1669
|
-
nextEntrants.forEach(({ address, bid }, i) => {
|
|
1670
|
-
const prevBidIndex = this.lastBids.findIndex((y) => y.address === address);
|
|
1671
|
-
const entry = {
|
|
1672
|
-
address,
|
|
1673
|
-
bidAmount: bid,
|
|
1674
|
-
bidPosition: i,
|
|
1675
|
-
prevPosition: prevBidIndex === -1 ? null : prevBidIndex
|
|
1676
|
-
};
|
|
1677
|
-
if (prevBidIndex !== -1) {
|
|
1678
|
-
const prevBidAmount = this.lastBids[prevBidIndex].bid;
|
|
1679
|
-
if (prevBidAmount !== bid) {
|
|
1680
|
-
entry.prevBidAmount = prevBidAmount;
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
historyEntry.bidChanges.push(entry);
|
|
1684
|
-
});
|
|
1685
|
-
this.lastBids.forEach(({ address, bid }, i) => {
|
|
1686
|
-
const nextBid = nextEntrants.some((y) => y.address === address);
|
|
1687
|
-
if (!nextBid) {
|
|
1688
|
-
historyEntry.bidChanges.push({
|
|
1689
|
-
address,
|
|
1690
|
-
bidAmount: bid,
|
|
1691
|
-
bidPosition: null,
|
|
1692
|
-
prevPosition: i
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
this.lastBids = nextEntrants;
|
|
1697
|
-
}
|
|
1698
|
-
return historyEntry;
|
|
1699
|
-
}
|
|
1700
|
-
onBidResult(historyEntry, param) {
|
|
1701
|
-
const { txFeePlusTip, bidPerSeat, bidsAttempted, successfulBids, blockNumber, bidError } = param;
|
|
1702
|
-
this.stats.fees += txFeePlusTip;
|
|
1703
|
-
this.stats.bidsAttempted += bidsAttempted;
|
|
1704
|
-
if (bidPerSeat > this.stats.maxBidPerSeat) {
|
|
1705
|
-
this.stats.maxBidPerSeat = bidPerSeat;
|
|
1706
|
-
}
|
|
1707
|
-
if (blockNumber !== void 0) {
|
|
1708
|
-
this.stats.lastBlockNumber = Math.max(blockNumber, this.stats.lastBlockNumber);
|
|
1709
|
-
}
|
|
1710
|
-
if (historyEntry.myBidsPlaced) {
|
|
1711
|
-
historyEntry.myBidsPlaced.failureReason = bidError;
|
|
1712
|
-
historyEntry.myBidsPlaced.successfulBids = successfulBids;
|
|
1713
|
-
historyEntry.myBidsPlaced.txFeePlusTip = txFeePlusTip;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
static async getStartingData(api) {
|
|
1717
|
-
const argonotPrice = await api.query.priceIndex.current();
|
|
1718
|
-
let argonotUsdPrice = 0;
|
|
1719
|
-
if (argonotPrice.isSome) {
|
|
1720
|
-
argonotUsdPrice = convertFixedU128ToBigNumber(
|
|
1721
|
-
argonotPrice.unwrap().argonotUsdPrice.toBigInt()
|
|
1722
|
-
).toNumber();
|
|
1723
|
-
}
|
|
1724
|
-
const argonotsPerSeat = await api.query.miningSlot.argonotsPerMiningSeat().then((x) => x.toBigInt());
|
|
1725
|
-
const cohortArgonsPerBlock = await api.query.blockRewards.argonsPerBlock().then((x) => x.toBigInt());
|
|
1726
|
-
return { argonotsPerSeat, argonotUsdPrice, cohortArgonsPerBlock };
|
|
1727
|
-
}
|
|
1728
|
-
}, _class10);
|
|
1729
|
-
|
|
1730
1660
|
// src/CohortBidder.ts
|
|
1731
|
-
var CohortBidder = (
|
|
1732
|
-
constructor(accountset, cohortStartingFrameId, subaccounts, options) {;
|
|
1661
|
+
var CohortBidder = (_class10 = class {
|
|
1662
|
+
constructor(accountset, cohortStartingFrameId, subaccounts, options) {;_class10.prototype.__init19.call(this);_class10.prototype.__init20.call(this);_class10.prototype.__init21.call(this);_class10.prototype.__init22.call(this);_class10.prototype.__init23.call(this);_class10.prototype.__init24.call(this);_class10.prototype.__init25.call(this);_class10.prototype.__init26.call(this);
|
|
1733
1663
|
this.accountset = accountset;
|
|
1734
1664
|
this.cohortStartingFrameId = cohortStartingFrameId;
|
|
1735
1665
|
this.subaccounts = subaccounts;
|
|
1736
1666
|
this.options = options;
|
|
1737
|
-
this.history = new CohortBidderHistory(cohortStartingFrameId, subaccounts);
|
|
1738
1667
|
this.subaccounts.forEach((x) => {
|
|
1739
1668
|
this.myAddresses.add(x.address);
|
|
1740
1669
|
});
|
|
@@ -1742,23 +1671,52 @@ var CohortBidder = (_class11 = class {
|
|
|
1742
1671
|
get client() {
|
|
1743
1672
|
return this.accountset.client;
|
|
1744
1673
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
}
|
|
1748
|
-
get bidHistory() {
|
|
1749
|
-
return this.history.bidHistory;
|
|
1750
|
-
}
|
|
1674
|
+
__init19() {this.txFees = 0n}
|
|
1675
|
+
__init20() {this.winningBids = []}
|
|
1751
1676
|
|
|
1752
1677
|
|
|
1753
1678
|
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1679
|
+
__init21() {this.isStopped = false}
|
|
1680
|
+
__init22() {this.needsRebid = false}
|
|
1681
|
+
__init23() {this.lastBidTime = 0}
|
|
1757
1682
|
|
|
1683
|
+
__init24() {this.minIncrement = 10000n}
|
|
1758
1684
|
|
|
1759
|
-
|
|
1685
|
+
__init25() {this.lastBidBlockNumber = 0}
|
|
1686
|
+
__init26() {this.myAddresses = /* @__PURE__ */ new Set()}
|
|
1687
|
+
async start() {
|
|
1688
|
+
console.log(`Starting cohort ${this.cohortStartingFrameId} bidder`, {
|
|
1689
|
+
maxBid: formatArgons(this.options.maxBid),
|
|
1690
|
+
minBid: formatArgons(this.options.minBid),
|
|
1691
|
+
bidIncrement: formatArgons(this.options.bidIncrement),
|
|
1692
|
+
maxBudget: formatArgons(this.options.maxBudget),
|
|
1693
|
+
bidDelay: this.options.bidDelay,
|
|
1694
|
+
subaccounts: this.subaccounts
|
|
1695
|
+
});
|
|
1696
|
+
const client = await this.client;
|
|
1697
|
+
this.minIncrement = client.consts.miningSlot.bidIncrements.toBigInt();
|
|
1698
|
+
this.nextCohortSize = await client.query.miningSlot.nextCohortSize().then((x) => x.toNumber());
|
|
1699
|
+
if (this.subaccounts.length > this.nextCohortSize) {
|
|
1700
|
+
console.info(
|
|
1701
|
+
`Cohort size ${this.nextCohortSize} is less than provided subaccounts ${this.subaccounts.length}.`
|
|
1702
|
+
);
|
|
1703
|
+
this.subaccounts.length = this.nextCohortSize;
|
|
1704
|
+
}
|
|
1705
|
+
this.millisPerTick = await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber());
|
|
1706
|
+
this.unsubscribe = await client.queryMulti(
|
|
1707
|
+
[
|
|
1708
|
+
client.query.miningSlot.bidsForNextSlotCohort,
|
|
1709
|
+
client.query.miningSlot.nextFrameId
|
|
1710
|
+
],
|
|
1711
|
+
async ([bids, nextFrameId]) => {
|
|
1712
|
+
if (nextFrameId.toNumber() === this.cohortStartingFrameId) {
|
|
1713
|
+
await this.checkWinningBids(bids);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1760
1718
|
async stop() {
|
|
1761
|
-
if (this.isStopped) return this.
|
|
1719
|
+
if (this.isStopped) return this.winningBids;
|
|
1762
1720
|
this.isStopped = true;
|
|
1763
1721
|
console.log("Stopping bidder for cohort", this.cohortStartingFrameId);
|
|
1764
1722
|
clearTimeout(this.retryTimeout);
|
|
@@ -1783,79 +1741,47 @@ var CohortBidder = (_class11 = class {
|
|
|
1783
1741
|
}
|
|
1784
1742
|
void await this.pendingRequest;
|
|
1785
1743
|
let header = await client.rpc.chain.getHeader();
|
|
1744
|
+
let api = await client.at(header.hash);
|
|
1786
1745
|
while (true) {
|
|
1787
|
-
const
|
|
1788
|
-
const cohortStartingFrameId = await api2.query.miningSlot.nextFrameId();
|
|
1746
|
+
const cohortStartingFrameId = await api.query.miningSlot.nextFrameId();
|
|
1789
1747
|
if (cohortStartingFrameId.toNumber() === this.cohortStartingFrameId) {
|
|
1790
1748
|
break;
|
|
1791
1749
|
}
|
|
1792
1750
|
header = await client.rpc.chain.getHeader(header.parentHash);
|
|
1751
|
+
api = await client.at(header.hash);
|
|
1793
1752
|
}
|
|
1794
|
-
const api = await client.at(header.hash);
|
|
1795
|
-
const tick = await api.query.ticks.currentTick().then((x) => x.toNumber());
|
|
1796
1753
|
const bids = await api.query.miningSlot.bidsForNextSlotCohort();
|
|
1797
|
-
this.
|
|
1754
|
+
this.updateSeatsWon(bids);
|
|
1798
1755
|
console.log("Bidder stopped", {
|
|
1799
1756
|
cohortStartingFrameId: this.cohortStartingFrameId,
|
|
1800
1757
|
blockNumber: header.number.toNumber(),
|
|
1801
|
-
|
|
1802
|
-
bids: bids.map((x) => ({
|
|
1803
|
-
address: x.accountId.toHuman(),
|
|
1804
|
-
bid: x.bid.toBigInt()
|
|
1805
|
-
}))
|
|
1758
|
+
bids: this.winningBids
|
|
1806
1759
|
});
|
|
1807
|
-
return this.
|
|
1808
|
-
}
|
|
1809
|
-
async start() {
|
|
1810
|
-
console.log(`Starting cohort ${this.cohortStartingFrameId} bidder`, {
|
|
1811
|
-
maxBid: formatArgons(this.options.maxBid),
|
|
1812
|
-
minBid: formatArgons(this.options.minBid),
|
|
1813
|
-
bidIncrement: formatArgons(this.options.bidIncrement),
|
|
1814
|
-
maxBudget: formatArgons(this.options.maxBudget),
|
|
1815
|
-
bidDelay: this.options.bidDelay,
|
|
1816
|
-
subaccounts: this.subaccounts
|
|
1817
|
-
});
|
|
1818
|
-
const client = await this.client;
|
|
1819
|
-
await this.history.init(client);
|
|
1820
|
-
this.millisPerTick ??= await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber());
|
|
1821
|
-
this.unsubscribe = await client.queryMulti(
|
|
1822
|
-
[
|
|
1823
|
-
client.query.miningSlot.bidsForNextSlotCohort,
|
|
1824
|
-
client.query.miningSlot.nextFrameId
|
|
1825
|
-
],
|
|
1826
|
-
async ([bids, nextFrameId]) => {
|
|
1827
|
-
if (nextFrameId.toNumber() === this.cohortStartingFrameId) {
|
|
1828
|
-
await this.checkWinningBids(bids);
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
);
|
|
1760
|
+
return this.winningBids;
|
|
1832
1761
|
}
|
|
1833
1762
|
async checkWinningBids(bids) {
|
|
1834
1763
|
if (this.isStopped) return;
|
|
1835
1764
|
clearTimeout(this.retryTimeout);
|
|
1765
|
+
this.updateSeatsWon(bids);
|
|
1766
|
+
const winningBids = this.winningBids.length;
|
|
1767
|
+
this.needsRebid = winningBids < this.subaccounts.length;
|
|
1836
1768
|
const client = await this.client;
|
|
1837
1769
|
const bestBlock = await client.rpc.chain.getBlockHash();
|
|
1838
1770
|
const api = await client.at(bestBlock);
|
|
1839
1771
|
const blockNumber = await api.query.system.number().then((x) => x.toNumber());
|
|
1840
|
-
if (
|
|
1841
|
-
return;
|
|
1842
|
-
}
|
|
1843
|
-
const tick = await api.query.ticks.currentTick().then((x) => x.toNumber());
|
|
1844
|
-
const historyEntry = this.history.trackChange(bids, blockNumber, tick);
|
|
1772
|
+
if (this.lastBidBlockNumber >= blockNumber) return;
|
|
1845
1773
|
if (this.pendingRequest) return;
|
|
1846
1774
|
const ticksSinceLastBid = Math.floor((Date.now() - this.lastBidTime) / this.millisPerTick);
|
|
1847
|
-
if (ticksSinceLastBid < this.options.bidDelay) {
|
|
1775
|
+
if (ticksSinceLastBid < this.options.bidDelay && this.needsRebid) {
|
|
1848
1776
|
this.retryTimeout = setTimeout(() => void this.checkCurrentSeats(), this.millisPerTick);
|
|
1849
1777
|
return;
|
|
1850
1778
|
}
|
|
1779
|
+
if (!this.needsRebid) return;
|
|
1851
1780
|
console.log(
|
|
1852
1781
|
"Checking bids for cohort",
|
|
1853
1782
|
this.cohortStartingFrameId,
|
|
1854
1783
|
this.subaccounts.map((x) => x.index)
|
|
1855
1784
|
);
|
|
1856
|
-
const winningBids = historyEntry.winningSeats;
|
|
1857
|
-
this.needsRebid = winningBids < this.subaccounts.length;
|
|
1858
|
-
if (!this.needsRebid) return;
|
|
1859
1785
|
const winningAddresses = new Set(bids.map((x) => x.accountId.toHuman()));
|
|
1860
1786
|
let lowestBid = -this.options.bidIncrement;
|
|
1861
1787
|
if (bids.length) {
|
|
@@ -1866,7 +1792,6 @@ var CohortBidder = (_class11 = class {
|
|
|
1866
1792
|
}
|
|
1867
1793
|
}
|
|
1868
1794
|
}
|
|
1869
|
-
const MIN_INCREMENT = 10000n;
|
|
1870
1795
|
let nextBid = lowestBid + this.options.bidIncrement;
|
|
1871
1796
|
if (nextBid < this.options.minBid) {
|
|
1872
1797
|
nextBid = this.options.minBid;
|
|
@@ -1895,10 +1820,9 @@ var CohortBidder = (_class11 = class {
|
|
|
1895
1820
|
console.log(
|
|
1896
1821
|
`Can't bid ${formatArgons(nextBid)}. Current lowest bid is ${formatArgons(lowestBid)}.`
|
|
1897
1822
|
);
|
|
1898
|
-
this.history.maybeReducingSeats(winningBids, "MaxBidTooLow" /* MaxBidTooLow */, historyEntry);
|
|
1899
1823
|
return;
|
|
1900
1824
|
}
|
|
1901
|
-
if (nextBid - lowestBid <
|
|
1825
|
+
if (nextBid - lowestBid < Number(this.minIncrement)) {
|
|
1902
1826
|
console.log(
|
|
1903
1827
|
`Can't make any more bids for ${this.cohortStartingFrameId} with given constraints.`,
|
|
1904
1828
|
{
|
|
@@ -1907,14 +1831,11 @@ var CohortBidder = (_class11 = class {
|
|
|
1907
1831
|
maxBid: formatArgons(this.options.maxBid)
|
|
1908
1832
|
}
|
|
1909
1833
|
);
|
|
1910
|
-
this.history.maybeReducingSeats(winningBids, "MaxBidTooLow" /* MaxBidTooLow */, historyEntry);
|
|
1911
1834
|
return;
|
|
1912
1835
|
}
|
|
1913
1836
|
const seatsInBudget = nextBid === 0n ? this.subaccounts.length : Number(budgetForSeats / nextBid);
|
|
1914
1837
|
let accountsToUse = [...this.subaccounts];
|
|
1915
1838
|
if (accountsToUse.length > seatsInBudget) {
|
|
1916
|
-
const reason = availableBalanceForBids - feePlusTip < nextBid * BigInt(seatsInBudget) ? "InsufficientFunds" /* InsufficientFunds */ : "MaxBudgetTooLow" /* MaxBudgetTooLow */;
|
|
1917
|
-
this.history.maybeReducingSeats(seatsInBudget, reason, historyEntry);
|
|
1918
1839
|
accountsToUse.sort((a, b) => {
|
|
1919
1840
|
const isWinningA = winningAddresses.has(a.address);
|
|
1920
1841
|
const isWinningB = winningAddresses.has(b.address);
|
|
@@ -1927,19 +1848,11 @@ var CohortBidder = (_class11 = class {
|
|
|
1927
1848
|
accountsToUse.length = seatsInBudget;
|
|
1928
1849
|
}
|
|
1929
1850
|
if (accountsToUse.length > winningBids) {
|
|
1930
|
-
|
|
1931
|
-
bids: accountsToUse.length,
|
|
1932
|
-
bidPerSeat: nextBid,
|
|
1933
|
-
txFeePlusTip: feePlusTip,
|
|
1934
|
-
successfulBids: 0
|
|
1935
|
-
};
|
|
1936
|
-
this.pendingRequest = this.bid(nextBid, accountsToUse, historyEntry);
|
|
1937
|
-
} else if (historyEntry.bidChanges.length === 0) {
|
|
1938
|
-
this.history.bidHistory.shift();
|
|
1851
|
+
this.pendingRequest = this.bid(nextBid, accountsToUse);
|
|
1939
1852
|
}
|
|
1940
1853
|
this.needsRebid = false;
|
|
1941
1854
|
}
|
|
1942
|
-
async bid(bidPerSeat, subaccounts
|
|
1855
|
+
async bid(bidPerSeat, subaccounts) {
|
|
1943
1856
|
const prevLastBidTime = this.lastBidTime;
|
|
1944
1857
|
try {
|
|
1945
1858
|
this.lastBidTime = Date.now();
|
|
@@ -1960,14 +1873,10 @@ var CohortBidder = (_class11 = class {
|
|
|
1960
1873
|
blockNumber = await api.query.system.number().then((x) => x.toNumber());
|
|
1961
1874
|
}
|
|
1962
1875
|
const successfulBids = _nullishCoalesce(txResult.batchInterruptedIndex, () => ( subaccounts.length));
|
|
1963
|
-
this.
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
txFeePlusTip: _nullishCoalesce(txResult.finalFee, () => ( 0n)),
|
|
1968
|
-
bidsAttempted: subaccounts.length,
|
|
1969
|
-
bidError
|
|
1970
|
-
});
|
|
1876
|
+
this.txFees += _nullishCoalesce(txResult.finalFee, () => ( 0n));
|
|
1877
|
+
if (blockNumber !== void 0) {
|
|
1878
|
+
this.lastBidBlockNumber = Math.max(blockNumber, this.lastBidBlockNumber);
|
|
1879
|
+
}
|
|
1971
1880
|
console.log("Done creating bids for cohort", {
|
|
1972
1881
|
successfulBids,
|
|
1973
1882
|
bidPerSeat,
|
|
@@ -1987,12 +1896,22 @@ var CohortBidder = (_class11 = class {
|
|
|
1987
1896
|
await this.checkCurrentSeats();
|
|
1988
1897
|
}
|
|
1989
1898
|
}
|
|
1899
|
+
updateSeatsWon(next) {
|
|
1900
|
+
this.winningBids.length = 0;
|
|
1901
|
+
for (const x of next) {
|
|
1902
|
+
const bid = x.bid.toBigInt();
|
|
1903
|
+
const address = x.accountId.toHuman();
|
|
1904
|
+
if (this.myAddresses.has(address)) {
|
|
1905
|
+
this.winningBids.push({ address, bid });
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1990
1909
|
async checkCurrentSeats() {
|
|
1991
1910
|
const client = await this.client;
|
|
1992
1911
|
const bids = await client.query.miningSlot.bidsForNextSlotCohort();
|
|
1993
1912
|
await this.checkWinningBids(bids);
|
|
1994
1913
|
}
|
|
1995
|
-
},
|
|
1914
|
+
}, _class10);
|
|
1996
1915
|
|
|
1997
1916
|
// src/BidPool.ts
|
|
1998
1917
|
|
|
@@ -2003,23 +1922,23 @@ var EMPTY_TABLE = {
|
|
|
2003
1922
|
tableBottom: { left: " ", mid: " ", other: " ", right: " " },
|
|
2004
1923
|
vertical: " "
|
|
2005
1924
|
};
|
|
2006
|
-
var BidPool = (
|
|
2007
|
-
constructor(client, keypair, accountRegistry = AccountRegistry.factory()) {;
|
|
1925
|
+
var BidPool = (_class11 = class {
|
|
1926
|
+
constructor(client, keypair, accountRegistry = AccountRegistry.factory()) {;_class11.prototype.__init27.call(this);_class11.prototype.__init28.call(this);_class11.prototype.__init29.call(this);_class11.prototype.__init30.call(this);_class11.prototype.__init31.call(this);_class11.prototype.__init32.call(this);
|
|
2008
1927
|
this.client = client;
|
|
2009
1928
|
this.keypair = keypair;
|
|
2010
1929
|
this.accountRegistry = accountRegistry;
|
|
2011
1930
|
this.blockWatch = new BlockWatch(client, { shouldLog: false });
|
|
2012
1931
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
1932
|
+
__init27() {this.bidPoolAmount = 0n}
|
|
1933
|
+
__init28() {this.nextFrameId = 1}
|
|
1934
|
+
__init29() {this.poolVaultCapitalByFrame = {}}
|
|
1935
|
+
__init30() {this.vaultSecuritization = []}
|
|
2017
1936
|
|
|
2018
1937
|
|
|
2019
|
-
|
|
1938
|
+
__init31() {this.vaultsById = {}}
|
|
2020
1939
|
|
|
2021
1940
|
|
|
2022
|
-
|
|
1941
|
+
__init32() {this.FrameSubscriptions = {}}
|
|
2023
1942
|
async onVaultsUpdated(blockHash, vaultIdSet) {
|
|
2024
1943
|
const client = await this.client;
|
|
2025
1944
|
this.tickDuration ??= (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();
|
|
@@ -2059,7 +1978,7 @@ var BidPool = (_class12 = class {
|
|
|
2059
1978
|
}
|
|
2060
1979
|
async loadAt(blockHash) {
|
|
2061
1980
|
const client = await this.client;
|
|
2062
|
-
blockHash ??=
|
|
1981
|
+
blockHash ??= new Uint8Array((await client.rpc.chain.getHeader()).hash);
|
|
2063
1982
|
const api = await client.at(blockHash);
|
|
2064
1983
|
const rawVaultIds = await api.query.vaults.vaultsById.keys();
|
|
2065
1984
|
const vaultIds = rawVaultIds.map((x) => x.args[0].toNumber());
|
|
@@ -2325,9 +2244,10 @@ Raising Funds (Frame ${this.nextFrameId + 1}):`);
|
|
|
2325
2244
|
});
|
|
2326
2245
|
}
|
|
2327
2246
|
}
|
|
2328
|
-
},
|
|
2247
|
+
}, _class11);
|
|
2329
2248
|
|
|
2330
2249
|
// src/BitcoinLocks.ts
|
|
2250
|
+
|
|
2331
2251
|
var SATS_PER_BTC = 100000000n;
|
|
2332
2252
|
var BitcoinLocks = class _BitcoinLocks {
|
|
2333
2253
|
constructor(client) {
|
|
@@ -2387,7 +2307,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2387
2307
|
async getUtxoRef(utxoId, atHeight) {
|
|
2388
2308
|
let client = await this.client;
|
|
2389
2309
|
if (atHeight !== void 0) {
|
|
2390
|
-
const blockHash = await client.
|
|
2310
|
+
const blockHash = await client.rpc.chain.getBlockHash(atHeight);
|
|
2391
2311
|
client = await client.at(blockHash);
|
|
2392
2312
|
}
|
|
2393
2313
|
const refRaw = await client.query.bitcoinUtxos.utxoIdToRef(utxoId);
|
|
@@ -2395,15 +2315,15 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2395
2315
|
return;
|
|
2396
2316
|
}
|
|
2397
2317
|
const ref = refRaw.unwrap();
|
|
2398
|
-
const txid =
|
|
2399
|
-
const
|
|
2318
|
+
const txid = _util.u8aToHex.call(void 0, ref.txid);
|
|
2319
|
+
const bitcoinTxid = _util.u8aToHex.call(void 0, ref.txid.reverse());
|
|
2400
2320
|
const vout = ref.outputIndex.toNumber();
|
|
2401
|
-
return { txid
|
|
2321
|
+
return { txid, vout, bitcoinTxid };
|
|
2402
2322
|
}
|
|
2403
2323
|
async getReleaseRequest(utxoId, atHeight) {
|
|
2404
2324
|
let client = await this.client;
|
|
2405
2325
|
if (atHeight !== void 0) {
|
|
2406
|
-
const blockHash = await client.
|
|
2326
|
+
const blockHash = await client.rpc.chain.getBlockHash(atHeight);
|
|
2407
2327
|
client = await client.at(blockHash);
|
|
2408
2328
|
}
|
|
2409
2329
|
const locksPendingRelease = await client.query.bitcoinLocks.locksPendingReleaseByUtxoId();
|
|
@@ -2423,15 +2343,15 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2423
2343
|
async submitVaultSignature(args) {
|
|
2424
2344
|
const { utxoId, vaultSignature, argonKeyring } = args;
|
|
2425
2345
|
const client = await this.client;
|
|
2426
|
-
if (!vaultSignature || vaultSignature.byteLength <
|
|
2346
|
+
if (!vaultSignature || vaultSignature.byteLength < 70 || vaultSignature.byteLength > 73) {
|
|
2427
2347
|
throw new Error(
|
|
2428
|
-
`Invalid vault signature length: ${vaultSignature.byteLength}. Must be
|
|
2348
|
+
`Invalid vault signature length: ${vaultSignature.byteLength}. Must be 70-73 bytes.`
|
|
2429
2349
|
);
|
|
2430
2350
|
}
|
|
2431
|
-
const signature =
|
|
2351
|
+
const signature = _util.u8aToHex.call(void 0, vaultSignature);
|
|
2432
2352
|
const tx = client.tx.bitcoinLocks.cosignRelease(utxoId, signature);
|
|
2433
2353
|
const submitter = new TxSubmitter(client, tx, argonKeyring);
|
|
2434
|
-
return await submitter.submit(
|
|
2354
|
+
return await submitter.submit();
|
|
2435
2355
|
}
|
|
2436
2356
|
async getBitcoinLock(utxoId) {
|
|
2437
2357
|
const client = await this.client;
|
|
@@ -2452,7 +2372,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2452
2372
|
const ownerPubkey = utxo.ownerPubkey.toHex();
|
|
2453
2373
|
const [fingerprint, cosign_hd_index, claim_hd_index] = utxo.vaultXpubSources;
|
|
2454
2374
|
const vaultXpubSources = {
|
|
2455
|
-
parentFingerprint:
|
|
2375
|
+
parentFingerprint: new Uint8Array(fingerprint),
|
|
2456
2376
|
cosignHdIndex: cosign_hd_index.toNumber(),
|
|
2457
2377
|
claimHdIndex: claim_hd_index.toNumber()
|
|
2458
2378
|
};
|
|
@@ -2534,7 +2454,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2534
2454
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
2535
2455
|
continue;
|
|
2536
2456
|
}
|
|
2537
|
-
const hash = await client.
|
|
2457
|
+
const hash = await client.rpc.chain.getBlockHash(atHeight).then((x) => x.toHex());
|
|
2538
2458
|
if (hash === "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2539
2459
|
console.warn(`Block hash not found for height ${atHeight}. Retrying...`);
|
|
2540
2460
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -2556,7 +2476,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2556
2476
|
if (client.events.bitcoinLocks.BitcoinUtxoCosigned.is(event.event)) {
|
|
2557
2477
|
const { utxoId: id, signature } = event.event.data;
|
|
2558
2478
|
if (id.toNumber() === utxoId) {
|
|
2559
|
-
return
|
|
2479
|
+
return new Uint8Array(signature);
|
|
2560
2480
|
}
|
|
2561
2481
|
}
|
|
2562
2482
|
}
|
|
@@ -2744,7 +2664,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2744
2664
|
const vaults = new VaultMonitor(accountset, {
|
|
2745
2665
|
bitcoinSpaceAvailable: argonAmount
|
|
2746
2666
|
});
|
|
2747
|
-
const bitcoinXpubBuffer =
|
|
2667
|
+
const bitcoinXpubBuffer = _util.hexToU8a.call(void 0, bitcoinXpub);
|
|
2748
2668
|
return new Promise(async (resolve, reject) => {
|
|
2749
2669
|
vaults.events.on("bitcoin-space-above", async (vaultId, amount) => {
|
|
2750
2670
|
const vault = vaults.vaultsById[vaultId];
|
|
@@ -2801,9 +2721,32 @@ function createKeyringPair(opts) {
|
|
|
2801
2721
|
}
|
|
2802
2722
|
|
|
2803
2723
|
// src/index.ts
|
|
2804
|
-
|
|
2805
|
-
var
|
|
2806
|
-
|
|
2724
|
+
|
|
2725
|
+
var _generic = require('@polkadot/types/generic');
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
|
|
2729
|
+
|
|
2730
|
+
|
|
2731
|
+
|
|
2732
|
+
|
|
2733
|
+
|
|
2734
|
+
|
|
2735
|
+
|
|
2736
|
+
|
|
2737
|
+
|
|
2738
|
+
|
|
2739
|
+
|
|
2740
|
+
|
|
2741
|
+
|
|
2742
|
+
|
|
2743
|
+
|
|
2744
|
+
|
|
2745
|
+
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+
|
|
2749
|
+
var _typescodec = require('@polkadot/types-codec');
|
|
2807
2750
|
async function waitForLoad() {
|
|
2808
2751
|
await _utilcrypto.cryptoWaitReady.call(void 0, );
|
|
2809
2752
|
}
|
|
@@ -2861,5 +2804,34 @@ async function getClient(host) {
|
|
|
2861
2804
|
|
|
2862
2805
|
|
|
2863
2806
|
|
|
2864
|
-
|
|
2865
|
-
|
|
2807
|
+
|
|
2808
|
+
|
|
2809
|
+
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
|
|
2822
|
+
|
|
2823
|
+
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
|
|
2835
|
+
|
|
2836
|
+
exports.WageProtector = WageProtector; exports.setConfig = setConfig; exports.getConfig = getConfig; exports.TxSubmitter = TxSubmitter; exports.MICROGONS_PER_ARGON = MICROGONS_PER_ARGON; exports.formatArgons = formatArgons; exports.formatPercent = formatPercent; exports.filterUndefined = filterUndefined; exports.gettersToObject = gettersToObject; exports.toFixedNumber = toFixedNumber; exports.convertNumberToFixedU128 = convertNumberToFixedU128; exports.convertFixedU128ToBigNumber = convertFixedU128ToBigNumber; exports.convertPermillToBigNumber = convertPermillToBigNumber; exports.convertNumberToPermill = convertNumberToPermill; exports.eventDataToJson = eventDataToJson; exports.dispatchErrorToString = dispatchErrorToString; exports.ExtrinsicError = ExtrinsicError2; exports.dispatchErrorToExtrinsicError = dispatchErrorToExtrinsicError; exports.checkForExtrinsicSuccess = checkForExtrinsicSuccess; exports.JsonExt = JsonExt; exports.createNanoEvents = createNanoEvents; exports.TypedEmitter = TypedEmitter; exports.AccountRegistry = AccountRegistry; exports.getTickFromHeader = getTickFromHeader; exports.getAuthorFromHeader = getAuthorFromHeader; exports.BlockWatch = BlockWatch; exports.FrameCalculator = FrameCalculator; exports.AccountMiners = AccountMiners; exports.Accountset = Accountset; exports.parseSubaccountRange = parseSubaccountRange; exports.MiningBids = MiningBids; exports.Vault = Vault; exports.VaultMonitor = VaultMonitor; exports.CohortBidder = CohortBidder; exports.BidPool = BidPool; exports.SATS_PER_BTC = SATS_PER_BTC; exports.BitcoinLocks = BitcoinLocks; exports.keyringFromSuri = keyringFromSuri; exports.createKeyringPair = createKeyringPair; exports.Keyring = _api.Keyring; exports.decodeAddress = _utilcrypto.decodeAddress; exports.mnemonicGenerate = _utilcrypto.mnemonicGenerate; exports.waitForLoad = waitForLoad; exports.getClient = getClient; exports.u8aToHex = _util.u8aToHex; exports.hexToU8a = _util.hexToU8a; exports.u8aEq = _util.u8aEq; exports.GenericEvent = _generic.GenericEvent; exports.GenericBlock = _generic.GenericBlock; exports.GenericAddress = _generic.GenericAddress; exports.BTreeMap = _typescodec.BTreeMap; exports.Bytes = _typescodec.Bytes; exports.Compact = _typescodec.Compact; exports.Enum = _typescodec.Enum; exports.Null = _typescodec.Null; exports.Option = _typescodec.Option; exports.Result = _typescodec.Result; exports.Bool = _typescodec.Bool; exports.Tuple = _typescodec.Tuple; exports.Range = _typescodec.Range; exports.Struct = _typescodec.Struct; exports.Text = _typescodec.Text; exports.U256 = _typescodec.U256; exports.U8aFixed = _typescodec.U8aFixed; exports.Vec = _typescodec.Vec; exports.bool = _typescodec.bool; exports.i128 = _typescodec.i128; exports.u128 = _typescodec.u128; exports.u16 = _typescodec.u16; exports.u32 = _typescodec.u32; exports.u64 = _typescodec.u64; exports.u8 = _typescodec.u8;
|
|
2837
|
+
//# sourceMappingURL=chunk-OFYVHBKG.cjs.map
|