@gvnrdao/dh-mcp 0.5.7 → 0.5.9
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/dist/boundary.js +114 -23
- package/dist/connector-embed.js +114 -23
- package/dist/connector.js +114 -23
- package/dist/index.js +114 -23
- package/package.json +2 -2
package/dist/boundary.js
CHANGED
|
@@ -17342,11 +17342,11 @@ ${auth.clientId}`;
|
|
|
17342
17342
|
);
|
|
17343
17343
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
17344
17344
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
17345
|
-
let
|
|
17345
|
+
let median2;
|
|
17346
17346
|
if (this.devSingleProvider) {
|
|
17347
|
-
|
|
17347
|
+
median2 = sorted[0];
|
|
17348
17348
|
} else {
|
|
17349
|
-
|
|
17349
|
+
median2 = sorted[1];
|
|
17350
17350
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
17351
17351
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
17352
17352
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -17356,10 +17356,10 @@ ${auth.clientId}`;
|
|
|
17356
17356
|
);
|
|
17357
17357
|
}
|
|
17358
17358
|
}
|
|
17359
|
-
const priceCents = Math.round(
|
|
17359
|
+
const priceCents = Math.round(median2 * 100);
|
|
17360
17360
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
17361
17361
|
const totalElapsed = Date.now() - startTime;
|
|
17362
|
-
console.log(`[Price Oracle] Median price: $${
|
|
17362
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
17363
17363
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
17364
17364
|
return priceWith8Decimals;
|
|
17365
17365
|
}
|
|
@@ -55394,11 +55394,11 @@ ${auth.clientId}`;
|
|
|
55394
55394
|
);
|
|
55395
55395
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
55396
55396
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
55397
|
-
let
|
|
55397
|
+
let median2;
|
|
55398
55398
|
if (this.devSingleProvider) {
|
|
55399
|
-
|
|
55399
|
+
median2 = sorted[0];
|
|
55400
55400
|
} else {
|
|
55401
|
-
|
|
55401
|
+
median2 = sorted[1];
|
|
55402
55402
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
55403
55403
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
55404
55404
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -55408,10 +55408,10 @@ ${auth.clientId}`;
|
|
|
55408
55408
|
);
|
|
55409
55409
|
}
|
|
55410
55410
|
}
|
|
55411
|
-
const priceCents = Math.round(
|
|
55411
|
+
const priceCents = Math.round(median2 * 100);
|
|
55412
55412
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
55413
55413
|
const totalElapsed = Date.now() - startTime;
|
|
55414
|
-
console.log(`[Price Oracle] Median price: $${
|
|
55414
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
55415
55415
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
55416
55416
|
return priceWith8Decimals;
|
|
55417
55417
|
}
|
|
@@ -57176,26 +57176,83 @@ var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
|
57176
57176
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
57177
57177
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
57178
57178
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
57179
|
-
|
|
57180
|
-
|
|
57181
|
-
|
|
57182
|
-
|
|
57183
|
-
|
|
57184
|
-
|
|
57185
|
-
|
|
57186
|
-
|
|
57187
|
-
|
|
57188
|
-
|
|
57189
|
-
|
|
57179
|
+
var PRIORITY_FEE_FLOOR_WEI = (0, import_ethers14.parseUnits)("0.1", "gwei");
|
|
57180
|
+
var PRIORITY_FEE_CAP_WEI = (0, import_ethers14.parseUnits)("3", "gwei");
|
|
57181
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
57182
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
57183
|
+
function isJsonRpcSendable(provider) {
|
|
57184
|
+
return typeof provider.send === "function";
|
|
57185
|
+
}
|
|
57186
|
+
function parseFeeHistory(raw) {
|
|
57187
|
+
if (typeof raw !== "object" || raw === null) {
|
|
57188
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
57189
|
+
}
|
|
57190
|
+
const { baseFeePerGas, reward } = raw;
|
|
57191
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
57192
|
+
throw new Error(
|
|
57193
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
57194
|
+
);
|
|
57195
|
+
}
|
|
57196
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
57197
|
+
throw new Error(
|
|
57198
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
57199
|
+
);
|
|
57190
57200
|
}
|
|
57201
|
+
const nextBaseFee = (0, import_ethers14.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
57202
|
+
const tips = reward.map((perBlock, i) => {
|
|
57203
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
57204
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
57205
|
+
}
|
|
57206
|
+
return (0, import_ethers14.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
57207
|
+
});
|
|
57208
|
+
return { nextBaseFee, tips };
|
|
57209
|
+
}
|
|
57210
|
+
function median(values) {
|
|
57211
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
57212
|
+
const mid = sorted.length >> 1;
|
|
57213
|
+
const hi = sorted[mid];
|
|
57214
|
+
if (hi === void 0) {
|
|
57215
|
+
throw new Error("median: no values");
|
|
57216
|
+
}
|
|
57217
|
+
if (sorted.length % 2 === 1)
|
|
57218
|
+
return hi;
|
|
57219
|
+
const lo = sorted[mid - 1];
|
|
57220
|
+
if (lo === void 0) {
|
|
57221
|
+
throw new Error("median: no values");
|
|
57222
|
+
}
|
|
57223
|
+
return (lo + hi) / 2n;
|
|
57224
|
+
}
|
|
57225
|
+
function clamp(value, floor, cap) {
|
|
57226
|
+
if (value < floor)
|
|
57227
|
+
return floor;
|
|
57228
|
+
if (value > cap)
|
|
57229
|
+
return cap;
|
|
57230
|
+
return value;
|
|
57231
|
+
}
|
|
57232
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
57233
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
57234
|
+
throw new Error(
|
|
57235
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
57236
|
+
);
|
|
57237
|
+
}
|
|
57238
|
+
const history = parseFeeHistory(
|
|
57239
|
+
await feeProvider.send("eth_feeHistory", [
|
|
57240
|
+
(0, import_ethers14.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
57241
|
+
"latest",
|
|
57242
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
57243
|
+
])
|
|
57244
|
+
);
|
|
57245
|
+
const marketTip = median(history.tips);
|
|
57246
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
57247
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
57191
57248
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
57192
57249
|
}
|
|
57193
57250
|
async function sendEip1559Transaction(params) {
|
|
57194
|
-
const { signer, to, data, gasLimit } = params;
|
|
57251
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
57195
57252
|
if (!signer.provider) {
|
|
57196
57253
|
throw new Error("Signer must have a provider attached");
|
|
57197
57254
|
}
|
|
57198
|
-
const fees = await resolveEip1559FeeFields(
|
|
57255
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
57199
57256
|
return signer.sendTransaction({
|
|
57200
57257
|
to,
|
|
57201
57258
|
data,
|
|
@@ -57212,6 +57269,17 @@ var DEFAULT_LIT_NETWORK = DEFAULT_LIT_NETWORKS.CHIPOTLE;
|
|
|
57212
57269
|
var VALID_LIT_NETWORKS = [
|
|
57213
57270
|
DEFAULT_LIT_NETWORKS.CHIPOTLE
|
|
57214
57271
|
];
|
|
57272
|
+
var PROTOCOL_LICENSE_IDENTIFIER = "UNLICENSED";
|
|
57273
|
+
var PROTOCOL_LICENSE_URI = "ipfs://bafkreigunb4phugonefe66by524nhnrgrpol4233ytg7e7eg7qomhy3s3a";
|
|
57274
|
+
var PROTOCOL_LICENSE_TEXT = '(c) GVNR DAO LLC, 2026\n\nExcept as otherwise provided in the header of a specific source code\nfile in this repository: (a) all intellectual property (including all\nsource code, designs and protocols) contained in this repository has been\npublished for informational purposes only; (b) no license, right of\nreproduction or distribution or other right with respect thereto is\ngranted or implied; and (c) all moral, intellectual property and other\nrights are hereby reserved by the copyright holder.\n\nTHE SOFTWARE AND INTELLECTUAL PROPERTY INCLUDED IN THIS REPOSITORY\nIS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS," AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR\nINTELLECTUAL PROPERTY (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\nBUSINESS INTERRUPTION), HOWEVER CAUSED OR CLAIMED (WHETHER IN CONTRACT,\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)), EVEN IF\nSUCH DAMAGES WERE REASONABLY FORESEEABLE OR THE COPYRIGHT HOLDERS WERE\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.';
|
|
57275
|
+
var PROTOCOL_LICENSE = Object.freeze({
|
|
57276
|
+
identifier: PROTOCOL_LICENSE_IDENTIFIER,
|
|
57277
|
+
uri: PROTOCOL_LICENSE_URI,
|
|
57278
|
+
text: PROTOCOL_LICENSE_TEXT
|
|
57279
|
+
});
|
|
57280
|
+
function getLicense() {
|
|
57281
|
+
return PROTOCOL_LICENSE;
|
|
57282
|
+
}
|
|
57215
57283
|
function assertSafeServiceEndpoint(endpoint) {
|
|
57216
57284
|
let url2;
|
|
57217
57285
|
try {
|
|
@@ -71999,6 +72067,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
71999
72067
|
}
|
|
72000
72068
|
const tx2 = await sendEip1559Transaction({
|
|
72001
72069
|
signer,
|
|
72070
|
+
feeProvider: this.getProviderOrThrow(),
|
|
72002
72071
|
to: positionManagerAddress,
|
|
72003
72072
|
data: mintCalldata,
|
|
72004
72073
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -73225,6 +73294,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
73225
73294
|
}
|
|
73226
73295
|
const tx2 = await sendEip1559Transaction({
|
|
73227
73296
|
signer: extendSigner,
|
|
73297
|
+
feeProvider: this.getProviderOrThrow(),
|
|
73228
73298
|
to: extendTo,
|
|
73229
73299
|
data: extendCalldata,
|
|
73230
73300
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -74159,6 +74229,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
74159
74229
|
}
|
|
74160
74230
|
const tx2 = await sendEip1559Transaction({
|
|
74161
74231
|
signer: paymentSigner,
|
|
74232
|
+
feeProvider: this.getProviderOrThrow(),
|
|
74162
74233
|
to: paymentContractAddress,
|
|
74163
74234
|
data: paymentCalldata,
|
|
74164
74235
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -74924,6 +74995,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
74924
74995
|
});
|
|
74925
74996
|
tx2 = await sendEip1559Transaction({
|
|
74926
74997
|
signer: withdrawSigner,
|
|
74998
|
+
feeProvider: this.getProviderOrThrow(),
|
|
74927
74999
|
to: positionManagerAddress,
|
|
74928
75000
|
data: withdrawCalldata,
|
|
74929
75001
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
|
@@ -77404,6 +77476,25 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
77404
77476
|
getConfig() {
|
|
77405
77477
|
return this.config;
|
|
77406
77478
|
}
|
|
77479
|
+
/**
|
|
77480
|
+
* Return the Diamond Hands protocol license.
|
|
77481
|
+
*
|
|
77482
|
+
* Same data as the standalone `getLicense()` export: the package `LICENSE`
|
|
77483
|
+
* file, which is the CIDv1 payload of `ContractVersionRegistry.LICENSE_URI`.
|
|
77484
|
+
* Does not fetch IPFS.
|
|
77485
|
+
*
|
|
77486
|
+
* @returns Identifier (`UNLICENSED`), IPFS URI, and full license text.
|
|
77487
|
+
*
|
|
77488
|
+
* @example
|
|
77489
|
+
* ```ts
|
|
77490
|
+
* const license = sdk.getLicense();
|
|
77491
|
+
* console.log(license.identifier); // "UNLICENSED"
|
|
77492
|
+
* console.log(license.uri); // "ipfs://bafkrei…"
|
|
77493
|
+
* ```
|
|
77494
|
+
*/
|
|
77495
|
+
getLicense() {
|
|
77496
|
+
return getLicense();
|
|
77497
|
+
}
|
|
77407
77498
|
/**
|
|
77408
77499
|
* Clear all caches
|
|
77409
77500
|
*/
|
package/dist/connector-embed.js
CHANGED
|
@@ -17461,11 +17461,11 @@ ${auth.clientId}`;
|
|
|
17461
17461
|
);
|
|
17462
17462
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
17463
17463
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
17464
|
-
let
|
|
17464
|
+
let median2;
|
|
17465
17465
|
if (this.devSingleProvider) {
|
|
17466
|
-
|
|
17466
|
+
median2 = sorted[0];
|
|
17467
17467
|
} else {
|
|
17468
|
-
|
|
17468
|
+
median2 = sorted[1];
|
|
17469
17469
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
17470
17470
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
17471
17471
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -17475,10 +17475,10 @@ ${auth.clientId}`;
|
|
|
17475
17475
|
);
|
|
17476
17476
|
}
|
|
17477
17477
|
}
|
|
17478
|
-
const priceCents = Math.round(
|
|
17478
|
+
const priceCents = Math.round(median2 * 100);
|
|
17479
17479
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
17480
17480
|
const totalElapsed = Date.now() - startTime;
|
|
17481
|
-
console.log(`[Price Oracle] Median price: $${
|
|
17481
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
17482
17482
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
17483
17483
|
return priceWith8Decimals;
|
|
17484
17484
|
}
|
|
@@ -56043,11 +56043,11 @@ ${auth.clientId}`;
|
|
|
56043
56043
|
);
|
|
56044
56044
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
56045
56045
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
56046
|
-
let
|
|
56046
|
+
let median2;
|
|
56047
56047
|
if (this.devSingleProvider) {
|
|
56048
|
-
|
|
56048
|
+
median2 = sorted[0];
|
|
56049
56049
|
} else {
|
|
56050
|
-
|
|
56050
|
+
median2 = sorted[1];
|
|
56051
56051
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
56052
56052
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
56053
56053
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -56057,10 +56057,10 @@ ${auth.clientId}`;
|
|
|
56057
56057
|
);
|
|
56058
56058
|
}
|
|
56059
56059
|
}
|
|
56060
|
-
const priceCents = Math.round(
|
|
56060
|
+
const priceCents = Math.round(median2 * 100);
|
|
56061
56061
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
56062
56062
|
const totalElapsed = Date.now() - startTime;
|
|
56063
|
-
console.log(`[Price Oracle] Median price: $${
|
|
56063
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
56064
56064
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
56065
56065
|
return priceWith8Decimals;
|
|
56066
56066
|
}
|
|
@@ -57825,26 +57825,83 @@ var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
|
57825
57825
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
57826
57826
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
57827
57827
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
57828
|
-
|
|
57829
|
-
|
|
57830
|
-
|
|
57831
|
-
|
|
57832
|
-
|
|
57833
|
-
|
|
57834
|
-
|
|
57835
|
-
|
|
57836
|
-
|
|
57837
|
-
|
|
57838
|
-
|
|
57828
|
+
var PRIORITY_FEE_FLOOR_WEI = (0, import_ethers15.parseUnits)("0.1", "gwei");
|
|
57829
|
+
var PRIORITY_FEE_CAP_WEI = (0, import_ethers15.parseUnits)("3", "gwei");
|
|
57830
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
57831
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
57832
|
+
function isJsonRpcSendable(provider) {
|
|
57833
|
+
return typeof provider.send === "function";
|
|
57834
|
+
}
|
|
57835
|
+
function parseFeeHistory(raw) {
|
|
57836
|
+
if (typeof raw !== "object" || raw === null) {
|
|
57837
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
57838
|
+
}
|
|
57839
|
+
const { baseFeePerGas, reward } = raw;
|
|
57840
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
57841
|
+
throw new Error(
|
|
57842
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
57843
|
+
);
|
|
57844
|
+
}
|
|
57845
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
57846
|
+
throw new Error(
|
|
57847
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
57848
|
+
);
|
|
57849
|
+
}
|
|
57850
|
+
const nextBaseFee = (0, import_ethers15.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
57851
|
+
const tips = reward.map((perBlock, i) => {
|
|
57852
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
57853
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
57854
|
+
}
|
|
57855
|
+
return (0, import_ethers15.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
57856
|
+
});
|
|
57857
|
+
return { nextBaseFee, tips };
|
|
57858
|
+
}
|
|
57859
|
+
function median(values) {
|
|
57860
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
57861
|
+
const mid = sorted.length >> 1;
|
|
57862
|
+
const hi = sorted[mid];
|
|
57863
|
+
if (hi === void 0) {
|
|
57864
|
+
throw new Error("median: no values");
|
|
57865
|
+
}
|
|
57866
|
+
if (sorted.length % 2 === 1)
|
|
57867
|
+
return hi;
|
|
57868
|
+
const lo = sorted[mid - 1];
|
|
57869
|
+
if (lo === void 0) {
|
|
57870
|
+
throw new Error("median: no values");
|
|
57871
|
+
}
|
|
57872
|
+
return (lo + hi) / 2n;
|
|
57873
|
+
}
|
|
57874
|
+
function clamp(value, floor, cap) {
|
|
57875
|
+
if (value < floor)
|
|
57876
|
+
return floor;
|
|
57877
|
+
if (value > cap)
|
|
57878
|
+
return cap;
|
|
57879
|
+
return value;
|
|
57880
|
+
}
|
|
57881
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
57882
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
57883
|
+
throw new Error(
|
|
57884
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
57885
|
+
);
|
|
57839
57886
|
}
|
|
57887
|
+
const history = parseFeeHistory(
|
|
57888
|
+
await feeProvider.send("eth_feeHistory", [
|
|
57889
|
+
(0, import_ethers15.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
57890
|
+
"latest",
|
|
57891
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
57892
|
+
])
|
|
57893
|
+
);
|
|
57894
|
+
const marketTip = median(history.tips);
|
|
57895
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
57896
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
57840
57897
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
57841
57898
|
}
|
|
57842
57899
|
async function sendEip1559Transaction(params) {
|
|
57843
|
-
const { signer, to, data, gasLimit } = params;
|
|
57900
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
57844
57901
|
if (!signer.provider) {
|
|
57845
57902
|
throw new Error("Signer must have a provider attached");
|
|
57846
57903
|
}
|
|
57847
|
-
const fees = await resolveEip1559FeeFields(
|
|
57904
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
57848
57905
|
return signer.sendTransaction({
|
|
57849
57906
|
to,
|
|
57850
57907
|
data,
|
|
@@ -57861,6 +57918,17 @@ var DEFAULT_LIT_NETWORK = DEFAULT_LIT_NETWORKS.CHIPOTLE;
|
|
|
57861
57918
|
var VALID_LIT_NETWORKS = [
|
|
57862
57919
|
DEFAULT_LIT_NETWORKS.CHIPOTLE
|
|
57863
57920
|
];
|
|
57921
|
+
var PROTOCOL_LICENSE_IDENTIFIER = "UNLICENSED";
|
|
57922
|
+
var PROTOCOL_LICENSE_URI = "ipfs://bafkreigunb4phugonefe66by524nhnrgrpol4233ytg7e7eg7qomhy3s3a";
|
|
57923
|
+
var PROTOCOL_LICENSE_TEXT = '(c) GVNR DAO LLC, 2026\n\nExcept as otherwise provided in the header of a specific source code\nfile in this repository: (a) all intellectual property (including all\nsource code, designs and protocols) contained in this repository has been\npublished for informational purposes only; (b) no license, right of\nreproduction or distribution or other right with respect thereto is\ngranted or implied; and (c) all moral, intellectual property and other\nrights are hereby reserved by the copyright holder.\n\nTHE SOFTWARE AND INTELLECTUAL PROPERTY INCLUDED IN THIS REPOSITORY\nIS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS," AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR\nINTELLECTUAL PROPERTY (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\nBUSINESS INTERRUPTION), HOWEVER CAUSED OR CLAIMED (WHETHER IN CONTRACT,\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)), EVEN IF\nSUCH DAMAGES WERE REASONABLY FORESEEABLE OR THE COPYRIGHT HOLDERS WERE\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.';
|
|
57924
|
+
var PROTOCOL_LICENSE = Object.freeze({
|
|
57925
|
+
identifier: PROTOCOL_LICENSE_IDENTIFIER,
|
|
57926
|
+
uri: PROTOCOL_LICENSE_URI,
|
|
57927
|
+
text: PROTOCOL_LICENSE_TEXT
|
|
57928
|
+
});
|
|
57929
|
+
function getLicense() {
|
|
57930
|
+
return PROTOCOL_LICENSE;
|
|
57931
|
+
}
|
|
57864
57932
|
function assertSafeServiceEndpoint(endpoint) {
|
|
57865
57933
|
let url2;
|
|
57866
57934
|
try {
|
|
@@ -72648,6 +72716,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
72648
72716
|
}
|
|
72649
72717
|
const tx2 = await sendEip1559Transaction({
|
|
72650
72718
|
signer,
|
|
72719
|
+
feeProvider: this.getProviderOrThrow(),
|
|
72651
72720
|
to: positionManagerAddress,
|
|
72652
72721
|
data: mintCalldata,
|
|
72653
72722
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -73874,6 +73943,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
73874
73943
|
}
|
|
73875
73944
|
const tx2 = await sendEip1559Transaction({
|
|
73876
73945
|
signer: extendSigner,
|
|
73946
|
+
feeProvider: this.getProviderOrThrow(),
|
|
73877
73947
|
to: extendTo,
|
|
73878
73948
|
data: extendCalldata,
|
|
73879
73949
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -74808,6 +74878,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
74808
74878
|
}
|
|
74809
74879
|
const tx2 = await sendEip1559Transaction({
|
|
74810
74880
|
signer: paymentSigner,
|
|
74881
|
+
feeProvider: this.getProviderOrThrow(),
|
|
74811
74882
|
to: paymentContractAddress,
|
|
74812
74883
|
data: paymentCalldata,
|
|
74813
74884
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -75573,6 +75644,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
75573
75644
|
});
|
|
75574
75645
|
tx2 = await sendEip1559Transaction({
|
|
75575
75646
|
signer: withdrawSigner,
|
|
75647
|
+
feeProvider: this.getProviderOrThrow(),
|
|
75576
75648
|
to: positionManagerAddress,
|
|
75577
75649
|
data: withdrawCalldata,
|
|
75578
75650
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
|
@@ -78053,6 +78125,25 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
78053
78125
|
getConfig() {
|
|
78054
78126
|
return this.config;
|
|
78055
78127
|
}
|
|
78128
|
+
/**
|
|
78129
|
+
* Return the Diamond Hands protocol license.
|
|
78130
|
+
*
|
|
78131
|
+
* Same data as the standalone `getLicense()` export: the package `LICENSE`
|
|
78132
|
+
* file, which is the CIDv1 payload of `ContractVersionRegistry.LICENSE_URI`.
|
|
78133
|
+
* Does not fetch IPFS.
|
|
78134
|
+
*
|
|
78135
|
+
* @returns Identifier (`UNLICENSED`), IPFS URI, and full license text.
|
|
78136
|
+
*
|
|
78137
|
+
* @example
|
|
78138
|
+
* ```ts
|
|
78139
|
+
* const license = sdk.getLicense();
|
|
78140
|
+
* console.log(license.identifier); // "UNLICENSED"
|
|
78141
|
+
* console.log(license.uri); // "ipfs://bafkrei…"
|
|
78142
|
+
* ```
|
|
78143
|
+
*/
|
|
78144
|
+
getLicense() {
|
|
78145
|
+
return getLicense();
|
|
78146
|
+
}
|
|
78056
78147
|
/**
|
|
78057
78148
|
* Clear all caches
|
|
78058
78149
|
*/
|
package/dist/connector.js
CHANGED
|
@@ -17461,11 +17461,11 @@ ${auth.clientId}`;
|
|
|
17461
17461
|
);
|
|
17462
17462
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
17463
17463
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
17464
|
-
let
|
|
17464
|
+
let median2;
|
|
17465
17465
|
if (this.devSingleProvider) {
|
|
17466
|
-
|
|
17466
|
+
median2 = sorted[0];
|
|
17467
17467
|
} else {
|
|
17468
|
-
|
|
17468
|
+
median2 = sorted[1];
|
|
17469
17469
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
17470
17470
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
17471
17471
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -17475,10 +17475,10 @@ ${auth.clientId}`;
|
|
|
17475
17475
|
);
|
|
17476
17476
|
}
|
|
17477
17477
|
}
|
|
17478
|
-
const priceCents = Math.round(
|
|
17478
|
+
const priceCents = Math.round(median2 * 100);
|
|
17479
17479
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
17480
17480
|
const totalElapsed = Date.now() - startTime;
|
|
17481
|
-
console.log(`[Price Oracle] Median price: $${
|
|
17481
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
17482
17482
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
17483
17483
|
return priceWith8Decimals;
|
|
17484
17484
|
}
|
|
@@ -56037,11 +56037,11 @@ ${auth.clientId}`;
|
|
|
56037
56037
|
);
|
|
56038
56038
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
56039
56039
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
56040
|
-
let
|
|
56040
|
+
let median2;
|
|
56041
56041
|
if (this.devSingleProvider) {
|
|
56042
|
-
|
|
56042
|
+
median2 = sorted[0];
|
|
56043
56043
|
} else {
|
|
56044
|
-
|
|
56044
|
+
median2 = sorted[1];
|
|
56045
56045
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
56046
56046
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
56047
56047
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -56051,10 +56051,10 @@ ${auth.clientId}`;
|
|
|
56051
56051
|
);
|
|
56052
56052
|
}
|
|
56053
56053
|
}
|
|
56054
|
-
const priceCents = Math.round(
|
|
56054
|
+
const priceCents = Math.round(median2 * 100);
|
|
56055
56055
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
56056
56056
|
const totalElapsed = Date.now() - startTime;
|
|
56057
|
-
console.log(`[Price Oracle] Median price: $${
|
|
56057
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
56058
56058
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
56059
56059
|
return priceWith8Decimals;
|
|
56060
56060
|
}
|
|
@@ -57819,26 +57819,83 @@ var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
|
57819
57819
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
57820
57820
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
57821
57821
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
57822
|
-
|
|
57823
|
-
|
|
57824
|
-
|
|
57825
|
-
|
|
57826
|
-
|
|
57827
|
-
|
|
57828
|
-
|
|
57829
|
-
|
|
57830
|
-
|
|
57831
|
-
|
|
57832
|
-
|
|
57822
|
+
var PRIORITY_FEE_FLOOR_WEI = (0, import_ethers15.parseUnits)("0.1", "gwei");
|
|
57823
|
+
var PRIORITY_FEE_CAP_WEI = (0, import_ethers15.parseUnits)("3", "gwei");
|
|
57824
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
57825
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
57826
|
+
function isJsonRpcSendable(provider) {
|
|
57827
|
+
return typeof provider.send === "function";
|
|
57828
|
+
}
|
|
57829
|
+
function parseFeeHistory(raw) {
|
|
57830
|
+
if (typeof raw !== "object" || raw === null) {
|
|
57831
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
57832
|
+
}
|
|
57833
|
+
const { baseFeePerGas, reward } = raw;
|
|
57834
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
57835
|
+
throw new Error(
|
|
57836
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
57837
|
+
);
|
|
57838
|
+
}
|
|
57839
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
57840
|
+
throw new Error(
|
|
57841
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
57842
|
+
);
|
|
57843
|
+
}
|
|
57844
|
+
const nextBaseFee = (0, import_ethers15.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
57845
|
+
const tips = reward.map((perBlock, i) => {
|
|
57846
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
57847
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
57848
|
+
}
|
|
57849
|
+
return (0, import_ethers15.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
57850
|
+
});
|
|
57851
|
+
return { nextBaseFee, tips };
|
|
57852
|
+
}
|
|
57853
|
+
function median(values) {
|
|
57854
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
57855
|
+
const mid = sorted.length >> 1;
|
|
57856
|
+
const hi = sorted[mid];
|
|
57857
|
+
if (hi === void 0) {
|
|
57858
|
+
throw new Error("median: no values");
|
|
57859
|
+
}
|
|
57860
|
+
if (sorted.length % 2 === 1)
|
|
57861
|
+
return hi;
|
|
57862
|
+
const lo = sorted[mid - 1];
|
|
57863
|
+
if (lo === void 0) {
|
|
57864
|
+
throw new Error("median: no values");
|
|
57865
|
+
}
|
|
57866
|
+
return (lo + hi) / 2n;
|
|
57867
|
+
}
|
|
57868
|
+
function clamp(value, floor, cap) {
|
|
57869
|
+
if (value < floor)
|
|
57870
|
+
return floor;
|
|
57871
|
+
if (value > cap)
|
|
57872
|
+
return cap;
|
|
57873
|
+
return value;
|
|
57874
|
+
}
|
|
57875
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
57876
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
57877
|
+
throw new Error(
|
|
57878
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
57879
|
+
);
|
|
57833
57880
|
}
|
|
57881
|
+
const history = parseFeeHistory(
|
|
57882
|
+
await feeProvider.send("eth_feeHistory", [
|
|
57883
|
+
(0, import_ethers15.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
57884
|
+
"latest",
|
|
57885
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
57886
|
+
])
|
|
57887
|
+
);
|
|
57888
|
+
const marketTip = median(history.tips);
|
|
57889
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
57890
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
57834
57891
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
57835
57892
|
}
|
|
57836
57893
|
async function sendEip1559Transaction(params) {
|
|
57837
|
-
const { signer, to, data, gasLimit } = params;
|
|
57894
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
57838
57895
|
if (!signer.provider) {
|
|
57839
57896
|
throw new Error("Signer must have a provider attached");
|
|
57840
57897
|
}
|
|
57841
|
-
const fees = await resolveEip1559FeeFields(
|
|
57898
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
57842
57899
|
return signer.sendTransaction({
|
|
57843
57900
|
to,
|
|
57844
57901
|
data,
|
|
@@ -57855,6 +57912,17 @@ var DEFAULT_LIT_NETWORK = DEFAULT_LIT_NETWORKS.CHIPOTLE;
|
|
|
57855
57912
|
var VALID_LIT_NETWORKS = [
|
|
57856
57913
|
DEFAULT_LIT_NETWORKS.CHIPOTLE
|
|
57857
57914
|
];
|
|
57915
|
+
var PROTOCOL_LICENSE_IDENTIFIER = "UNLICENSED";
|
|
57916
|
+
var PROTOCOL_LICENSE_URI = "ipfs://bafkreigunb4phugonefe66by524nhnrgrpol4233ytg7e7eg7qomhy3s3a";
|
|
57917
|
+
var PROTOCOL_LICENSE_TEXT = '(c) GVNR DAO LLC, 2026\n\nExcept as otherwise provided in the header of a specific source code\nfile in this repository: (a) all intellectual property (including all\nsource code, designs and protocols) contained in this repository has been\npublished for informational purposes only; (b) no license, right of\nreproduction or distribution or other right with respect thereto is\ngranted or implied; and (c) all moral, intellectual property and other\nrights are hereby reserved by the copyright holder.\n\nTHE SOFTWARE AND INTELLECTUAL PROPERTY INCLUDED IN THIS REPOSITORY\nIS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS," AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR\nINTELLECTUAL PROPERTY (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\nBUSINESS INTERRUPTION), HOWEVER CAUSED OR CLAIMED (WHETHER IN CONTRACT,\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)), EVEN IF\nSUCH DAMAGES WERE REASONABLY FORESEEABLE OR THE COPYRIGHT HOLDERS WERE\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.';
|
|
57918
|
+
var PROTOCOL_LICENSE = Object.freeze({
|
|
57919
|
+
identifier: PROTOCOL_LICENSE_IDENTIFIER,
|
|
57920
|
+
uri: PROTOCOL_LICENSE_URI,
|
|
57921
|
+
text: PROTOCOL_LICENSE_TEXT
|
|
57922
|
+
});
|
|
57923
|
+
function getLicense() {
|
|
57924
|
+
return PROTOCOL_LICENSE;
|
|
57925
|
+
}
|
|
57858
57926
|
function assertSafeServiceEndpoint(endpoint) {
|
|
57859
57927
|
let url2;
|
|
57860
57928
|
try {
|
|
@@ -72642,6 +72710,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
72642
72710
|
}
|
|
72643
72711
|
const tx2 = await sendEip1559Transaction({
|
|
72644
72712
|
signer,
|
|
72713
|
+
feeProvider: this.getProviderOrThrow(),
|
|
72645
72714
|
to: positionManagerAddress,
|
|
72646
72715
|
data: mintCalldata,
|
|
72647
72716
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -73868,6 +73937,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
73868
73937
|
}
|
|
73869
73938
|
const tx2 = await sendEip1559Transaction({
|
|
73870
73939
|
signer: extendSigner,
|
|
73940
|
+
feeProvider: this.getProviderOrThrow(),
|
|
73871
73941
|
to: extendTo,
|
|
73872
73942
|
data: extendCalldata,
|
|
73873
73943
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -74802,6 +74872,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
74802
74872
|
}
|
|
74803
74873
|
const tx2 = await sendEip1559Transaction({
|
|
74804
74874
|
signer: paymentSigner,
|
|
74875
|
+
feeProvider: this.getProviderOrThrow(),
|
|
74805
74876
|
to: paymentContractAddress,
|
|
74806
74877
|
data: paymentCalldata,
|
|
74807
74878
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -75567,6 +75638,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
75567
75638
|
});
|
|
75568
75639
|
tx2 = await sendEip1559Transaction({
|
|
75569
75640
|
signer: withdrawSigner,
|
|
75641
|
+
feeProvider: this.getProviderOrThrow(),
|
|
75570
75642
|
to: positionManagerAddress,
|
|
75571
75643
|
data: withdrawCalldata,
|
|
75572
75644
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
|
@@ -78047,6 +78119,25 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
78047
78119
|
getConfig() {
|
|
78048
78120
|
return this.config;
|
|
78049
78121
|
}
|
|
78122
|
+
/**
|
|
78123
|
+
* Return the Diamond Hands protocol license.
|
|
78124
|
+
*
|
|
78125
|
+
* Same data as the standalone `getLicense()` export: the package `LICENSE`
|
|
78126
|
+
* file, which is the CIDv1 payload of `ContractVersionRegistry.LICENSE_URI`.
|
|
78127
|
+
* Does not fetch IPFS.
|
|
78128
|
+
*
|
|
78129
|
+
* @returns Identifier (`UNLICENSED`), IPFS URI, and full license text.
|
|
78130
|
+
*
|
|
78131
|
+
* @example
|
|
78132
|
+
* ```ts
|
|
78133
|
+
* const license = sdk.getLicense();
|
|
78134
|
+
* console.log(license.identifier); // "UNLICENSED"
|
|
78135
|
+
* console.log(license.uri); // "ipfs://bafkrei…"
|
|
78136
|
+
* ```
|
|
78137
|
+
*/
|
|
78138
|
+
getLicense() {
|
|
78139
|
+
return getLicense();
|
|
78140
|
+
}
|
|
78050
78141
|
/**
|
|
78051
78142
|
* Clear all caches
|
|
78052
78143
|
*/
|
package/dist/index.js
CHANGED
|
@@ -17342,11 +17342,11 @@ ${auth.clientId}`;
|
|
|
17342
17342
|
);
|
|
17343
17343
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
17344
17344
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
17345
|
-
let
|
|
17345
|
+
let median2;
|
|
17346
17346
|
if (this.devSingleProvider) {
|
|
17347
|
-
|
|
17347
|
+
median2 = sorted[0];
|
|
17348
17348
|
} else {
|
|
17349
|
-
|
|
17349
|
+
median2 = sorted[1];
|
|
17350
17350
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
17351
17351
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
17352
17352
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -17356,10 +17356,10 @@ ${auth.clientId}`;
|
|
|
17356
17356
|
);
|
|
17357
17357
|
}
|
|
17358
17358
|
}
|
|
17359
|
-
const priceCents = Math.round(
|
|
17359
|
+
const priceCents = Math.round(median2 * 100);
|
|
17360
17360
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
17361
17361
|
const totalElapsed = Date.now() - startTime;
|
|
17362
|
-
console.log(`[Price Oracle] Median price: $${
|
|
17362
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
17363
17363
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
17364
17364
|
return priceWith8Decimals;
|
|
17365
17365
|
}
|
|
@@ -55596,11 +55596,11 @@ ${auth.clientId}`;
|
|
|
55596
55596
|
);
|
|
55597
55597
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
55598
55598
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
55599
|
-
let
|
|
55599
|
+
let median2;
|
|
55600
55600
|
if (this.devSingleProvider) {
|
|
55601
|
-
|
|
55601
|
+
median2 = sorted[0];
|
|
55602
55602
|
} else {
|
|
55603
|
-
|
|
55603
|
+
median2 = sorted[1];
|
|
55604
55604
|
const spread3 = (sorted[2] - sorted[0]) / sorted[0];
|
|
55605
55605
|
if (spread3 > PRICE_ORACLE_TOLERANCE) {
|
|
55606
55606
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -55610,10 +55610,10 @@ ${auth.clientId}`;
|
|
|
55610
55610
|
);
|
|
55611
55611
|
}
|
|
55612
55612
|
}
|
|
55613
|
-
const priceCents = Math.round(
|
|
55613
|
+
const priceCents = Math.round(median2 * 100);
|
|
55614
55614
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
55615
55615
|
const totalElapsed = Date.now() - startTime;
|
|
55616
|
-
console.log(`[Price Oracle] Median price: $${
|
|
55616
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
55617
55617
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
55618
55618
|
return priceWith8Decimals;
|
|
55619
55619
|
}
|
|
@@ -57378,26 +57378,83 @@ var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
|
57378
57378
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
57379
57379
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
57380
57380
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
57381
|
-
|
|
57382
|
-
|
|
57383
|
-
|
|
57384
|
-
|
|
57385
|
-
|
|
57386
|
-
|
|
57387
|
-
|
|
57388
|
-
|
|
57389
|
-
|
|
57390
|
-
|
|
57391
|
-
|
|
57381
|
+
var PRIORITY_FEE_FLOOR_WEI = (0, import_ethers14.parseUnits)("0.1", "gwei");
|
|
57382
|
+
var PRIORITY_FEE_CAP_WEI = (0, import_ethers14.parseUnits)("3", "gwei");
|
|
57383
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
57384
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
57385
|
+
function isJsonRpcSendable(provider) {
|
|
57386
|
+
return typeof provider.send === "function";
|
|
57387
|
+
}
|
|
57388
|
+
function parseFeeHistory(raw) {
|
|
57389
|
+
if (typeof raw !== "object" || raw === null) {
|
|
57390
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
57391
|
+
}
|
|
57392
|
+
const { baseFeePerGas, reward } = raw;
|
|
57393
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
57394
|
+
throw new Error(
|
|
57395
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
57396
|
+
);
|
|
57397
|
+
}
|
|
57398
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
57399
|
+
throw new Error(
|
|
57400
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
57401
|
+
);
|
|
57402
|
+
}
|
|
57403
|
+
const nextBaseFee = (0, import_ethers14.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
57404
|
+
const tips = reward.map((perBlock, i) => {
|
|
57405
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
57406
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
57407
|
+
}
|
|
57408
|
+
return (0, import_ethers14.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
57409
|
+
});
|
|
57410
|
+
return { nextBaseFee, tips };
|
|
57411
|
+
}
|
|
57412
|
+
function median(values) {
|
|
57413
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
57414
|
+
const mid = sorted.length >> 1;
|
|
57415
|
+
const hi = sorted[mid];
|
|
57416
|
+
if (hi === void 0) {
|
|
57417
|
+
throw new Error("median: no values");
|
|
57418
|
+
}
|
|
57419
|
+
if (sorted.length % 2 === 1)
|
|
57420
|
+
return hi;
|
|
57421
|
+
const lo = sorted[mid - 1];
|
|
57422
|
+
if (lo === void 0) {
|
|
57423
|
+
throw new Error("median: no values");
|
|
57424
|
+
}
|
|
57425
|
+
return (lo + hi) / 2n;
|
|
57426
|
+
}
|
|
57427
|
+
function clamp(value, floor, cap) {
|
|
57428
|
+
if (value < floor)
|
|
57429
|
+
return floor;
|
|
57430
|
+
if (value > cap)
|
|
57431
|
+
return cap;
|
|
57432
|
+
return value;
|
|
57433
|
+
}
|
|
57434
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
57435
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
57436
|
+
throw new Error(
|
|
57437
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
57438
|
+
);
|
|
57392
57439
|
}
|
|
57440
|
+
const history = parseFeeHistory(
|
|
57441
|
+
await feeProvider.send("eth_feeHistory", [
|
|
57442
|
+
(0, import_ethers14.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
57443
|
+
"latest",
|
|
57444
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
57445
|
+
])
|
|
57446
|
+
);
|
|
57447
|
+
const marketTip = median(history.tips);
|
|
57448
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
57449
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
57393
57450
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
57394
57451
|
}
|
|
57395
57452
|
async function sendEip1559Transaction(params) {
|
|
57396
|
-
const { signer, to, data, gasLimit } = params;
|
|
57453
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
57397
57454
|
if (!signer.provider) {
|
|
57398
57455
|
throw new Error("Signer must have a provider attached");
|
|
57399
57456
|
}
|
|
57400
|
-
const fees = await resolveEip1559FeeFields(
|
|
57457
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
57401
57458
|
return signer.sendTransaction({
|
|
57402
57459
|
to,
|
|
57403
57460
|
data,
|
|
@@ -57414,6 +57471,17 @@ var DEFAULT_LIT_NETWORK = DEFAULT_LIT_NETWORKS.CHIPOTLE;
|
|
|
57414
57471
|
var VALID_LIT_NETWORKS = [
|
|
57415
57472
|
DEFAULT_LIT_NETWORKS.CHIPOTLE
|
|
57416
57473
|
];
|
|
57474
|
+
var PROTOCOL_LICENSE_IDENTIFIER = "UNLICENSED";
|
|
57475
|
+
var PROTOCOL_LICENSE_URI = "ipfs://bafkreigunb4phugonefe66by524nhnrgrpol4233ytg7e7eg7qomhy3s3a";
|
|
57476
|
+
var PROTOCOL_LICENSE_TEXT = '(c) GVNR DAO LLC, 2026\n\nExcept as otherwise provided in the header of a specific source code\nfile in this repository: (a) all intellectual property (including all\nsource code, designs and protocols) contained in this repository has been\npublished for informational purposes only; (b) no license, right of\nreproduction or distribution or other right with respect thereto is\ngranted or implied; and (c) all moral, intellectual property and other\nrights are hereby reserved by the copyright holder.\n\nTHE SOFTWARE AND INTELLECTUAL PROPERTY INCLUDED IN THIS REPOSITORY\nIS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS," AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR\nINTELLECTUAL PROPERTY (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\nBUSINESS INTERRUPTION), HOWEVER CAUSED OR CLAIMED (WHETHER IN CONTRACT,\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)), EVEN IF\nSUCH DAMAGES WERE REASONABLY FORESEEABLE OR THE COPYRIGHT HOLDERS WERE\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.';
|
|
57477
|
+
var PROTOCOL_LICENSE = Object.freeze({
|
|
57478
|
+
identifier: PROTOCOL_LICENSE_IDENTIFIER,
|
|
57479
|
+
uri: PROTOCOL_LICENSE_URI,
|
|
57480
|
+
text: PROTOCOL_LICENSE_TEXT
|
|
57481
|
+
});
|
|
57482
|
+
function getLicense() {
|
|
57483
|
+
return PROTOCOL_LICENSE;
|
|
57484
|
+
}
|
|
57417
57485
|
function assertSafeServiceEndpoint(endpoint) {
|
|
57418
57486
|
let url2;
|
|
57419
57487
|
try {
|
|
@@ -72201,6 +72269,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
72201
72269
|
}
|
|
72202
72270
|
const tx2 = await sendEip1559Transaction({
|
|
72203
72271
|
signer,
|
|
72272
|
+
feeProvider: this.getProviderOrThrow(),
|
|
72204
72273
|
to: positionManagerAddress,
|
|
72205
72274
|
data: mintCalldata,
|
|
72206
72275
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -73427,6 +73496,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
73427
73496
|
}
|
|
73428
73497
|
const tx2 = await sendEip1559Transaction({
|
|
73429
73498
|
signer: extendSigner,
|
|
73499
|
+
feeProvider: this.getProviderOrThrow(),
|
|
73430
73500
|
to: extendTo,
|
|
73431
73501
|
data: extendCalldata,
|
|
73432
73502
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -74361,6 +74431,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
74361
74431
|
}
|
|
74362
74432
|
const tx2 = await sendEip1559Transaction({
|
|
74363
74433
|
signer: paymentSigner,
|
|
74434
|
+
feeProvider: this.getProviderOrThrow(),
|
|
74364
74435
|
to: paymentContractAddress,
|
|
74365
74436
|
data: paymentCalldata,
|
|
74366
74437
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -75126,6 +75197,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
75126
75197
|
});
|
|
75127
75198
|
tx2 = await sendEip1559Transaction({
|
|
75128
75199
|
signer: withdrawSigner,
|
|
75200
|
+
feeProvider: this.getProviderOrThrow(),
|
|
75129
75201
|
to: positionManagerAddress,
|
|
75130
75202
|
data: withdrawCalldata,
|
|
75131
75203
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
|
@@ -77606,6 +77678,25 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
77606
77678
|
getConfig() {
|
|
77607
77679
|
return this.config;
|
|
77608
77680
|
}
|
|
77681
|
+
/**
|
|
77682
|
+
* Return the Diamond Hands protocol license.
|
|
77683
|
+
*
|
|
77684
|
+
* Same data as the standalone `getLicense()` export: the package `LICENSE`
|
|
77685
|
+
* file, which is the CIDv1 payload of `ContractVersionRegistry.LICENSE_URI`.
|
|
77686
|
+
* Does not fetch IPFS.
|
|
77687
|
+
*
|
|
77688
|
+
* @returns Identifier (`UNLICENSED`), IPFS URI, and full license text.
|
|
77689
|
+
*
|
|
77690
|
+
* @example
|
|
77691
|
+
* ```ts
|
|
77692
|
+
* const license = sdk.getLicense();
|
|
77693
|
+
* console.log(license.identifier); // "UNLICENSED"
|
|
77694
|
+
* console.log(license.uri); // "ipfs://bafkrei…"
|
|
77695
|
+
* ```
|
|
77696
|
+
*/
|
|
77697
|
+
getLicense() {
|
|
77698
|
+
return getLicense();
|
|
77699
|
+
}
|
|
77609
77700
|
/**
|
|
77610
77701
|
* Clear all caches
|
|
77611
77702
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvnrdao/dh-mcp",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"description": "MCP server for the Diamond Hands protocol — Bitcoin-collateralized UCD lending with human-approved signing (sepolia practice by default; mainnet fully enabled)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@anthropic-ai/mcpb": "2.1.2",
|
|
56
|
-
"@gvnrdao/dh-sdk": "^0.0.
|
|
56
|
+
"@gvnrdao/dh-sdk": "^0.0.335",
|
|
57
57
|
"@types/express": "5.0.3",
|
|
58
58
|
"@types/jest": "29.5.12",
|
|
59
59
|
"@types/node": "20.14.10",
|