@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/node/index.js
CHANGED
|
@@ -13,12 +13,10 @@ import { WsProvider, ApiPromise } from '@polkadot/api';
|
|
|
13
13
|
import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
|
|
14
14
|
import { GraphQLClient } from 'graphql-request';
|
|
15
15
|
import { Decimal } from 'decimal.js';
|
|
16
|
-
import { createStorage } from 'unstorage';
|
|
17
16
|
import stringify from 'safe-stable-stringify';
|
|
17
|
+
import { createStorage } from 'unstorage';
|
|
18
|
+
import inMemoryDriver from 'unstorage/drivers/memory';
|
|
18
19
|
import fsDriver from 'unstorage/drivers/fs';
|
|
19
|
-
import indexedDBDriver from 'unstorage/drivers/indexedb';
|
|
20
|
-
import localStorageDriver from 'unstorage/drivers/localstorage';
|
|
21
|
-
import memoryDriver from 'unstorage/drivers/memory';
|
|
22
20
|
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
23
21
|
|
|
24
22
|
var __defProp = Object.defineProperty;
|
|
@@ -10004,6 +10002,77 @@ var ABI4 = [
|
|
|
10004
10002
|
}
|
|
10005
10003
|
];
|
|
10006
10004
|
var IntentGateway_default = { ABI: ABI4 };
|
|
10005
|
+
var loadDriver = ({ options }) => {
|
|
10006
|
+
return fsDriver({ base: options?.basePath ?? "./.hyperbridge-cache" });
|
|
10007
|
+
};
|
|
10008
|
+
|
|
10009
|
+
// src/storage/index.ts
|
|
10010
|
+
var convertBigIntsToSerializable = (value) => {
|
|
10011
|
+
if (value === null || value === void 0) return value;
|
|
10012
|
+
if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
|
|
10013
|
+
if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
|
|
10014
|
+
if (typeof value === "object") {
|
|
10015
|
+
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
10016
|
+
acc[k] = convertBigIntsToSerializable(v);
|
|
10017
|
+
return acc;
|
|
10018
|
+
}, {});
|
|
10019
|
+
}
|
|
10020
|
+
return value;
|
|
10021
|
+
};
|
|
10022
|
+
var convertSerializableToBigInts = (value) => {
|
|
10023
|
+
if (value === null || value === void 0) return value;
|
|
10024
|
+
if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
|
|
10025
|
+
if (typeof value === "object" && value !== null) {
|
|
10026
|
+
const obj = value;
|
|
10027
|
+
if (obj.__type === "bigint" && typeof obj.value === "string") {
|
|
10028
|
+
return BigInt(obj.value);
|
|
10029
|
+
}
|
|
10030
|
+
return Object.entries(obj).reduce((acc, [k, v]) => {
|
|
10031
|
+
acc[k] = convertSerializableToBigInts(v);
|
|
10032
|
+
return acc;
|
|
10033
|
+
}, {});
|
|
10034
|
+
}
|
|
10035
|
+
return value;
|
|
10036
|
+
};
|
|
10037
|
+
var detectEnvironment = () => {
|
|
10038
|
+
if (typeof process !== "undefined" && !!process.versions?.node) return "node";
|
|
10039
|
+
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
|
|
10040
|
+
if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
|
|
10041
|
+
return "memory";
|
|
10042
|
+
};
|
|
10043
|
+
function createCancellationStorage(options = {}) {
|
|
10044
|
+
options.env ?? detectEnvironment();
|
|
10045
|
+
const driver = loadDriver({ options }) ?? inMemoryDriver;
|
|
10046
|
+
const baseStorage = createStorage({ driver });
|
|
10047
|
+
const getItem = async (key2) => {
|
|
10048
|
+
const value = await baseStorage.getItem(key2);
|
|
10049
|
+
if (!value) return null;
|
|
10050
|
+
try {
|
|
10051
|
+
return convertSerializableToBigInts(JSON.parse(value));
|
|
10052
|
+
} catch {
|
|
10053
|
+
return value;
|
|
10054
|
+
}
|
|
10055
|
+
};
|
|
10056
|
+
const setItem = async (key2, value) => {
|
|
10057
|
+
const serializable = convertBigIntsToSerializable(value);
|
|
10058
|
+
const stringified = stringify(serializable) ?? "null";
|
|
10059
|
+
await baseStorage.setItem(key2, stringified);
|
|
10060
|
+
};
|
|
10061
|
+
const removeItem = async (key2) => {
|
|
10062
|
+
baseStorage.removeItem(key2);
|
|
10063
|
+
};
|
|
10064
|
+
return Object.freeze({
|
|
10065
|
+
...baseStorage,
|
|
10066
|
+
getItem,
|
|
10067
|
+
setItem,
|
|
10068
|
+
removeItem
|
|
10069
|
+
});
|
|
10070
|
+
}
|
|
10071
|
+
var STORAGE_KEYS = Object.freeze({
|
|
10072
|
+
destProof: (orderId) => `cancel-order:${orderId}:destProof`,
|
|
10073
|
+
getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
|
|
10074
|
+
sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
|
|
10075
|
+
});
|
|
10007
10076
|
|
|
10008
10077
|
// src/abis/uniswapV3Quoter.ts
|
|
10009
10078
|
var ABI5 = [
|
|
@@ -12324,81 +12393,6 @@ var Swap = class {
|
|
|
12324
12393
|
}
|
|
12325
12394
|
}
|
|
12326
12395
|
};
|
|
12327
|
-
var convertBigIntsToSerializable = (value) => {
|
|
12328
|
-
if (value === null || value === void 0) return value;
|
|
12329
|
-
if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
|
|
12330
|
-
if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
|
|
12331
|
-
if (typeof value === "object") {
|
|
12332
|
-
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
12333
|
-
acc[k] = convertBigIntsToSerializable(v);
|
|
12334
|
-
return acc;
|
|
12335
|
-
}, {});
|
|
12336
|
-
}
|
|
12337
|
-
return value;
|
|
12338
|
-
};
|
|
12339
|
-
var convertSerializableToBigInts = (value) => {
|
|
12340
|
-
if (value === null || value === void 0) return value;
|
|
12341
|
-
if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
|
|
12342
|
-
if (typeof value === "object" && value !== null) {
|
|
12343
|
-
const obj = value;
|
|
12344
|
-
if (obj.__type === "bigint" && typeof obj.value === "string") {
|
|
12345
|
-
return BigInt(obj.value);
|
|
12346
|
-
}
|
|
12347
|
-
return Object.entries(obj).reduce((acc, [k, v]) => {
|
|
12348
|
-
acc[k] = convertSerializableToBigInts(v);
|
|
12349
|
-
return acc;
|
|
12350
|
-
}, {});
|
|
12351
|
-
}
|
|
12352
|
-
return value;
|
|
12353
|
-
};
|
|
12354
|
-
var detectEnvironment = () => {
|
|
12355
|
-
if (typeof process !== "undefined" && !!process.versions?.node) return "node";
|
|
12356
|
-
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
|
|
12357
|
-
if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
|
|
12358
|
-
return "memory";
|
|
12359
|
-
};
|
|
12360
|
-
function createCancellationStorage(options = {}) {
|
|
12361
|
-
const environment = options.env ?? detectEnvironment();
|
|
12362
|
-
const driver = (() => {
|
|
12363
|
-
switch (environment) {
|
|
12364
|
-
case "node":
|
|
12365
|
-
return fsDriver({ base: options.basePath ?? "./.hyperbridge-cache" });
|
|
12366
|
-
case "localstorage":
|
|
12367
|
-
return localStorageDriver({ base: "hyperbridge" });
|
|
12368
|
-
case "indexeddb":
|
|
12369
|
-
return indexedDBDriver({ base: "hyperbridge" });
|
|
12370
|
-
default:
|
|
12371
|
-
return memoryDriver();
|
|
12372
|
-
}
|
|
12373
|
-
})();
|
|
12374
|
-
const baseStorage = createStorage({ driver });
|
|
12375
|
-
const getItem = async (key) => {
|
|
12376
|
-
const value = await baseStorage.getItem(key);
|
|
12377
|
-
if (!value) return null;
|
|
12378
|
-
try {
|
|
12379
|
-
return convertSerializableToBigInts(JSON.parse(value));
|
|
12380
|
-
} catch {
|
|
12381
|
-
return value;
|
|
12382
|
-
}
|
|
12383
|
-
};
|
|
12384
|
-
const setItem = async (key, value) => {
|
|
12385
|
-
const serializable = convertBigIntsToSerializable(value);
|
|
12386
|
-
const stringified = stringify(serializable) ?? "null";
|
|
12387
|
-
await baseStorage.setItem(key, stringified);
|
|
12388
|
-
};
|
|
12389
|
-
const removeItem = (key) => baseStorage.removeItem(key);
|
|
12390
|
-
return Object.freeze({
|
|
12391
|
-
...baseStorage,
|
|
12392
|
-
getItem,
|
|
12393
|
-
setItem,
|
|
12394
|
-
removeItem
|
|
12395
|
-
});
|
|
12396
|
-
}
|
|
12397
|
-
var STORAGE_KEYS = Object.freeze({
|
|
12398
|
-
destProof: (orderId) => `cancel-order:${orderId}:destProof`,
|
|
12399
|
-
getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
|
|
12400
|
-
sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
|
|
12401
|
-
});
|
|
12402
12396
|
|
|
12403
12397
|
// src/protocols/intents.ts
|
|
12404
12398
|
var IntentGateway = class {
|
|
@@ -12472,7 +12466,10 @@ var IntentGateway = class {
|
|
|
12472
12466
|
tokenAddress,
|
|
12473
12467
|
allowanceData
|
|
12474
12468
|
);
|
|
12475
|
-
stateDiffs.push({
|
|
12469
|
+
stateDiffs.push({
|
|
12470
|
+
slot: allowanceSlot,
|
|
12471
|
+
value: testValue
|
|
12472
|
+
});
|
|
12476
12473
|
} catch (e) {
|
|
12477
12474
|
console.warn(`Could not find allowance slot for token ${tokenAddress}:`, e);
|
|
12478
12475
|
}
|
|
@@ -12832,7 +12829,7 @@ var IntentGateway = class {
|
|
|
12832
12829
|
*/
|
|
12833
12830
|
async *cancelOrder(order, indexerClient) {
|
|
12834
12831
|
const orderId = orderCommitment(order);
|
|
12835
|
-
|
|
12832
|
+
const hyperbridge = indexerClient.hyperbridge;
|
|
12836
12833
|
const sourceStateMachine = hexToString$1(order.sourceChain);
|
|
12837
12834
|
const sourceConsensusStateId = this.source.configService.getConsensusStateId(sourceStateMachine);
|
|
12838
12835
|
let destIProof = await this.storage.getItem(STORAGE_KEYS.destProof(orderId));
|
|
@@ -12842,19 +12839,30 @@ var IntentGateway = class {
|
|
|
12842
12839
|
}
|
|
12843
12840
|
let getRequest = await this.storage.getItem(STORAGE_KEYS.getRequest(orderId));
|
|
12844
12841
|
if (!getRequest) {
|
|
12845
|
-
const transactionHash = yield {
|
|
12846
|
-
|
|
12842
|
+
const transactionHash = yield {
|
|
12843
|
+
status: "AWAITING_GET_REQUEST",
|
|
12844
|
+
data: void 0
|
|
12845
|
+
};
|
|
12846
|
+
const receipt = await this.source.client.getTransactionReceipt({
|
|
12847
|
+
hash: transactionHash
|
|
12848
|
+
});
|
|
12847
12849
|
const events = parseEventLogs({ abi: evmHost_default.ABI, logs: receipt.logs });
|
|
12848
12850
|
const request = events.find((e) => e.eventName === "GetRequestEvent");
|
|
12849
12851
|
if (!request) throw new Error("GetRequest missing");
|
|
12850
12852
|
getRequest = request.args;
|
|
12851
12853
|
await this.storage.setItem(STORAGE_KEYS.getRequest(orderId), getRequest);
|
|
12852
12854
|
}
|
|
12853
|
-
const commitment = getRequestCommitment({
|
|
12855
|
+
const commitment = getRequestCommitment({
|
|
12856
|
+
...getRequest,
|
|
12857
|
+
keys: [...getRequest.keys]
|
|
12858
|
+
});
|
|
12854
12859
|
const sourceStatusStream = indexerClient.getRequestStatusStream(commitment);
|
|
12855
12860
|
for await (const statusUpdate of sourceStatusStream) {
|
|
12856
12861
|
if (statusUpdate.status === RequestStatus.SOURCE_FINALIZED) {
|
|
12857
|
-
yield {
|
|
12862
|
+
yield {
|
|
12863
|
+
status: "SOURCE_FINALIZED",
|
|
12864
|
+
data: { metadata: statusUpdate.metadata }
|
|
12865
|
+
};
|
|
12858
12866
|
const sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
|
|
12859
12867
|
let sourceIProof = await this.storage.getItem(STORAGE_KEYS.sourceProof(orderId));
|
|
12860
12868
|
if (!sourceIProof) {
|
|
@@ -12885,11 +12893,17 @@ var IntentGateway = class {
|
|
|
12885
12893
|
continue;
|
|
12886
12894
|
}
|
|
12887
12895
|
if (statusUpdate.status === RequestStatus.HYPERBRIDGE_DELIVERED) {
|
|
12888
|
-
yield {
|
|
12896
|
+
yield {
|
|
12897
|
+
status: "HYPERBRIDGE_DELIVERED",
|
|
12898
|
+
data: statusUpdate
|
|
12899
|
+
};
|
|
12889
12900
|
continue;
|
|
12890
12901
|
}
|
|
12891
12902
|
if (statusUpdate.status === RequestStatus.HYPERBRIDGE_FINALIZED) {
|
|
12892
|
-
yield {
|
|
12903
|
+
yield {
|
|
12904
|
+
status: "HYPERBRIDGE_FINALIZED",
|
|
12905
|
+
data: statusUpdate
|
|
12906
|
+
};
|
|
12893
12907
|
await this.storage.removeItem(STORAGE_KEYS.destProof(orderId));
|
|
12894
12908
|
await this.storage.removeItem(STORAGE_KEYS.getRequest(orderId));
|
|
12895
12909
|
await this.storage.removeItem(STORAGE_KEYS.sourceProof(orderId));
|