@hyperbridge/sdk 1.9.4 → 1.9.6
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.d.ts +211 -5
- package/dist/browser/index.js +384 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +211 -5
- package/dist/node/index.js +384 -11
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -3662,6 +3662,8 @@ var Chains = /* @__PURE__ */ ((Chains3) => {
|
|
|
3662
3662
|
Chains3["POLKADOT_ASSET_HUB_PASEO"] = "EVM-420420417";
|
|
3663
3663
|
Chains3["TRON_MAINNET"] = "EVM-728126428";
|
|
3664
3664
|
Chains3["TRON_NILE"] = "EVM-3448148188";
|
|
3665
|
+
Chains3["PHAROS_MAINNET"] = "EVM-688600";
|
|
3666
|
+
Chains3["PHAROS_ATLANTIC"] = "EVM-688689";
|
|
3665
3667
|
return Chains3;
|
|
3666
3668
|
})(Chains || {});
|
|
3667
3669
|
var polkadotAssetHubPaseo = defineChain({
|
|
@@ -3675,6 +3677,22 @@ var polkadotAssetHubPaseo = defineChain({
|
|
|
3675
3677
|
default: { name: "Routescan", url: "https://polkadot.testnet.routescan.io" }
|
|
3676
3678
|
}
|
|
3677
3679
|
});
|
|
3680
|
+
var pharosMainnet = defineChain({
|
|
3681
|
+
id: 688600,
|
|
3682
|
+
name: "Pharos Mainnet",
|
|
3683
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
3684
|
+
rpcUrls: {
|
|
3685
|
+
default: { http: ["https://atlantic.dplabs-internal.com"] }
|
|
3686
|
+
}
|
|
3687
|
+
});
|
|
3688
|
+
var pharosAtlantic = defineChain({
|
|
3689
|
+
id: 688689,
|
|
3690
|
+
name: "Pharos Atlantic Testnet",
|
|
3691
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
3692
|
+
rpcUrls: {
|
|
3693
|
+
default: { http: ["https://atlantic.dplabs-internal.com"] }
|
|
3694
|
+
}
|
|
3695
|
+
});
|
|
3678
3696
|
var tronNile = defineChain({
|
|
3679
3697
|
id: 3448148188,
|
|
3680
3698
|
name: "TRON Nile Testnet",
|
|
@@ -4393,6 +4411,30 @@ var chainConfigs = {
|
|
|
4393
4411
|
defaultRpcUrl: "https://testnet-asset-hub-eth-rpc.polkadot.io",
|
|
4394
4412
|
consensusStateId: "PAS0",
|
|
4395
4413
|
coingeckoId: "polkadot"
|
|
4414
|
+
},
|
|
4415
|
+
688600: {
|
|
4416
|
+
chainId: 688600,
|
|
4417
|
+
stateMachineId: "EVM-688600" /* PHAROS_MAINNET */,
|
|
4418
|
+
viemChain: pharosMainnet,
|
|
4419
|
+
wrappedNativeDecimals: 18,
|
|
4420
|
+
addresses: {
|
|
4421
|
+
Host: "0x0000000000000000000000000000000000000000"
|
|
4422
|
+
},
|
|
4423
|
+
consensusStateId: "PHAR",
|
|
4424
|
+
coingeckoId: "pharos"
|
|
4425
|
+
},
|
|
4426
|
+
688689: {
|
|
4427
|
+
chainId: 688689,
|
|
4428
|
+
stateMachineId: "EVM-688689" /* PHAROS_ATLANTIC */,
|
|
4429
|
+
viemChain: pharosAtlantic,
|
|
4430
|
+
wrappedNativeDecimals: 18,
|
|
4431
|
+
addresses: {
|
|
4432
|
+
TokenGateway: "0x451bDd8273839AD0Ec7F4Fa798E8B3DABb223fD8",
|
|
4433
|
+
Host: "0xED54E9b64043c389173316B6351Bd25491060eA8",
|
|
4434
|
+
IntentGatewayV2: "0xb8039832c6c9266F928d038eA49A8a169300C670"
|
|
4435
|
+
},
|
|
4436
|
+
consensusStateId: "PHAR",
|
|
4437
|
+
coingeckoId: "pharos"
|
|
4396
4438
|
}
|
|
4397
4439
|
};
|
|
4398
4440
|
var configsByStateMachineId = Object.fromEntries(
|
|
@@ -5543,7 +5585,9 @@ var chains = {
|
|
|
5543
5585
|
[unichain.id]: unichain,
|
|
5544
5586
|
[tron.id]: tron,
|
|
5545
5587
|
[tronNile.id]: tronNile,
|
|
5546
|
-
[polkadotAssetHubPaseo.id]: polkadotAssetHubPaseo
|
|
5588
|
+
[polkadotAssetHubPaseo.id]: polkadotAssetHubPaseo,
|
|
5589
|
+
[pharosMainnet.id]: pharosMainnet,
|
|
5590
|
+
[pharosAtlantic.id]: pharosAtlantic
|
|
5547
5591
|
};
|
|
5548
5592
|
var DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
5549
5593
|
var EvmChain = class _EvmChain {
|
|
@@ -5584,8 +5628,12 @@ var EvmChain = class _EvmChain {
|
|
|
5584
5628
|
// Gnosis Chiado
|
|
5585
5629
|
420420417: "PAS0",
|
|
5586
5630
|
// Polkadot Asset Hub (Paseo)
|
|
5587
|
-
420420419: "DOT0"
|
|
5631
|
+
420420419: "DOT0",
|
|
5588
5632
|
// Polkadot Asset Hub (Polkadot)
|
|
5633
|
+
688600: "PHAR",
|
|
5634
|
+
// Pharos Mainnet
|
|
5635
|
+
688689: "PHAR"
|
|
5636
|
+
// Pharos Atlantic (Testnet)
|
|
5589
5637
|
};
|
|
5590
5638
|
if (!params.consensusStateId) {
|
|
5591
5639
|
params.consensusStateId = defaultConsensusStateIds[params.chainId];
|
|
@@ -7812,6 +7860,312 @@ var PolkadotHubChain = class _PolkadotHubChain {
|
|
|
7812
7860
|
return this.evm.getTransactionReceipt(hash);
|
|
7813
7861
|
}
|
|
7814
7862
|
};
|
|
7863
|
+
var PharosProofNodeCodec = Struct({
|
|
7864
|
+
proofNode: Vector(u8),
|
|
7865
|
+
nextBeginOffset: u32,
|
|
7866
|
+
nextEndOffset: u32
|
|
7867
|
+
});
|
|
7868
|
+
var SiblingLeftmostLeafProofCodec = Struct({
|
|
7869
|
+
slotIndex: u8,
|
|
7870
|
+
leftmostLeafKey: Vector(u8),
|
|
7871
|
+
proofPath: Vector(PharosProofNodeCodec)
|
|
7872
|
+
});
|
|
7873
|
+
var NonExistenceProofCodec = Struct({
|
|
7874
|
+
proofNodes: Vector(PharosProofNodeCodec),
|
|
7875
|
+
siblingProofs: Vector(SiblingLeftmostLeafProofCodec)
|
|
7876
|
+
});
|
|
7877
|
+
var AccountProofDataCodec = Struct({
|
|
7878
|
+
proofNodes: Vector(PharosProofNodeCodec),
|
|
7879
|
+
rawValue: Vector(u8)
|
|
7880
|
+
});
|
|
7881
|
+
var PharosStateProof = Struct({
|
|
7882
|
+
storageProof: Vector(Tuple(Vector(u8), Vector(PharosProofNodeCodec))),
|
|
7883
|
+
storageValues: Vector(Tuple(Vector(u8), Vector(u8))),
|
|
7884
|
+
nonExistenceProofs: Vector(Tuple(Vector(u8), NonExistenceProofCodec)),
|
|
7885
|
+
accountProofs: Vector(Tuple(Vector(u8), AccountProofDataCodec))
|
|
7886
|
+
});
|
|
7887
|
+
|
|
7888
|
+
// src/chains/pharos.ts
|
|
7889
|
+
var EvmHttpRpc = class {
|
|
7890
|
+
constructor(url) {
|
|
7891
|
+
this.url = url;
|
|
7892
|
+
}
|
|
7893
|
+
url;
|
|
7894
|
+
async call(method, params = []) {
|
|
7895
|
+
const response = await fetch(this.url, {
|
|
7896
|
+
method: "POST",
|
|
7897
|
+
headers: { "Content-Type": "application/json" },
|
|
7898
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: Date.now(), method, params })
|
|
7899
|
+
});
|
|
7900
|
+
if (!response.ok) {
|
|
7901
|
+
throw new Error(`Pharos RPC HTTP error: ${response.status}`);
|
|
7902
|
+
}
|
|
7903
|
+
const json = await response.json();
|
|
7904
|
+
if (json.error) {
|
|
7905
|
+
throw new Error(`Pharos RPC error: ${json.error.message}`);
|
|
7906
|
+
}
|
|
7907
|
+
if (json.result === void 0) {
|
|
7908
|
+
throw new Error("Pharos RPC: missing result");
|
|
7909
|
+
}
|
|
7910
|
+
return json.result;
|
|
7911
|
+
}
|
|
7912
|
+
};
|
|
7913
|
+
function padTo32Bytes(hex) {
|
|
7914
|
+
const bytes = hexToBytes(hex);
|
|
7915
|
+
if (bytes.length > 32) {
|
|
7916
|
+
throw new Error(`Pharos value exceeds 32 bytes: ${hex}`);
|
|
7917
|
+
}
|
|
7918
|
+
const out = new Uint8Array(32);
|
|
7919
|
+
out.set(bytes, 32 - bytes.length);
|
|
7920
|
+
return out;
|
|
7921
|
+
}
|
|
7922
|
+
function rpcToProofNodes(nodes) {
|
|
7923
|
+
return nodes.map((n) => ({
|
|
7924
|
+
proofNode: Array.from(hexToBytes(n.proofNode)),
|
|
7925
|
+
nextBeginOffset: n.nextBeginOffset,
|
|
7926
|
+
nextEndOffset: n.nextEndOffset
|
|
7927
|
+
}));
|
|
7928
|
+
}
|
|
7929
|
+
function rpcToSiblingProofs(siblings) {
|
|
7930
|
+
return (siblings ?? []).map((s) => ({
|
|
7931
|
+
slotIndex: s.slotIndex,
|
|
7932
|
+
leftmostLeafKey: Array.from(hexToBytes(s.leftmostLeafKey)),
|
|
7933
|
+
proofPath: rpcToProofNodes(s.proofPath)
|
|
7934
|
+
}));
|
|
7935
|
+
}
|
|
7936
|
+
function blockTag(at) {
|
|
7937
|
+
return at === void 0 ? "latest" : `0x${at.toString(16)}`;
|
|
7938
|
+
}
|
|
7939
|
+
function newAccumulator() {
|
|
7940
|
+
return {
|
|
7941
|
+
storageProof: /* @__PURE__ */ new Map(),
|
|
7942
|
+
storageValues: /* @__PURE__ */ new Map(),
|
|
7943
|
+
nonExistenceProofs: /* @__PURE__ */ new Map(),
|
|
7944
|
+
accountProofs: /* @__PURE__ */ new Map()
|
|
7945
|
+
};
|
|
7946
|
+
}
|
|
7947
|
+
function hexKey2(bytes) {
|
|
7948
|
+
return bytesToHex(bytes);
|
|
7949
|
+
}
|
|
7950
|
+
function mapToEntries(m) {
|
|
7951
|
+
const entries = [];
|
|
7952
|
+
for (const [k, v] of m.entries()) {
|
|
7953
|
+
entries.push([Array.from(hexToBytes(k)), v]);
|
|
7954
|
+
}
|
|
7955
|
+
return entries;
|
|
7956
|
+
}
|
|
7957
|
+
function encodeAccumulator(acc) {
|
|
7958
|
+
const encoded = PharosStateProof.enc({
|
|
7959
|
+
storageProof: mapToEntries(acc.storageProof),
|
|
7960
|
+
storageValues: mapToEntries(acc.storageValues),
|
|
7961
|
+
nonExistenceProofs: mapToEntries(acc.nonExistenceProofs),
|
|
7962
|
+
accountProofs: mapToEntries(acc.accountProofs)
|
|
7963
|
+
});
|
|
7964
|
+
return bytesToHex(encoded);
|
|
7965
|
+
}
|
|
7966
|
+
var PharosChain = class _PharosChain {
|
|
7967
|
+
constructor(params, evm) {
|
|
7968
|
+
this.params = params;
|
|
7969
|
+
this.evm = evm;
|
|
7970
|
+
this.rpc = new EvmHttpRpc(replaceWebsocketWithHttp(params.rpcUrl));
|
|
7971
|
+
}
|
|
7972
|
+
params;
|
|
7973
|
+
evm;
|
|
7974
|
+
rpc;
|
|
7975
|
+
static fromParams(params) {
|
|
7976
|
+
const evm = EvmChain.fromParams(params);
|
|
7977
|
+
return new _PharosChain(params, evm);
|
|
7978
|
+
}
|
|
7979
|
+
/**
|
|
7980
|
+
* Creates a `PharosChain` by auto-detecting the EVM chain ID and `IsmpHost`
|
|
7981
|
+
* address via {@link EvmChain.create}.
|
|
7982
|
+
*
|
|
7983
|
+
* @param rpcUrl - HTTP(S) JSON-RPC URL of the Pharos node
|
|
7984
|
+
* @param bundlerUrl - Optional ERC-4337 bundler URL forwarded to `EvmChain.create`
|
|
7985
|
+
*/
|
|
7986
|
+
static async create(rpcUrl, bundlerUrl) {
|
|
7987
|
+
const evm = await EvmChain.create(rpcUrl, bundlerUrl);
|
|
7988
|
+
const chainId = Number.parseInt(evm.config.stateMachineId.replace(/^EVM-/, ""), 10);
|
|
7989
|
+
if (!Number.isFinite(chainId)) {
|
|
7990
|
+
throw new Error(`Unexpected EVM stateMachineId: ${evm.config.stateMachineId}`);
|
|
7991
|
+
}
|
|
7992
|
+
const params = {
|
|
7993
|
+
chainId,
|
|
7994
|
+
rpcUrl: evm.config.rpcUrl,
|
|
7995
|
+
host: evm.config.host,
|
|
7996
|
+
consensusStateId: evm.config.consensusStateId,
|
|
7997
|
+
bundlerUrl: evm.bundlerUrl
|
|
7998
|
+
};
|
|
7999
|
+
return new _PharosChain(params, evm);
|
|
8000
|
+
}
|
|
8001
|
+
get client() {
|
|
8002
|
+
return this.evm.client;
|
|
8003
|
+
}
|
|
8004
|
+
get host() {
|
|
8005
|
+
return this.evm.host;
|
|
8006
|
+
}
|
|
8007
|
+
get bundlerUrl() {
|
|
8008
|
+
return this.evm.bundlerUrl;
|
|
8009
|
+
}
|
|
8010
|
+
get configService() {
|
|
8011
|
+
return this.evm.configService;
|
|
8012
|
+
}
|
|
8013
|
+
get config() {
|
|
8014
|
+
return this.evm.config;
|
|
8015
|
+
}
|
|
8016
|
+
hostAddress() {
|
|
8017
|
+
return getAddress(this.evm.host);
|
|
8018
|
+
}
|
|
8019
|
+
/**
|
|
8020
|
+
* Fetch a storage proof for `slotKeys` under `address` at the given block and
|
|
8021
|
+
* merge the response into the supplied accumulator. Mirrors the membership
|
|
8022
|
+
* proof path of `PharosEvmClient::fetch_pharos_proof` on the Rust side.
|
|
8023
|
+
*/
|
|
8024
|
+
async fetchStorageProofInto(acc, at, address, slotKeys) {
|
|
8025
|
+
const rpcProof = await this.rpc.call("eth_getProof", [
|
|
8026
|
+
address,
|
|
8027
|
+
slotKeys,
|
|
8028
|
+
blockTag(at)
|
|
8029
|
+
]);
|
|
8030
|
+
for (const sp of rpcProof.storageProof) {
|
|
8031
|
+
const slotKey = hexKey2(padTo32Bytes(sp.key));
|
|
8032
|
+
if (sp.isExist) {
|
|
8033
|
+
acc.storageProof.set(slotKey, rpcToProofNodes(sp.proof));
|
|
8034
|
+
acc.storageValues.set(slotKey, Array.from(padTo32Bytes(sp.value)));
|
|
8035
|
+
} else {
|
|
8036
|
+
acc.nonExistenceProofs.set(slotKey, {
|
|
8037
|
+
proofNodes: rpcToProofNodes(sp.proof),
|
|
8038
|
+
siblingProofs: rpcToSiblingProofs(sp.siblingLeftmostLeafProofs)
|
|
8039
|
+
});
|
|
8040
|
+
}
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
/**
|
|
8044
|
+
* Fetch an account proof (no storage keys) at the given block and record it on
|
|
8045
|
+
* the accumulator. Mirrors `PharosEvmClient::fetch_account_proof`.
|
|
8046
|
+
*/
|
|
8047
|
+
async fetchAccountProofInto(acc, at, address) {
|
|
8048
|
+
const rpcProof = await this.rpc.call("eth_getProof", [
|
|
8049
|
+
address,
|
|
8050
|
+
[],
|
|
8051
|
+
blockTag(at)
|
|
8052
|
+
]);
|
|
8053
|
+
const addrBytes = hexToBytes(address);
|
|
8054
|
+
acc.accountProofs.set(hexKey2(addrBytes), {
|
|
8055
|
+
proofNodes: rpcToProofNodes(rpcProof.accountProof),
|
|
8056
|
+
rawValue: Array.from(hexToBytes(rpcProof.rawValue))
|
|
8057
|
+
});
|
|
8058
|
+
}
|
|
8059
|
+
timestamp() {
|
|
8060
|
+
return this.evm.timestamp();
|
|
8061
|
+
}
|
|
8062
|
+
requestReceiptKey(commitment) {
|
|
8063
|
+
return this.evm.requestReceiptKey(commitment);
|
|
8064
|
+
}
|
|
8065
|
+
queryRequestReceipt(commitment) {
|
|
8066
|
+
return this.evm.queryRequestReceipt(commitment);
|
|
8067
|
+
}
|
|
8068
|
+
/**
|
|
8069
|
+
* Query a Pharos state proof for the request/response commitments in `message`.
|
|
8070
|
+
*
|
|
8071
|
+
* Mirrors `PharosEvmClient::query_requests_proof` / `query_responses_proof`:
|
|
8072
|
+
* for every commitment we derive the second storage slot (`slot1` from
|
|
8073
|
+
* {@link requestCommitmentKey} / {@link responseCommitmentKey}) and request it
|
|
8074
|
+
* from the ISMP host via `eth_getProof`.
|
|
8075
|
+
*/
|
|
8076
|
+
async queryProof(message, _counterparty, at) {
|
|
8077
|
+
if (at === void 0) {
|
|
8078
|
+
throw new Error("PharosChain.queryProof requires an explicit block height `at`");
|
|
8079
|
+
}
|
|
8080
|
+
const slotKeys = "Requests" in message ? message.Requests.map((c) => requestCommitmentKey(c).slot1) : message.Responses.map((c) => responseCommitmentKey(c));
|
|
8081
|
+
const acc = newAccumulator();
|
|
8082
|
+
await this.fetchStorageProofInto(acc, at, this.hostAddress(), slotKeys);
|
|
8083
|
+
return encodeAccumulator(acc);
|
|
8084
|
+
}
|
|
8085
|
+
/**
|
|
8086
|
+
* Query a Pharos state proof for arbitrary keys.
|
|
8087
|
+
*
|
|
8088
|
+
* Supports the same key shapes as `PharosEvmClient::query_state_proof`:
|
|
8089
|
+
* - 32-byte keys: ISMP host storage slots
|
|
8090
|
+
* - 52-byte keys: `address (20) || slot (32)` grouped by contract
|
|
8091
|
+
* - 20-byte keys: account queries (proves the account leaf itself)
|
|
8092
|
+
*
|
|
8093
|
+
* If `address` is provided, all keys are treated as 32-byte slots under that
|
|
8094
|
+
* contract (matching the `EvmChain.queryStateProof` contract-override shape).
|
|
8095
|
+
*/
|
|
8096
|
+
async queryStateProof(at, keys, address) {
|
|
8097
|
+
const acc = newAccumulator();
|
|
8098
|
+
if (address !== void 0) {
|
|
8099
|
+
await this.fetchStorageProofInto(acc, at, getAddress(address), keys);
|
|
8100
|
+
return encodeAccumulator(acc);
|
|
8101
|
+
}
|
|
8102
|
+
const keyBytes = keys.map((k) => hexToBytes(k));
|
|
8103
|
+
const hostAddr = this.hostAddress();
|
|
8104
|
+
const ismpSlots = [];
|
|
8105
|
+
const groups = /* @__PURE__ */ new Map();
|
|
8106
|
+
const accountQueries = [];
|
|
8107
|
+
for (const bytes of keyBytes) {
|
|
8108
|
+
if (bytes.length === 32) {
|
|
8109
|
+
ismpSlots.push(bytesToHex(bytes));
|
|
8110
|
+
} else if (bytes.length === 52) {
|
|
8111
|
+
const addr = getAddress(bytesToHex(bytes.subarray(0, 20)));
|
|
8112
|
+
const slot = bytesToHex(bytes.subarray(20, 52));
|
|
8113
|
+
const list = groups.get(addr) ?? [];
|
|
8114
|
+
list.push(slot);
|
|
8115
|
+
groups.set(addr, list);
|
|
8116
|
+
} else if (bytes.length === 20) {
|
|
8117
|
+
accountQueries.push(getAddress(bytesToHex(bytes)));
|
|
8118
|
+
} else {
|
|
8119
|
+
throw new Error(
|
|
8120
|
+
`PharosChain.queryStateProof: unsupported key length ${bytes.length}; expected 20, 32, or 52`
|
|
8121
|
+
);
|
|
8122
|
+
}
|
|
8123
|
+
}
|
|
8124
|
+
if (ismpSlots.length > 0) {
|
|
8125
|
+
await this.fetchStorageProofInto(acc, at, hostAddr, ismpSlots);
|
|
8126
|
+
}
|
|
8127
|
+
for (const [addr, slots] of groups) {
|
|
8128
|
+
await this.fetchStorageProofInto(acc, at, addr, slots);
|
|
8129
|
+
}
|
|
8130
|
+
for (const addr of accountQueries) {
|
|
8131
|
+
await this.fetchAccountProofInto(acc, at, addr);
|
|
8132
|
+
}
|
|
8133
|
+
return encodeAccumulator(acc);
|
|
8134
|
+
}
|
|
8135
|
+
encode(message) {
|
|
8136
|
+
return this.evm.encode(message);
|
|
8137
|
+
}
|
|
8138
|
+
latestStateMachineHeight(stateMachineId) {
|
|
8139
|
+
return this.evm.latestStateMachineHeight(stateMachineId);
|
|
8140
|
+
}
|
|
8141
|
+
challengePeriod(stateMachineId) {
|
|
8142
|
+
return this.evm.challengePeriod(stateMachineId);
|
|
8143
|
+
}
|
|
8144
|
+
stateMachineUpdateTime(stateMachineHeight) {
|
|
8145
|
+
return this.evm.stateMachineUpdateTime(stateMachineHeight);
|
|
8146
|
+
}
|
|
8147
|
+
getHostNonce() {
|
|
8148
|
+
return this.evm.getHostNonce();
|
|
8149
|
+
}
|
|
8150
|
+
quoteNative(request, fee) {
|
|
8151
|
+
return this.evm.quoteNative(request, fee);
|
|
8152
|
+
}
|
|
8153
|
+
getFeeTokenWithDecimals() {
|
|
8154
|
+
return this.evm.getFeeTokenWithDecimals();
|
|
8155
|
+
}
|
|
8156
|
+
getPlaceOrderCalldata(txHash, intentGatewayAddress) {
|
|
8157
|
+
return this.evm.getPlaceOrderCalldata(txHash, intentGatewayAddress);
|
|
8158
|
+
}
|
|
8159
|
+
estimateGas(request) {
|
|
8160
|
+
return this.evm.estimateGas(request);
|
|
8161
|
+
}
|
|
8162
|
+
broadcastTransaction(signedTransaction) {
|
|
8163
|
+
return this.evm.broadcastTransaction(signedTransaction);
|
|
8164
|
+
}
|
|
8165
|
+
getTransactionReceipt(hash) {
|
|
8166
|
+
return this.evm.getTransactionReceipt(hash);
|
|
8167
|
+
}
|
|
8168
|
+
};
|
|
7815
8169
|
function getPeakPosByHeight(height) {
|
|
7816
8170
|
return (1n << BigInt(height + 1)) - 2n;
|
|
7817
8171
|
}
|
|
@@ -15496,7 +15850,7 @@ var OrderExecutor = class {
|
|
|
15496
15850
|
async *executeOrder(options) {
|
|
15497
15851
|
const { order, sessionPrivateKey, auctionTimeMs, pollIntervalMs = DEFAULT_POLL_INTERVAL, solver } = options;
|
|
15498
15852
|
const commitment = order.id;
|
|
15499
|
-
|
|
15853
|
+
order.source === order.destination;
|
|
15500
15854
|
if (!this.ctx.intentsCoprocessor) {
|
|
15501
15855
|
yield { status: "FAILED", error: "IntentsCoprocessor required for order execution" };
|
|
15502
15856
|
return;
|
|
@@ -15525,10 +15879,15 @@ var OrderExecutor = class {
|
|
|
15525
15879
|
});
|
|
15526
15880
|
const deadlineTimeout = this.deadlineStream(order.deadline, commitment);
|
|
15527
15881
|
const combined = mergeRace(deadlineTimeout, executionStream);
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15882
|
+
try {
|
|
15883
|
+
for await (const update of combined) {
|
|
15884
|
+
yield update;
|
|
15885
|
+
if (update.status === "EXPIRED" || update.status === "FILLED") return;
|
|
15886
|
+
}
|
|
15887
|
+
} finally {
|
|
15888
|
+
console.log(`[OrderExecutor] Tearing down streams for commitment=${commitment}`);
|
|
15889
|
+
await executionStream.return(void 0);
|
|
15890
|
+
await deadlineTimeout.return(void 0);
|
|
15532
15891
|
}
|
|
15533
15892
|
}
|
|
15534
15893
|
/**
|
|
@@ -15549,6 +15908,12 @@ var OrderExecutor = class {
|
|
|
15549
15908
|
targetAssets
|
|
15550
15909
|
} = params;
|
|
15551
15910
|
let { totalFilledAssets, remainingAssets } = params;
|
|
15911
|
+
const MAX_BID_ATTEMPTS = 2;
|
|
15912
|
+
const bidFailCounts = /* @__PURE__ */ new Map();
|
|
15913
|
+
const isFreshBid = (bid) => {
|
|
15914
|
+
const key = userOpHashKey(bid.userOp);
|
|
15915
|
+
return !usedUserOps.has(key) && (bidFailCounts.get(key) ?? 0) < MAX_BID_ATTEMPTS;
|
|
15916
|
+
};
|
|
15552
15917
|
const solverLockStartTime = Date.now();
|
|
15553
15918
|
yield { status: "AWAITING_BIDS", commitment, totalFilledAssets, remainingAssets };
|
|
15554
15919
|
try {
|
|
@@ -15576,7 +15941,7 @@ var OrderExecutor = class {
|
|
|
15576
15941
|
let freshBids;
|
|
15577
15942
|
try {
|
|
15578
15943
|
const bids = await this.fetchBids({ commitment, solver, solverLockStartTime });
|
|
15579
|
-
freshBids = bids.filter(
|
|
15944
|
+
freshBids = bids.filter(isFreshBid);
|
|
15580
15945
|
} catch {
|
|
15581
15946
|
await sleep(pollIntervalMs);
|
|
15582
15947
|
continue;
|
|
@@ -15604,6 +15969,14 @@ var OrderExecutor = class {
|
|
|
15604
15969
|
remainingAssets,
|
|
15605
15970
|
error: `Failed to select bid and submit: ${err instanceof Error ? err.message : String(err)}`
|
|
15606
15971
|
};
|
|
15972
|
+
try {
|
|
15973
|
+
const sorted = await this.bidManager.validateAndSortBids(freshBids, order);
|
|
15974
|
+
if (sorted.length > 0) {
|
|
15975
|
+
const key = userOpHashKey(sorted[0].bid.userOp);
|
|
15976
|
+
bidFailCounts.set(key, (bidFailCounts.get(key) ?? 0) + 1);
|
|
15977
|
+
}
|
|
15978
|
+
} catch {
|
|
15979
|
+
}
|
|
15607
15980
|
await sleep(pollIntervalMs);
|
|
15608
15981
|
continue;
|
|
15609
15982
|
}
|
|
@@ -19206,9 +19579,9 @@ async function fetchLocalAssetId(params) {
|
|
|
19206
19579
|
const palletPrefix = xxhashAsU8a("TokenGateway", 128);
|
|
19207
19580
|
const storagePrefix = xxhashAsU8a("LocalAssets", 128);
|
|
19208
19581
|
const full_key = new Uint8Array([...palletPrefix, ...storagePrefix, ...assetId]);
|
|
19209
|
-
const
|
|
19582
|
+
const hexKey3 = bytesToHex(full_key);
|
|
19210
19583
|
const storage_value = await api.rpc.state.getStorage(
|
|
19211
|
-
|
|
19584
|
+
hexKey3
|
|
19212
19585
|
);
|
|
19213
19586
|
if (storage_value.isSome) {
|
|
19214
19587
|
const assetId2 = storage_value.value.toU8a();
|
|
@@ -19481,6 +19854,6 @@ async function teleportDot(param_) {
|
|
|
19481
19854
|
return stream;
|
|
19482
19855
|
}
|
|
19483
19856
|
|
|
19484
|
-
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, IndexerClient, IntentGateway, ABI7 as IntentGatewayV2ABI, IntentOrderStatus, IntentsCoprocessor, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, USE_ETHERSCAN_CHAINS, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, orderCommitment, parseStateMachineId, polkadotAssetHubPaseo, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
19857
|
+
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, IndexerClient, IntentGateway, ABI7 as IntentGatewayV2ABI, IntentOrderStatus, IntentsCoprocessor, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, USE_ETHERSCAN_CHAINS, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
19485
19858
|
//# sourceMappingURL=index.js.map
|
|
19486
19859
|
//# sourceMappingURL=index.js.map
|