@hyperbridge/sdk 1.4.6 → 1.4.7-rc0000000001
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/browser/index.js +111 -86
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.js +101 -87
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -3
package/dist/browser/index.js
CHANGED
|
@@ -10,12 +10,11 @@ import { WsProvider, ApiPromise } from '@polkadot/api';
|
|
|
10
10
|
import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
|
|
11
11
|
import { GraphQLClient } from 'graphql-request';
|
|
12
12
|
import { Decimal } from 'decimal.js';
|
|
13
|
-
import { createStorage } from 'unstorage';
|
|
14
13
|
import stringify from 'safe-stable-stringify';
|
|
15
|
-
import
|
|
14
|
+
import { createStorage } from 'unstorage';
|
|
15
|
+
import inMemoryDriver from 'unstorage/drivers/memory';
|
|
16
16
|
import indexedDBDriver from 'unstorage/drivers/indexedb';
|
|
17
17
|
import localStorageDriver from 'unstorage/drivers/localstorage';
|
|
18
|
-
import memoryDriver from 'unstorage/drivers/memory';
|
|
19
18
|
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
20
19
|
|
|
21
20
|
var __defProp = Object.defineProperty;
|
|
@@ -10053,6 +10052,87 @@ var ABI4 = [
|
|
|
10053
10052
|
}
|
|
10054
10053
|
];
|
|
10055
10054
|
var IntentGateway_default = { ABI: ABI4 };
|
|
10055
|
+
var BASE_KEY = "hyperbridge/sdk/proof";
|
|
10056
|
+
var loadDriver = ({ key }) => {
|
|
10057
|
+
if (key === "localstorage") {
|
|
10058
|
+
return localStorageDriver({ base: BASE_KEY });
|
|
10059
|
+
}
|
|
10060
|
+
if (key === "indexeddb") {
|
|
10061
|
+
return indexedDBDriver({ base: BASE_KEY });
|
|
10062
|
+
}
|
|
10063
|
+
console.warn(
|
|
10064
|
+
`Hyperbridge/SDK/BrowserDriver: Unexpected storage driver: ${key}. Driver can't be loaded in the browser environment.`
|
|
10065
|
+
);
|
|
10066
|
+
return null;
|
|
10067
|
+
};
|
|
10068
|
+
|
|
10069
|
+
// src/storage/index.ts
|
|
10070
|
+
var convertBigIntsToSerializable = (value) => {
|
|
10071
|
+
if (value === null || value === void 0) return value;
|
|
10072
|
+
if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
|
|
10073
|
+
if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
|
|
10074
|
+
if (typeof value === "object") {
|
|
10075
|
+
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
10076
|
+
acc[k] = convertBigIntsToSerializable(v);
|
|
10077
|
+
return acc;
|
|
10078
|
+
}, {});
|
|
10079
|
+
}
|
|
10080
|
+
return value;
|
|
10081
|
+
};
|
|
10082
|
+
var convertSerializableToBigInts = (value) => {
|
|
10083
|
+
if (value === null || value === void 0) return value;
|
|
10084
|
+
if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
|
|
10085
|
+
if (typeof value === "object" && value !== null) {
|
|
10086
|
+
const obj = value;
|
|
10087
|
+
if (obj.__type === "bigint" && typeof obj.value === "string") {
|
|
10088
|
+
return BigInt(obj.value);
|
|
10089
|
+
}
|
|
10090
|
+
return Object.entries(obj).reduce((acc, [k, v]) => {
|
|
10091
|
+
acc[k] = convertSerializableToBigInts(v);
|
|
10092
|
+
return acc;
|
|
10093
|
+
}, {});
|
|
10094
|
+
}
|
|
10095
|
+
return value;
|
|
10096
|
+
};
|
|
10097
|
+
var detectEnvironment = () => {
|
|
10098
|
+
if (typeof process !== "undefined" && !!process.versions?.node) return "node";
|
|
10099
|
+
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
|
|
10100
|
+
if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
|
|
10101
|
+
return "memory";
|
|
10102
|
+
};
|
|
10103
|
+
function createCancellationStorage(options = {}) {
|
|
10104
|
+
const key = options.env ?? detectEnvironment();
|
|
10105
|
+
const driver = loadDriver({ key}) ?? inMemoryDriver;
|
|
10106
|
+
const baseStorage = createStorage({ driver });
|
|
10107
|
+
const getItem = async (key2) => {
|
|
10108
|
+
const value = await baseStorage.getItem(key2);
|
|
10109
|
+
if (!value) return null;
|
|
10110
|
+
try {
|
|
10111
|
+
return convertSerializableToBigInts(JSON.parse(value));
|
|
10112
|
+
} catch {
|
|
10113
|
+
return value;
|
|
10114
|
+
}
|
|
10115
|
+
};
|
|
10116
|
+
const setItem = async (key2, value) => {
|
|
10117
|
+
const serializable = convertBigIntsToSerializable(value);
|
|
10118
|
+
const stringified = stringify(serializable) ?? "null";
|
|
10119
|
+
await baseStorage.setItem(key2, stringified);
|
|
10120
|
+
};
|
|
10121
|
+
const removeItem = async (key2) => {
|
|
10122
|
+
baseStorage.removeItem(key2);
|
|
10123
|
+
};
|
|
10124
|
+
return Object.freeze({
|
|
10125
|
+
...baseStorage,
|
|
10126
|
+
getItem,
|
|
10127
|
+
setItem,
|
|
10128
|
+
removeItem
|
|
10129
|
+
});
|
|
10130
|
+
}
|
|
10131
|
+
var STORAGE_KEYS = Object.freeze({
|
|
10132
|
+
destProof: (orderId) => `cancel-order:${orderId}:destProof`,
|
|
10133
|
+
getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
|
|
10134
|
+
sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
|
|
10135
|
+
});
|
|
10056
10136
|
|
|
10057
10137
|
// src/abis/uniswapV3Quoter.ts
|
|
10058
10138
|
var ABI5 = [
|
|
@@ -12373,81 +12453,6 @@ var Swap = class {
|
|
|
12373
12453
|
}
|
|
12374
12454
|
}
|
|
12375
12455
|
};
|
|
12376
|
-
var convertBigIntsToSerializable = (value) => {
|
|
12377
|
-
if (value === null || value === void 0) return value;
|
|
12378
|
-
if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
|
|
12379
|
-
if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
|
|
12380
|
-
if (typeof value === "object") {
|
|
12381
|
-
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
12382
|
-
acc[k] = convertBigIntsToSerializable(v);
|
|
12383
|
-
return acc;
|
|
12384
|
-
}, {});
|
|
12385
|
-
}
|
|
12386
|
-
return value;
|
|
12387
|
-
};
|
|
12388
|
-
var convertSerializableToBigInts = (value) => {
|
|
12389
|
-
if (value === null || value === void 0) return value;
|
|
12390
|
-
if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
|
|
12391
|
-
if (typeof value === "object" && value !== null) {
|
|
12392
|
-
const obj = value;
|
|
12393
|
-
if (obj.__type === "bigint" && typeof obj.value === "string") {
|
|
12394
|
-
return BigInt(obj.value);
|
|
12395
|
-
}
|
|
12396
|
-
return Object.entries(obj).reduce((acc, [k, v]) => {
|
|
12397
|
-
acc[k] = convertSerializableToBigInts(v);
|
|
12398
|
-
return acc;
|
|
12399
|
-
}, {});
|
|
12400
|
-
}
|
|
12401
|
-
return value;
|
|
12402
|
-
};
|
|
12403
|
-
var detectEnvironment = () => {
|
|
12404
|
-
if (typeof process !== "undefined" && !!process.versions?.node) return "node";
|
|
12405
|
-
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
|
|
12406
|
-
if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
|
|
12407
|
-
return "memory";
|
|
12408
|
-
};
|
|
12409
|
-
function createCancellationStorage(options = {}) {
|
|
12410
|
-
const environment = options.env ?? detectEnvironment();
|
|
12411
|
-
const driver = (() => {
|
|
12412
|
-
switch (environment) {
|
|
12413
|
-
case "node":
|
|
12414
|
-
return fsDriver({ base: options.basePath ?? "./.hyperbridge-cache" });
|
|
12415
|
-
case "localstorage":
|
|
12416
|
-
return localStorageDriver({ base: "hyperbridge" });
|
|
12417
|
-
case "indexeddb":
|
|
12418
|
-
return indexedDBDriver({ base: "hyperbridge" });
|
|
12419
|
-
default:
|
|
12420
|
-
return memoryDriver();
|
|
12421
|
-
}
|
|
12422
|
-
})();
|
|
12423
|
-
const baseStorage = createStorage({ driver });
|
|
12424
|
-
const getItem = async (key) => {
|
|
12425
|
-
const value = await baseStorage.getItem(key);
|
|
12426
|
-
if (!value) return null;
|
|
12427
|
-
try {
|
|
12428
|
-
return convertSerializableToBigInts(JSON.parse(value));
|
|
12429
|
-
} catch {
|
|
12430
|
-
return value;
|
|
12431
|
-
}
|
|
12432
|
-
};
|
|
12433
|
-
const setItem = async (key, value) => {
|
|
12434
|
-
const serializable = convertBigIntsToSerializable(value);
|
|
12435
|
-
const stringified = stringify(serializable) ?? "null";
|
|
12436
|
-
await baseStorage.setItem(key, stringified);
|
|
12437
|
-
};
|
|
12438
|
-
const removeItem = (key) => baseStorage.removeItem(key);
|
|
12439
|
-
return Object.freeze({
|
|
12440
|
-
...baseStorage,
|
|
12441
|
-
getItem,
|
|
12442
|
-
setItem,
|
|
12443
|
-
removeItem
|
|
12444
|
-
});
|
|
12445
|
-
}
|
|
12446
|
-
var STORAGE_KEYS = Object.freeze({
|
|
12447
|
-
destProof: (orderId) => `cancel-order:${orderId}:destProof`,
|
|
12448
|
-
getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
|
|
12449
|
-
sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
|
|
12450
|
-
});
|
|
12451
12456
|
|
|
12452
12457
|
// src/protocols/intents.ts
|
|
12453
12458
|
var IntentGateway = class {
|
|
@@ -12521,7 +12526,10 @@ var IntentGateway = class {
|
|
|
12521
12526
|
tokenAddress,
|
|
12522
12527
|
allowanceData
|
|
12523
12528
|
);
|
|
12524
|
-
stateDiffs.push({
|
|
12529
|
+
stateDiffs.push({
|
|
12530
|
+
slot: allowanceSlot,
|
|
12531
|
+
value: testValue
|
|
12532
|
+
});
|
|
12525
12533
|
} catch (e) {
|
|
12526
12534
|
console.warn(`Could not find allowance slot for token ${tokenAddress}:`, e);
|
|
12527
12535
|
}
|
|
@@ -12881,7 +12889,7 @@ var IntentGateway = class {
|
|
|
12881
12889
|
*/
|
|
12882
12890
|
async *cancelOrder(order, indexerClient) {
|
|
12883
12891
|
const orderId = orderCommitment(order);
|
|
12884
|
-
|
|
12892
|
+
const hyperbridge = indexerClient.hyperbridge;
|
|
12885
12893
|
const sourceStateMachine = hexToString$1(order.sourceChain);
|
|
12886
12894
|
const sourceConsensusStateId = this.source.configService.getConsensusStateId(sourceStateMachine);
|
|
12887
12895
|
let destIProof = await this.storage.getItem(STORAGE_KEYS.destProof(orderId));
|
|
@@ -12891,19 +12899,30 @@ var IntentGateway = class {
|
|
|
12891
12899
|
}
|
|
12892
12900
|
let getRequest = await this.storage.getItem(STORAGE_KEYS.getRequest(orderId));
|
|
12893
12901
|
if (!getRequest) {
|
|
12894
|
-
const transactionHash = yield {
|
|
12895
|
-
|
|
12902
|
+
const transactionHash = yield {
|
|
12903
|
+
status: "AWAITING_GET_REQUEST",
|
|
12904
|
+
data: void 0
|
|
12905
|
+
};
|
|
12906
|
+
const receipt = await this.source.client.getTransactionReceipt({
|
|
12907
|
+
hash: transactionHash
|
|
12908
|
+
});
|
|
12896
12909
|
const events = parseEventLogs({ abi: evmHost_default.ABI, logs: receipt.logs });
|
|
12897
12910
|
const request = events.find((e) => e.eventName === "GetRequestEvent");
|
|
12898
12911
|
if (!request) throw new Error("GetRequest missing");
|
|
12899
12912
|
getRequest = request.args;
|
|
12900
12913
|
await this.storage.setItem(STORAGE_KEYS.getRequest(orderId), getRequest);
|
|
12901
12914
|
}
|
|
12902
|
-
const commitment = getRequestCommitment({
|
|
12915
|
+
const commitment = getRequestCommitment({
|
|
12916
|
+
...getRequest,
|
|
12917
|
+
keys: [...getRequest.keys]
|
|
12918
|
+
});
|
|
12903
12919
|
const sourceStatusStream = indexerClient.getRequestStatusStream(commitment);
|
|
12904
12920
|
for await (const statusUpdate of sourceStatusStream) {
|
|
12905
12921
|
if (statusUpdate.status === RequestStatus.SOURCE_FINALIZED) {
|
|
12906
|
-
yield {
|
|
12922
|
+
yield {
|
|
12923
|
+
status: "SOURCE_FINALIZED",
|
|
12924
|
+
data: { metadata: statusUpdate.metadata }
|
|
12925
|
+
};
|
|
12907
12926
|
const sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
|
|
12908
12927
|
let sourceIProof = await this.storage.getItem(STORAGE_KEYS.sourceProof(orderId));
|
|
12909
12928
|
if (!sourceIProof) {
|
|
@@ -12934,11 +12953,17 @@ var IntentGateway = class {
|
|
|
12934
12953
|
continue;
|
|
12935
12954
|
}
|
|
12936
12955
|
if (statusUpdate.status === RequestStatus.HYPERBRIDGE_DELIVERED) {
|
|
12937
|
-
yield {
|
|
12956
|
+
yield {
|
|
12957
|
+
status: "HYPERBRIDGE_DELIVERED",
|
|
12958
|
+
data: statusUpdate
|
|
12959
|
+
};
|
|
12938
12960
|
continue;
|
|
12939
12961
|
}
|
|
12940
12962
|
if (statusUpdate.status === RequestStatus.HYPERBRIDGE_FINALIZED) {
|
|
12941
|
-
yield {
|
|
12963
|
+
yield {
|
|
12964
|
+
status: "HYPERBRIDGE_FINALIZED",
|
|
12965
|
+
data: statusUpdate
|
|
12966
|
+
};
|
|
12942
12967
|
await this.storage.removeItem(STORAGE_KEYS.destProof(orderId));
|
|
12943
12968
|
await this.storage.removeItem(STORAGE_KEYS.getRequest(orderId));
|
|
12944
12969
|
await this.storage.removeItem(STORAGE_KEYS.sourceProof(orderId));
|