@hyperbridge/sdk 2.2.3 → 2.3.1
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 +129 -24
- package/dist/browser/index.js +539 -111
- package/dist/browser/index.js.map +1 -1
- package/dist/node/IntentGatewayV2-SB851bZs.d.cts +5750 -0
- package/dist/node/IntentGatewayV2-SB851bZs.d.ts +5750 -0
- package/dist/node/index.cjs +539 -109
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1500 -5743
- package/dist/node/index.d.ts +1500 -5743
- package/dist/node/index.js +539 -111
- package/dist/node/index.js.map +1 -1
- package/dist/node/intents-helpers.cjs +2084 -0
- package/dist/node/intents-helpers.cjs.map +1 -0
- package/dist/node/intents-helpers.d.cts +1469 -0
- package/dist/node/intents-helpers.d.ts +1469 -0
- package/dist/node/intents-helpers.js +2072 -0
- package/dist/node/intents-helpers.js.map +1 -0
- package/package.json +16 -1
package/dist/node/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ var api = require('@polkadot/api');
|
|
|
13
13
|
var scaleTs = require('scale-ts');
|
|
14
14
|
var utilCrypto = require('@polkadot/util-crypto');
|
|
15
15
|
var util = require('@polkadot/util');
|
|
16
|
+
var PQueue = require('p-queue');
|
|
16
17
|
var stdEnv = require('std-env');
|
|
17
18
|
var mergeRace = require('@async-generator/merge-race');
|
|
18
19
|
var graphqlRequest = require('graphql-request');
|
|
@@ -25,6 +26,7 @@ var Decimal2 = require('decimal.js');
|
|
|
25
26
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
26
27
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
28
|
|
|
29
|
+
var PQueue__default = /*#__PURE__*/_interopDefault(PQueue);
|
|
28
30
|
var mergeRace__default = /*#__PURE__*/_interopDefault(mergeRace);
|
|
29
31
|
var inMemoryDriver__default = /*#__PURE__*/_interopDefault(inMemoryDriver);
|
|
30
32
|
var fsDriver__default = /*#__PURE__*/_interopDefault(fsDriver);
|
|
@@ -524,6 +526,11 @@ var ABI = [
|
|
|
524
526
|
name: "context",
|
|
525
527
|
type: "bytes",
|
|
526
528
|
internalType: "bytes"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: "payer",
|
|
532
|
+
type: "address",
|
|
533
|
+
internalType: "address"
|
|
527
534
|
}
|
|
528
535
|
]
|
|
529
536
|
}
|
|
@@ -2104,7 +2111,7 @@ var ABI2 = [
|
|
|
2104
2111
|
{ internalType: "bytes", name: "source", type: "bytes" },
|
|
2105
2112
|
{ internalType: "bytes", name: "dest", type: "bytes" },
|
|
2106
2113
|
{ internalType: "uint64", name: "nonce", type: "uint64" },
|
|
2107
|
-
{ internalType: "
|
|
2114
|
+
{ internalType: "bytes", name: "from", type: "bytes" },
|
|
2108
2115
|
{ internalType: "uint64", name: "timeoutTimestamp", type: "uint64" },
|
|
2109
2116
|
{ internalType: "bytes[]", name: "keys", type: "bytes[]" },
|
|
2110
2117
|
{ internalType: "uint64", name: "height", type: "uint64" },
|
|
@@ -2171,7 +2178,7 @@ var ABI2 = [
|
|
|
2171
2178
|
{ internalType: "bytes", name: "source", type: "bytes" },
|
|
2172
2179
|
{ internalType: "bytes", name: "dest", type: "bytes" },
|
|
2173
2180
|
{ internalType: "uint64", name: "nonce", type: "uint64" },
|
|
2174
|
-
{ internalType: "
|
|
2181
|
+
{ internalType: "bytes", name: "from", type: "bytes" },
|
|
2175
2182
|
{ internalType: "uint64", name: "timeoutTimestamp", type: "uint64" },
|
|
2176
2183
|
{ internalType: "bytes[]", name: "keys", type: "bytes[]" },
|
|
2177
2184
|
{ internalType: "uint64", name: "height", type: "uint64" },
|
|
@@ -2579,9 +2586,9 @@ var chainConfigs = {
|
|
|
2579
2586
|
USDT: { balanceSlot: 151, allowanceSlot: 152 }
|
|
2580
2587
|
},
|
|
2581
2588
|
addresses: {
|
|
2582
|
-
IntentGateway: "
|
|
2589
|
+
IntentGateway: "0x6CF42FA9BecbC5b6a26884964956b113530f7cFA",
|
|
2583
2590
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2584
|
-
Host: "
|
|
2591
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
2585
2592
|
UniswapRouter02: "0x9639379819420704457B07A0C33B678D9E0F8Df0",
|
|
2586
2593
|
UniswapV2Factory: "0x12e036669DA18F4A2777853d6e2136b32AceEC86",
|
|
2587
2594
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -2589,7 +2596,7 @@ var chainConfigs = {
|
|
|
2589
2596
|
UniswapV3Quoter: "0x0000000000000000000000000000000000000000",
|
|
2590
2597
|
UniswapV4Quoter: "0x0000000000000000000000000000000000000000",
|
|
2591
2598
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
2592
|
-
SolverAccount: "
|
|
2599
|
+
SolverAccount: "0x07FeC66d967800998060194EaECDd7C66dA4a1B1"
|
|
2593
2600
|
},
|
|
2594
2601
|
rpcEnvKey: "BSC_CHAPEL",
|
|
2595
2602
|
defaultRpcUrl: "https://bnb-testnet.api.onfinality.io/public",
|
|
@@ -2620,7 +2627,7 @@ var chainConfigs = {
|
|
|
2620
2627
|
addresses: {
|
|
2621
2628
|
IntentGateway: "0x016b6ffC9f890d1e28f9Fdb9eaDA776b02F89509",
|
|
2622
2629
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2623
|
-
Host: "
|
|
2630
|
+
Host: "0x58A41B89F4871725E5D898d98eF4BF917601c5eB",
|
|
2624
2631
|
UniswapRouter02: "0x0000000000000000000000000000000000000000",
|
|
2625
2632
|
UniswapV2Factory: "0x0000000000000000000000000000000000000000",
|
|
2626
2633
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -2659,7 +2666,7 @@ var chainConfigs = {
|
|
|
2659
2666
|
addresses: {
|
|
2660
2667
|
IntentGateway: "0x016b6ffC9f890d1e28f9Fdb9eaDA776b02F89509",
|
|
2661
2668
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2662
|
-
Host: "
|
|
2669
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
2663
2670
|
UniswapRouter02: "0x0000000000000000000000000000000000000000",
|
|
2664
2671
|
UniswapV2Factory: "0x0000000000000000000000000000000000000000",
|
|
2665
2672
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -3005,13 +3012,13 @@ var chainConfigs = {
|
|
|
3005
3012
|
USDC: { balanceSlot: 1, allowanceSlot: 2 }
|
|
3006
3013
|
},
|
|
3007
3014
|
addresses: {
|
|
3008
|
-
IntentGateway: "
|
|
3015
|
+
IntentGateway: "0x6CF42FA9BecbC5b6a26884964956b113530f7cFA",
|
|
3009
3016
|
TokenGateway: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
|
|
3010
|
-
Host: "
|
|
3017
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3011
3018
|
Calldispatcher: "0x876F1891982E260026630c233A4897160A281Fb8",
|
|
3012
3019
|
Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
3013
3020
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
3014
|
-
SolverAccount: "
|
|
3021
|
+
SolverAccount: "0x07FeC66d967800998060194EaECDd7C66dA4a1B1"
|
|
3015
3022
|
},
|
|
3016
3023
|
rpcEnvKey: "POLYGON_AMOY",
|
|
3017
3024
|
defaultRpcUrl: "https://rpc-amoy.polygon.technology",
|
|
@@ -3127,7 +3134,7 @@ var chainConfigs = {
|
|
|
3127
3134
|
},
|
|
3128
3135
|
addresses: {
|
|
3129
3136
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3130
|
-
Host: "
|
|
3137
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3131
3138
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3132
3139
|
},
|
|
3133
3140
|
defaultRpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
@@ -3151,7 +3158,7 @@ var chainConfigs = {
|
|
|
3151
3158
|
},
|
|
3152
3159
|
addresses: {
|
|
3153
3160
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3154
|
-
Host: "
|
|
3161
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3155
3162
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3156
3163
|
},
|
|
3157
3164
|
defaultRpcUrl: "https://sepolia.optimism.io",
|
|
@@ -3175,7 +3182,7 @@ var chainConfigs = {
|
|
|
3175
3182
|
},
|
|
3176
3183
|
addresses: {
|
|
3177
3184
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3178
|
-
Host: "
|
|
3185
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3179
3186
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3180
3187
|
},
|
|
3181
3188
|
defaultRpcUrl: "https://sepolia.base.org",
|
|
@@ -3201,7 +3208,7 @@ var chainConfigs = {
|
|
|
3201
3208
|
addresses: {
|
|
3202
3209
|
IntentGateway: "0x606ba811aa6cb424ce2108e8977c5284686f0d1f",
|
|
3203
3210
|
TokenGateway: "0x1c1e5be83df4a54c7a2230c337e4a3e8b7354b1c",
|
|
3204
|
-
Host: "
|
|
3211
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3205
3212
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3206
3213
|
},
|
|
3207
3214
|
defaultRpcUrl: "https://testnet-asset-hub-eth-rpc.polkadot.io",
|
|
@@ -3251,7 +3258,7 @@ var chainConfigs = {
|
|
|
3251
3258
|
wrappedNativeDecimals: 18,
|
|
3252
3259
|
addresses: {
|
|
3253
3260
|
TokenGateway: "0x451bDd8273839AD0Ec7F4Fa798E8B3DABb223fD8",
|
|
3254
|
-
Host: "
|
|
3261
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3255
3262
|
IntentGateway: "0xb8039832c6c9266F928d038eA49A8a169300C670"
|
|
3256
3263
|
},
|
|
3257
3264
|
consensusStateId: "PHAR",
|
|
@@ -4383,6 +4390,11 @@ var ABI3 = [
|
|
|
4383
4390
|
name: "context",
|
|
4384
4391
|
type: "bytes",
|
|
4385
4392
|
internalType: "bytes"
|
|
4393
|
+
},
|
|
4394
|
+
{
|
|
4395
|
+
name: "payer",
|
|
4396
|
+
type: "address",
|
|
4397
|
+
internalType: "address"
|
|
4386
4398
|
}
|
|
4387
4399
|
]
|
|
4388
4400
|
}
|
|
@@ -6391,28 +6403,60 @@ var EvmChain = class _EvmChain {
|
|
|
6391
6403
|
}
|
|
6392
6404
|
/**
|
|
6393
6405
|
* Query and return the encoded storage proof for the provided keys at the given height.
|
|
6406
|
+
*
|
|
6407
|
+
* Keys may be either:
|
|
6408
|
+
* - 32-byte storage slots — read from `address` (or the host contract when omitted), or
|
|
6409
|
+
* - 52-byte cross-chain GET keys encoded as `address(20) || slot(32)`, where the target
|
|
6410
|
+
* contract is embedded in the key. These may span multiple contracts.
|
|
6411
|
+
*
|
|
6394
6412
|
* @param {bigint} at - The block height at which to query the storage proof.
|
|
6395
6413
|
* @param {HexString[]} keys - The keys for which to query the storage proof.
|
|
6396
|
-
* @param {HexString} address - Optional contract address
|
|
6414
|
+
* @param {HexString} address - Optional contract address; forces all keys to be read as slots
|
|
6415
|
+
* of this contract. Omit to let 52-byte keys carry their own contract address.
|
|
6397
6416
|
* @returns {Promise<HexString>} The encoded storage proof.
|
|
6398
6417
|
*/
|
|
6399
6418
|
async queryStateProof(at, keys, address) {
|
|
6400
|
-
const
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6419
|
+
const slotsByContract = /* @__PURE__ */ new Map();
|
|
6420
|
+
for (const key of keys) {
|
|
6421
|
+
let contract;
|
|
6422
|
+
let slot;
|
|
6423
|
+
if (address) {
|
|
6424
|
+
contract = address.toLowerCase();
|
|
6425
|
+
slot = key;
|
|
6426
|
+
} else if ((key.length - 2) / 2 === 52) {
|
|
6427
|
+
contract = key.slice(0, 42).toLowerCase();
|
|
6428
|
+
slot = `0x${key.slice(42)}`;
|
|
6429
|
+
} else {
|
|
6430
|
+
contract = this.params.host.toLowerCase();
|
|
6431
|
+
slot = key;
|
|
6432
|
+
}
|
|
6433
|
+
const slots = slotsByContract.get(contract) ?? [];
|
|
6434
|
+
slots.push(slot);
|
|
6435
|
+
slotsByContract.set(contract, slots);
|
|
6436
|
+
}
|
|
6437
|
+
const contracts = Array.from(slotsByContract.entries());
|
|
6438
|
+
const proofs = await Promise.all(
|
|
6439
|
+
contracts.map(([contract, slots]) => {
|
|
6440
|
+
const config = { address: contract, storageKeys: slots };
|
|
6441
|
+
if (!at) {
|
|
6442
|
+
config.blockTag = "latest";
|
|
6443
|
+
} else {
|
|
6444
|
+
config.blockNumber = at;
|
|
6445
|
+
}
|
|
6446
|
+
return this.publicClient.getProof(config);
|
|
6447
|
+
})
|
|
6448
|
+
);
|
|
6449
|
+
const contractProof = Array.from(new Set(lodashEs.flatten(proofs.map((proof) => proof.accountProof))));
|
|
6450
|
+
const storageProof = contracts.map(([contract], i) => {
|
|
6451
|
+
const flattened = Array.from(new Set(lodashEs.flatten(proofs[i].storageProof.map((item) => item.proof))));
|
|
6452
|
+
return [
|
|
6453
|
+
Array.from(viem.hexToBytes(contract)),
|
|
6454
|
+
flattened.map((item) => Array.from(viem.hexToBytes(item)))
|
|
6455
|
+
];
|
|
6456
|
+
});
|
|
6411
6457
|
const encoded = EvmStateProof.enc({
|
|
6412
|
-
contractProof:
|
|
6413
|
-
storageProof
|
|
6414
|
-
[Array.from(viem.hexToBytes(config.address)), flattenedProof.map((item) => Array.from(viem.hexToBytes(item)))]
|
|
6415
|
-
]
|
|
6458
|
+
contractProof: contractProof.map((item) => Array.from(viem.hexToBytes(item))),
|
|
6459
|
+
storageProof
|
|
6416
6460
|
});
|
|
6417
6461
|
return viem.toHex(encoded);
|
|
6418
6462
|
}
|
|
@@ -7134,6 +7178,49 @@ var SubstrateChain = class _SubstrateChain {
|
|
|
7134
7178
|
const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
|
|
7135
7179
|
return item;
|
|
7136
7180
|
}
|
|
7181
|
+
/**
|
|
7182
|
+
* Returns the storage key for a response receipt in the child trie.
|
|
7183
|
+
* A response receipt is keyed by the originating *request* commitment.
|
|
7184
|
+
* @param {HexString} key - The request commitment (0x-prefixed H256 hex string)
|
|
7185
|
+
* @returns {HexString} The storage key as a hex string
|
|
7186
|
+
*/
|
|
7187
|
+
responseReceiptKey(key) {
|
|
7188
|
+
const prefix = new TextEncoder().encode("ResponseReceipts");
|
|
7189
|
+
const keyBytes = viem.hexToBytes(key);
|
|
7190
|
+
return viem.bytesToHex(new Uint8Array([...prefix, ...keyBytes]));
|
|
7191
|
+
}
|
|
7192
|
+
/**
|
|
7193
|
+
* Queries the response receipt for a request commitment. For a GET, Hyperbridge
|
|
7194
|
+
* produces the response as it processes the request, so the presence of a response
|
|
7195
|
+
* receipt indicates the request has already been delivered and handled.
|
|
7196
|
+
* @param {HexString} commitment - The originating request commitment to query.
|
|
7197
|
+
* @returns {Promise<HexString | undefined>} The receipt data if present, otherwise undefined.
|
|
7198
|
+
*/
|
|
7199
|
+
async queryResponseReceipt(commitment) {
|
|
7200
|
+
const prefix = viem.toHex(":child_storage:default:ISMP");
|
|
7201
|
+
const key = this.responseReceiptKey(commitment);
|
|
7202
|
+
const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
|
|
7203
|
+
return item;
|
|
7204
|
+
}
|
|
7205
|
+
/**
|
|
7206
|
+
* Queries the state-machine commitment Hyperbridge holds for a counterparty chain at an
|
|
7207
|
+
* exact height — the `BoundedStateCommitments` map that `state_machine_commitment` (and thus
|
|
7208
|
+
* proof verification) reads. Returns the committed `stateRoot`, or undefined if Hyperbridge
|
|
7209
|
+
* has not finalized that chain at exactly that height.
|
|
7210
|
+
* @param {StateMachineHeight} height - The counterparty state machine id + height.
|
|
7211
|
+
* @returns {Promise<HexString | undefined>} The committed state root, or undefined if absent.
|
|
7212
|
+
*/
|
|
7213
|
+
async queryStateMachineCommitment(height) {
|
|
7214
|
+
if (!this.api) throw new Error("API not initialized");
|
|
7215
|
+
const id = {
|
|
7216
|
+
stateId: height.id.stateId,
|
|
7217
|
+
// on-chain StateMachineId encodes consensusStateId as [u8; 4]
|
|
7218
|
+
consensusStateId: viem.toHex(viem.toBytes(height.id.consensusStateId))
|
|
7219
|
+
};
|
|
7220
|
+
const commitment = await this.api.query.ismp.boundedStateCommitments(id, Number(height.height));
|
|
7221
|
+
if (commitment.isNone) return void 0;
|
|
7222
|
+
return commitment.toJSON()?.stateRoot;
|
|
7223
|
+
}
|
|
7137
7224
|
/**
|
|
7138
7225
|
* Returns the current timestamp of the chain.
|
|
7139
7226
|
* @returns {Promise<bigint>} The current timestamp.
|
|
@@ -7543,6 +7630,7 @@ function encodeISMPMessage(message) {
|
|
|
7543
7630
|
}
|
|
7544
7631
|
}
|
|
7545
7632
|
var OFFCHAIN_BID_PREFIX = new TextEncoder().encode("intents::bid::");
|
|
7633
|
+
var OFFCHAIN_PHANTOM_PREFIX = new TextEncoder().encode("intents::phantom::order::");
|
|
7546
7634
|
var BidCodec = scaleTs.Struct({ filler: scaleTs.Bytes(32), user_op: scaleTs.Vector(scaleTs.u8) });
|
|
7547
7635
|
var PackedUserOperationCodec = scaleTs.Struct({
|
|
7548
7636
|
sender: scaleTs.Bytes(20),
|
|
@@ -7603,6 +7691,11 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7603
7691
|
ownsConnection;
|
|
7604
7692
|
/** Cached result of whether the node exposes intents_* RPC methods */
|
|
7605
7693
|
hasIntentsRpc = null;
|
|
7694
|
+
// Serialises every extrinsic submission on this instance's substrate account. All submit/retract
|
|
7695
|
+
// methods funnel through signAndSendExtrinsic, each using the API's auto-nonce; fired in parallel
|
|
7696
|
+
// (bids for orders on different chains, or several phantom orders in one interval) they would grab
|
|
7697
|
+
// the same nonce and all but one would fail. Concurrency 1 sequences them.
|
|
7698
|
+
submissionQueue = new PQueue__default.default({ concurrency: 1 });
|
|
7606
7699
|
/**
|
|
7607
7700
|
* Creates and connects an IntentsCoprocessor to a Hyperbridge node.
|
|
7608
7701
|
* This creates and manages its own API connection.
|
|
@@ -7655,14 +7748,17 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7655
7748
|
}
|
|
7656
7749
|
}
|
|
7657
7750
|
/**
|
|
7658
|
-
* Creates a Substrate keypair from the configured private key
|
|
7659
|
-
* Supports
|
|
7751
|
+
* Creates a Substrate keypair from the configured private key.
|
|
7752
|
+
* Supports hex seed (with or without 0x), mnemonic phrases, and URI derivation paths (//Alice).
|
|
7660
7753
|
*/
|
|
7661
7754
|
getKeyPair() {
|
|
7662
7755
|
if (!this.substratePrivateKey) {
|
|
7663
7756
|
throw new Error("Substrate PrivateKey Required");
|
|
7664
7757
|
}
|
|
7665
7758
|
const keyring = new api.Keyring({ type: "sr25519" });
|
|
7759
|
+
if (this.substratePrivateKey.startsWith("//")) {
|
|
7760
|
+
return keyring.addFromUri(this.substratePrivateKey);
|
|
7761
|
+
}
|
|
7666
7762
|
if (this.substratePrivateKey.includes(" ")) {
|
|
7667
7763
|
return keyring.addFromMnemonic(this.substratePrivateKey);
|
|
7668
7764
|
}
|
|
@@ -7671,10 +7767,19 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7671
7767
|
return keyring.addFromSeed(seedBytes);
|
|
7672
7768
|
}
|
|
7673
7769
|
/**
|
|
7674
|
-
* Signs and sends an extrinsic
|
|
7675
|
-
*
|
|
7770
|
+
* Signs and sends an extrinsic. Submissions are serialised through {@link submissionQueue} so
|
|
7771
|
+
* concurrent calls never collide on the substrate account nonce — each extrinsic reaches a block
|
|
7772
|
+
* before the next is signed.
|
|
7676
7773
|
*/
|
|
7677
7774
|
async signAndSendExtrinsic(extrinsic, maxRetries = 3, timeoutMs = 3e4) {
|
|
7775
|
+
const result = await this.submissionQueue.add(() => this.sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs));
|
|
7776
|
+
return result ?? { success: false, error: "Submission queue returned no result" };
|
|
7777
|
+
}
|
|
7778
|
+
/**
|
|
7779
|
+
* Signs and sends an extrinsic, handling status updates and errors.
|
|
7780
|
+
* Implements retry logic with progressive tip increases for stuck transactions.
|
|
7781
|
+
*/
|
|
7782
|
+
async sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs) {
|
|
7678
7783
|
const keyPair = this.getKeyPair();
|
|
7679
7784
|
let baseTip = 500000000000n;
|
|
7680
7785
|
let attempt = 0;
|
|
@@ -7719,20 +7824,51 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7719
7824
|
}, timeoutMs);
|
|
7720
7825
|
extrinsic.signAndSend(keyPair, { tip }, (result) => {
|
|
7721
7826
|
if (resolved) return;
|
|
7722
|
-
if (result.status.isInBlock || result.status.isFinalized) {
|
|
7827
|
+
if (result.dispatchError && (result.status.isInBlock || result.status.isFinalized)) {
|
|
7723
7828
|
resolved = true;
|
|
7724
7829
|
clearTimeout(timeoutId);
|
|
7830
|
+
let errorMsg;
|
|
7831
|
+
if (result.dispatchError.isModule) {
|
|
7832
|
+
const decoded = this.api.registry.findMetaError(result.dispatchError.asModule);
|
|
7833
|
+
errorMsg = `Dispatch error: ${decoded.section}::${decoded.name}`;
|
|
7834
|
+
} else {
|
|
7835
|
+
errorMsg = `Dispatch error: ${result.dispatchError.toString()}`;
|
|
7836
|
+
}
|
|
7725
7837
|
resolve({
|
|
7726
|
-
success:
|
|
7727
|
-
|
|
7728
|
-
extrinsicHash: extrinsic.hash.toHex()
|
|
7838
|
+
success: false,
|
|
7839
|
+
error: errorMsg
|
|
7729
7840
|
});
|
|
7730
|
-
} else if (result.
|
|
7841
|
+
} else if (result.status.isDropped || result.status.isInvalid || result.status.isUsurped || result.status.isFinalityTimeout) {
|
|
7731
7842
|
resolved = true;
|
|
7732
7843
|
clearTimeout(timeoutId);
|
|
7733
7844
|
resolve({
|
|
7734
7845
|
success: false,
|
|
7735
|
-
error: `
|
|
7846
|
+
error: `Transaction ${result.status.type.toLowerCase()}`
|
|
7847
|
+
});
|
|
7848
|
+
} else if (result.status.isInBlock || result.status.isFinalized) {
|
|
7849
|
+
resolved = true;
|
|
7850
|
+
clearTimeout(timeoutId);
|
|
7851
|
+
const interrupted = result.events.find(
|
|
7852
|
+
({ event }) => event.section === "utility" && event.method === "BatchInterrupted"
|
|
7853
|
+
);
|
|
7854
|
+
if (interrupted) {
|
|
7855
|
+
const [indexCodec, dispatchError] = interrupted.event.data;
|
|
7856
|
+
if (Number(indexCodec.toString()) === 0) {
|
|
7857
|
+
let errorMsg;
|
|
7858
|
+
if (dispatchError?.isModule) {
|
|
7859
|
+
const decoded = this.api.registry.findMetaError(dispatchError.asModule);
|
|
7860
|
+
errorMsg = `Dispatch error: ${decoded.section}::${decoded.name}`;
|
|
7861
|
+
} else {
|
|
7862
|
+
errorMsg = `Dispatch error: batch interrupted (${dispatchError?.toString()})`;
|
|
7863
|
+
}
|
|
7864
|
+
resolve({ success: false, error: errorMsg });
|
|
7865
|
+
return;
|
|
7866
|
+
}
|
|
7867
|
+
}
|
|
7868
|
+
resolve({
|
|
7869
|
+
success: true,
|
|
7870
|
+
blockHash: (result.status.isInBlock ? result.status.asInBlock : result.status.asFinalized).toHex(),
|
|
7871
|
+
extrinsicHash: extrinsic.hash.toHex()
|
|
7736
7872
|
});
|
|
7737
7873
|
}
|
|
7738
7874
|
}).then((unsub) => {
|
|
@@ -7787,6 +7923,40 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7787
7923
|
};
|
|
7788
7924
|
}
|
|
7789
7925
|
}
|
|
7926
|
+
/**
|
|
7927
|
+
* Places a new bid and retracts a previous one in a single transaction via utility.batch.
|
|
7928
|
+
*
|
|
7929
|
+
* The new bid is the primary operation, so `placeBid` MUST run first. `utility.batch` is
|
|
7930
|
+
* non-atomic: a failing call interrupts the batch (via a BatchInterrupted event) without
|
|
7931
|
+
* reverting the calls that already succeeded. Placing first guarantees the new bid lands even
|
|
7932
|
+
* when the retraction then fails — which it routinely does, because a previous commitment's bid
|
|
7933
|
+
* may already be gone (or was itself never placed), making `retractBid` return `BidNotFound`.
|
|
7934
|
+
*
|
|
7935
|
+
* Ordering retraction first (the previous behaviour) caused a self-sustaining cascade: a
|
|
7936
|
+
* `BidNotFound` on the leading retract skipped the trailing `placeBid`, so the current bid never
|
|
7937
|
+
* landed, so the *next* interval's retract of that never-placed commitment also failed, and so
|
|
7938
|
+
* on — silently, because the batch extrinsic itself reports success. The deposit reclaim is
|
|
7939
|
+
* best-effort; landing the bid is not.
|
|
7940
|
+
*
|
|
7941
|
+
* @param retractCommitment - The order commitment of the bid to retract (bytes32)
|
|
7942
|
+
* @param bidCommitment - The order commitment of the new bid (bytes32)
|
|
7943
|
+
* @param userOp - The encoded PackedUserOperation as hex string
|
|
7944
|
+
* @returns BidSubmissionResult with success status and block/extrinsic hash
|
|
7945
|
+
*/
|
|
7946
|
+
async submitBidWithRetraction(retractCommitment, bidCommitment, userOp) {
|
|
7947
|
+
try {
|
|
7948
|
+
const batch = this.api.tx.utility.batch([
|
|
7949
|
+
this.api.tx.intentsCoprocessor.placeBid(bidCommitment, userOp),
|
|
7950
|
+
this.api.tx.intentsCoprocessor.retractBid(retractCommitment)
|
|
7951
|
+
]);
|
|
7952
|
+
return await this.signAndSendExtrinsic(batch);
|
|
7953
|
+
} catch (error) {
|
|
7954
|
+
return {
|
|
7955
|
+
success: false,
|
|
7956
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
7957
|
+
};
|
|
7958
|
+
}
|
|
7959
|
+
}
|
|
7790
7960
|
/**
|
|
7791
7961
|
* Fetches all bid storage entries for a given order commitment.
|
|
7792
7962
|
* Returns the on-chain data only (filler addresses and deposits).
|
|
@@ -7871,6 +8041,80 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7871
8041
|
buildOffchainBidKey(commitment, filler) {
|
|
7872
8042
|
return util.u8aConcat(OFFCHAIN_BID_PREFIX, util.hexToU8a(commitment), utilCrypto.decodeAddress(filler));
|
|
7873
8043
|
}
|
|
8044
|
+
/**
|
|
8045
|
+
* Fetches the ABI-encoded phantom order from offchain storage and decodes it
|
|
8046
|
+
* into an `Order` object. The pallet writes the order bytes under the key
|
|
8047
|
+
* `intents::phantom::order::<commitment>` when it calls `on_initialize`.
|
|
8048
|
+
*
|
|
8049
|
+
* Returns `null` if the key is absent (e.g. the node is not an offchain worker
|
|
8050
|
+
* or the commitment has expired and been cleared).
|
|
8051
|
+
*/
|
|
8052
|
+
async fetchPhantomOrder(commitment) {
|
|
8053
|
+
const key = util.u8aConcat(OFFCHAIN_PHANTOM_PREFIX, util.hexToU8a(commitment));
|
|
8054
|
+
const result = await this.api.rpc.offchain.localStorageGet("PERSISTENT", util.u8aToHex(key));
|
|
8055
|
+
if (!result || result.isNone) return null;
|
|
8056
|
+
const rawHex = result.unwrap().toHex();
|
|
8057
|
+
if (rawHex === "0x" || rawHex === "0x00") return null;
|
|
8058
|
+
const placeOrderAbi = IntentGatewayV2_default.ABI.find(
|
|
8059
|
+
(item) => item.type === "function" && item.name === "placeOrder"
|
|
8060
|
+
);
|
|
8061
|
+
const orderType = placeOrderAbi?.inputs?.[0];
|
|
8062
|
+
if (!orderType) return null;
|
|
8063
|
+
const [decoded] = viem.decodeAbiParameters([orderType], rawHex);
|
|
8064
|
+
const d = decoded;
|
|
8065
|
+
const textDecoder = new TextDecoder();
|
|
8066
|
+
return {
|
|
8067
|
+
id: commitment,
|
|
8068
|
+
user: d.user,
|
|
8069
|
+
source: textDecoder.decode(viem.hexToBytes(d.source)),
|
|
8070
|
+
destination: textDecoder.decode(viem.hexToBytes(d.destination)),
|
|
8071
|
+
deadline: d.deadline,
|
|
8072
|
+
nonce: d.nonce,
|
|
8073
|
+
fees: d.fees,
|
|
8074
|
+
session: d.session,
|
|
8075
|
+
predispatch: {
|
|
8076
|
+
assets: d.predispatch.assets.map((a) => ({
|
|
8077
|
+
token: a.token,
|
|
8078
|
+
amount: a.amount
|
|
8079
|
+
})),
|
|
8080
|
+
call: d.predispatch.call
|
|
8081
|
+
},
|
|
8082
|
+
inputs: d.inputs.map((i) => ({
|
|
8083
|
+
token: i.token,
|
|
8084
|
+
amount: i.amount
|
|
8085
|
+
})),
|
|
8086
|
+
output: {
|
|
8087
|
+
beneficiary: d.output.beneficiary,
|
|
8088
|
+
assets: d.output.assets.map((a) => ({
|
|
8089
|
+
token: a.token,
|
|
8090
|
+
amount: a.amount
|
|
8091
|
+
})),
|
|
8092
|
+
call: d.output.call
|
|
8093
|
+
}
|
|
8094
|
+
};
|
|
8095
|
+
}
|
|
8096
|
+
/**
|
|
8097
|
+
* Subscribes to PhantomOrderRegistered events from the intents coprocessor pallet.
|
|
8098
|
+
* Calls the callback for each new phantom order as blocks arrive.
|
|
8099
|
+
* Returns an unsubscribe function to stop the subscription.
|
|
8100
|
+
*/
|
|
8101
|
+
async subscribePhantomOrders(callback) {
|
|
8102
|
+
const unsub = await this.api.query.system.events((records) => {
|
|
8103
|
+
for (const { event } of records) {
|
|
8104
|
+
if (event.section !== "intentsCoprocessor" || event.method !== "PhantomOrderRegistered") continue;
|
|
8105
|
+
const [commitment, chain, createdAt, tokenA, tokenB, standardAmount] = event.data;
|
|
8106
|
+
callback({
|
|
8107
|
+
commitment: commitment.toHex(),
|
|
8108
|
+
chain: new TextDecoder().decode(util.hexToU8a(chain.toHex())),
|
|
8109
|
+
createdAt: createdAt.toNumber(),
|
|
8110
|
+
tokenA: tokenA.toHex(),
|
|
8111
|
+
tokenB: tokenB.toHex(),
|
|
8112
|
+
standardAmount: BigInt(standardAmount.toString())
|
|
8113
|
+
});
|
|
8114
|
+
}
|
|
8115
|
+
});
|
|
8116
|
+
return unsub;
|
|
8117
|
+
}
|
|
7874
8118
|
};
|
|
7875
8119
|
var TronChain = class _TronChain {
|
|
7876
8120
|
constructor(params, evm) {
|
|
@@ -9809,6 +10053,7 @@ var GetRequestClient = class {
|
|
|
9809
10053
|
const latestMetadata = request.statuses[request.statuses.length - 1];
|
|
9810
10054
|
status = lodashEs.maxBy([status, latestMetadata.status], (item) => REQUEST_STATUS_WEIGHTS[item]);
|
|
9811
10055
|
if (!status) return;
|
|
10056
|
+
let sourceFinalizedHeight;
|
|
9812
10057
|
while (true) {
|
|
9813
10058
|
switch (status) {
|
|
9814
10059
|
case RequestStatus.SOURCE: {
|
|
@@ -9820,6 +10065,7 @@ var GetRequestClient = class {
|
|
|
9820
10065
|
chain: this.ctx.config.hyperbridge.config.stateMachineId
|
|
9821
10066
|
})
|
|
9822
10067
|
});
|
|
10068
|
+
sourceFinalizedHeight = BigInt(sourceUpdate.height);
|
|
9823
10069
|
yield {
|
|
9824
10070
|
status: RequestStatus.SOURCE_FINALIZED,
|
|
9825
10071
|
metadata: {
|
|
@@ -9833,6 +10079,15 @@ var GetRequestClient = class {
|
|
|
9833
10079
|
break;
|
|
9834
10080
|
}
|
|
9835
10081
|
case RequestStatus.SOURCE_FINALIZED: {
|
|
10082
|
+
if (request.source !== this.ctx.config.hyperbridge.config.stateMachineId && sourceFinalizedHeight !== void 0) {
|
|
10083
|
+
try {
|
|
10084
|
+
await this.deliverToHyperbridge(request, sourceFinalizedHeight);
|
|
10085
|
+
} catch (error) {
|
|
10086
|
+
this.logger.warn(
|
|
10087
|
+
`Self-delivery to Hyperbridge failed; waiting for a relayer instead: ${error instanceof Error ? error.message : error}`
|
|
10088
|
+
);
|
|
10089
|
+
}
|
|
10090
|
+
}
|
|
9836
10091
|
request = await waitOrAbort(this.ctx, {
|
|
9837
10092
|
signal,
|
|
9838
10093
|
promise: () => this.queries.queryGetRequest(hash),
|
|
@@ -9853,7 +10108,10 @@ var GetRequestClient = class {
|
|
|
9853
10108
|
}
|
|
9854
10109
|
case RequestStatus.HYPERBRIDGE_DELIVERED: {
|
|
9855
10110
|
if (request.source === this.ctx.config.hyperbridge.config.stateMachineId) return;
|
|
9856
|
-
const response = await this.
|
|
10111
|
+
const response = await waitOrAbort(this.ctx, {
|
|
10112
|
+
signal,
|
|
10113
|
+
promise: () => this.queries.queryResponseByRequestId(hash)
|
|
10114
|
+
});
|
|
9857
10115
|
yield await this.streamFinalized(signal, request, 1, response);
|
|
9858
10116
|
status = RequestStatus.HYPERBRIDGE_FINALIZED;
|
|
9859
10117
|
break;
|
|
@@ -9883,6 +10141,102 @@ var GetRequestClient = class {
|
|
|
9883
10141
|
}
|
|
9884
10142
|
}
|
|
9885
10143
|
}
|
|
10144
|
+
/**
|
|
10145
|
+
* Self-delivers a GET request to Hyperbridge — the request→Hyperbridge hop that would
|
|
10146
|
+
* otherwise require an external relayer.
|
|
10147
|
+
*
|
|
10148
|
+
* Mirrors the relayer path (and {@link OrderCanceller}): prove the request commitment on
|
|
10149
|
+
* the source chain at the Hyperbridge-finalized source height, prove the requested keys on
|
|
10150
|
+
* the destination chain at the request's height, wait out the source challenge period, then
|
|
10151
|
+
* submit an unsigned `GetRequest` message. Source and destination may each be EVM or
|
|
10152
|
+
* substrate — proofs are built via the chain-agnostic {@link IChain} methods.
|
|
10153
|
+
*
|
|
10154
|
+
* Idempotent: returns early if Hyperbridge already holds the response receipt. The caller
|
|
10155
|
+
* wraps this best-effort, so a failure leaves the stream observing as before.
|
|
10156
|
+
*/
|
|
10157
|
+
async deliverToHyperbridge(request, sourceFinalizedHeight) {
|
|
10158
|
+
const sourceChain = this.ctx.config.source;
|
|
10159
|
+
const destChain = this.ctx.config.dest;
|
|
10160
|
+
const hyperbridge = this.ctx.config.hyperbridge;
|
|
10161
|
+
const commitment = getRequestCommitment({ ...request, keys: [...request.keys] });
|
|
10162
|
+
const retry = { maxRetries: 5, backoffMs: 2e3 };
|
|
10163
|
+
if (await withRetry(this.ctx, () => hyperbridge.queryResponseReceipt(commitment), retry)) return;
|
|
10164
|
+
this.logger.info(
|
|
10165
|
+
`Delivering GET ${commitment} to Hyperbridge (${request.source}@${sourceFinalizedHeight} \u2192 ${request.dest}@${request.height})`
|
|
10166
|
+
);
|
|
10167
|
+
const sourceProof = {
|
|
10168
|
+
height: sourceFinalizedHeight,
|
|
10169
|
+
stateMachine: request.source,
|
|
10170
|
+
consensusStateId: sourceChain.config.consensusStateId,
|
|
10171
|
+
proof: await withRetry(
|
|
10172
|
+
this.ctx,
|
|
10173
|
+
() => sourceChain.queryProof(
|
|
10174
|
+
{ Requests: [commitment] },
|
|
10175
|
+
this.ctx.config.hyperbridge.config.stateMachineId,
|
|
10176
|
+
sourceFinalizedHeight
|
|
10177
|
+
),
|
|
10178
|
+
retry
|
|
10179
|
+
)
|
|
10180
|
+
};
|
|
10181
|
+
this.logger.info(` \u2713 built source proof: ${(sourceProof.proof.length - 2) / 2} bytes @ ${request.source}#${sourceFinalizedHeight}`);
|
|
10182
|
+
const destCommitment = await withRetry(
|
|
10183
|
+
this.ctx,
|
|
10184
|
+
() => hyperbridge.queryStateMachineCommitment({
|
|
10185
|
+
id: {
|
|
10186
|
+
stateId: parseStateMachineId(request.dest).stateId,
|
|
10187
|
+
consensusStateId: destChain.config.consensusStateId
|
|
10188
|
+
},
|
|
10189
|
+
height: request.height
|
|
10190
|
+
}),
|
|
10191
|
+
retry
|
|
10192
|
+
);
|
|
10193
|
+
if (!destCommitment) {
|
|
10194
|
+
throw new Error(`Hyperbridge has no state commitment for ${request.dest} at height ${request.height}`);
|
|
10195
|
+
}
|
|
10196
|
+
const responseProof = {
|
|
10197
|
+
height: request.height,
|
|
10198
|
+
stateMachine: request.dest,
|
|
10199
|
+
consensusStateId: destChain.config.consensusStateId,
|
|
10200
|
+
proof: await withRetry(this.ctx, () => destChain.queryStateProof(request.height, [...request.keys]), retry)
|
|
10201
|
+
};
|
|
10202
|
+
this.logger.info(
|
|
10203
|
+
` \u2713 built response proof: ${(responseProof.proof.length - 2) / 2} bytes (${request.keys.length} key(s) @ ${request.dest}#${request.height})`
|
|
10204
|
+
);
|
|
10205
|
+
await withRetry(
|
|
10206
|
+
this.ctx,
|
|
10207
|
+
() => waitForChallengePeriod(hyperbridge, {
|
|
10208
|
+
height: sourceFinalizedHeight,
|
|
10209
|
+
id: {
|
|
10210
|
+
stateId: parseStateMachineId(request.source).stateId,
|
|
10211
|
+
consensusStateId: sourceChain.config.consensusStateId
|
|
10212
|
+
}
|
|
10213
|
+
}),
|
|
10214
|
+
retry
|
|
10215
|
+
);
|
|
10216
|
+
const message = {
|
|
10217
|
+
kind: "GetRequest",
|
|
10218
|
+
requests: [
|
|
10219
|
+
{
|
|
10220
|
+
source: request.source,
|
|
10221
|
+
dest: request.dest,
|
|
10222
|
+
nonce: request.nonce,
|
|
10223
|
+
from: request.from,
|
|
10224
|
+
timeoutTimestamp: request.timeoutTimestamp,
|
|
10225
|
+
keys: [...request.keys],
|
|
10226
|
+
height: request.height,
|
|
10227
|
+
context: request.context
|
|
10228
|
+
}
|
|
10229
|
+
],
|
|
10230
|
+
source: sourceProof,
|
|
10231
|
+
response: responseProof,
|
|
10232
|
+
signer: viem.pad("0x")
|
|
10233
|
+
};
|
|
10234
|
+
this.logger.info(" \u2192 submitting GetRequest message (source + response proofs) to Hyperbridge\u2026");
|
|
10235
|
+
const result = await withRetry(this.ctx, () => hyperbridge.submitUnsigned(message), retry);
|
|
10236
|
+
this.logger.info(
|
|
10237
|
+
` \u2713 delivered GET ${commitment} in Hyperbridge block #${result.blockNumber} (tx ${result.transactionHash})`
|
|
10238
|
+
);
|
|
10239
|
+
}
|
|
9886
10240
|
/**
|
|
9887
10241
|
* Snapshot helper: returns the `HYPERBRIDGE_FINALIZED` event with source-chain
|
|
9888
10242
|
* calldata if prerequisites are met, or `undefined` if we're still waiting
|
|
@@ -9896,7 +10250,7 @@ var GetRequestClient = class {
|
|
|
9896
10250
|
const finality = await this.queries.queryStateMachineUpdateByHeight({
|
|
9897
10251
|
statemachineId: config.stateMachineId,
|
|
9898
10252
|
height: hyperbridgeDelivered.metadata.blockNumber,
|
|
9899
|
-
chain:
|
|
10253
|
+
chain: request.source
|
|
9900
10254
|
});
|
|
9901
10255
|
if (finality) {
|
|
9902
10256
|
const proof = await hyperbridge.queryProof(
|
|
@@ -9967,14 +10321,19 @@ var GetRequestClient = class {
|
|
|
9967
10321
|
],
|
|
9968
10322
|
signer: viem.pad("0x")
|
|
9969
10323
|
});
|
|
10324
|
+
const hyperbridgeFinality = await this.queries.queryStateMachineUpdateByHeight({
|
|
10325
|
+
statemachineId: config.stateMachineId,
|
|
10326
|
+
height: hyperbridgeDelivered.metadata.blockNumber,
|
|
10327
|
+
chain: config.stateMachineId
|
|
10328
|
+
});
|
|
10329
|
+
if (!hyperbridgeFinality) return void 0;
|
|
9970
10330
|
return {
|
|
9971
10331
|
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
9972
10332
|
metadata: {
|
|
9973
|
-
blockHash:
|
|
9974
|
-
blockNumber:
|
|
9975
|
-
transactionHash:
|
|
9976
|
-
|
|
9977
|
-
timestamp: hyperbridgeDelivered.metadata.timestamp,
|
|
10333
|
+
blockHash: hyperbridgeFinality.blockHash,
|
|
10334
|
+
blockNumber: hyperbridgeFinality.height,
|
|
10335
|
+
transactionHash: hyperbridgeFinality.transactionHash,
|
|
10336
|
+
timestamp: hyperbridgeFinality.timestamp,
|
|
9978
10337
|
calldata
|
|
9979
10338
|
}
|
|
9980
10339
|
};
|
|
@@ -9994,12 +10353,44 @@ var GetRequestClient = class {
|
|
|
9994
10353
|
const hyperbridge = this.ctx.config.hyperbridge;
|
|
9995
10354
|
const stateMachineId = this.ctx.config.hyperbridge.config.stateMachineId;
|
|
9996
10355
|
const neededHeight = BigInt(request.statuses[hyperbridgeDeliveredIndex].metadata.blockNumber);
|
|
10356
|
+
const consensusStateId = this.ctx.config.hyperbridge.config.consensusStateId;
|
|
10357
|
+
const encodeGetResponse = (height, proof2) => sourceChain.encode({
|
|
10358
|
+
kind: "GetResponse",
|
|
10359
|
+
proof: { stateMachine: stateMachineId, consensusStateId, proof: proof2, height },
|
|
10360
|
+
responses: [
|
|
10361
|
+
{
|
|
10362
|
+
get: request,
|
|
10363
|
+
values: request.keys.map((key, index) => ({
|
|
10364
|
+
key,
|
|
10365
|
+
value: response?.values[index] || "0x"
|
|
10366
|
+
}))
|
|
10367
|
+
}
|
|
10368
|
+
],
|
|
10369
|
+
signer: viem.pad("0x")
|
|
10370
|
+
});
|
|
9997
10371
|
let finality = await this.queries.queryStateMachineUpdateByHeight({
|
|
9998
10372
|
statemachineId: stateMachineId,
|
|
9999
10373
|
height: Number(neededHeight),
|
|
10000
|
-
chain:
|
|
10374
|
+
chain: request.source
|
|
10001
10375
|
});
|
|
10002
|
-
if (
|
|
10376
|
+
if (finality) {
|
|
10377
|
+
const proof2 = await hyperbridge.queryProof(
|
|
10378
|
+
{ Responses: [response?.commitment] },
|
|
10379
|
+
request.source,
|
|
10380
|
+
BigInt(finality.height)
|
|
10381
|
+
);
|
|
10382
|
+
return {
|
|
10383
|
+
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10384
|
+
metadata: {
|
|
10385
|
+
blockHash: finality.blockHash,
|
|
10386
|
+
blockNumber: finality.height,
|
|
10387
|
+
transactionHash: finality.transactionHash,
|
|
10388
|
+
timestamp: finality.timestamp,
|
|
10389
|
+
calldata: encodeGetResponse(BigInt(finality.height), proof2)
|
|
10390
|
+
}
|
|
10391
|
+
};
|
|
10392
|
+
}
|
|
10393
|
+
if (sourceChain instanceof EvmChain) {
|
|
10003
10394
|
const hyperbridgeSubstrate = hyperbridge;
|
|
10004
10395
|
const currentEpoch = await sourceChain.currentEpoch();
|
|
10005
10396
|
const consensusResult = await waitOrAbort(this.ctx, {
|
|
@@ -10011,12 +10402,12 @@ var GetRequestClient = class {
|
|
|
10011
10402
|
request.source,
|
|
10012
10403
|
consensusResult.provenHeight
|
|
10013
10404
|
);
|
|
10014
|
-
const
|
|
10405
|
+
const calldata = sourceChain.encode({
|
|
10015
10406
|
kind: "BatchConsensusAndGetResponse",
|
|
10016
10407
|
consensusProofs: consensusResult.proofs,
|
|
10017
10408
|
proof: {
|
|
10018
10409
|
stateMachine: stateMachineId,
|
|
10019
|
-
consensusStateId
|
|
10410
|
+
consensusStateId,
|
|
10020
10411
|
proof: proof2,
|
|
10021
10412
|
height: consensusResult.provenHeight
|
|
10022
10413
|
},
|
|
@@ -10031,20 +10422,7 @@ var GetRequestClient = class {
|
|
|
10031
10422
|
],
|
|
10032
10423
|
signer: viem.pad("0x")
|
|
10033
10424
|
});
|
|
10034
|
-
|
|
10035
|
-
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10036
|
-
metadata: {
|
|
10037
|
-
blockHash: request.statuses[hyperbridgeDeliveredIndex].metadata.blockHash,
|
|
10038
|
-
blockNumber: Number(consensusResult.provenHeight),
|
|
10039
|
-
transactionHash: request.statuses[hyperbridgeDeliveredIndex].metadata.transactionHash,
|
|
10040
|
-
// @ts-ignore
|
|
10041
|
-
timestamp: request.statuses[hyperbridgeDeliveredIndex].metadata.timestamp,
|
|
10042
|
-
calldata: calldata2
|
|
10043
|
-
}
|
|
10044
|
-
};
|
|
10045
|
-
}
|
|
10046
|
-
if (!finality) {
|
|
10047
|
-
finality = await waitOrAbort(this.ctx, {
|
|
10425
|
+
const hyperbridgeFinality = await waitOrAbort(this.ctx, {
|
|
10048
10426
|
signal,
|
|
10049
10427
|
promise: () => this.queries.queryStateMachineUpdateByHeight({
|
|
10050
10428
|
statemachineId: stateMachineId,
|
|
@@ -10052,31 +10430,30 @@ var GetRequestClient = class {
|
|
|
10052
10430
|
chain: stateMachineId
|
|
10053
10431
|
})
|
|
10054
10432
|
});
|
|
10433
|
+
return {
|
|
10434
|
+
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10435
|
+
metadata: {
|
|
10436
|
+
blockHash: hyperbridgeFinality.blockHash,
|
|
10437
|
+
blockNumber: hyperbridgeFinality.height,
|
|
10438
|
+
transactionHash: hyperbridgeFinality.transactionHash,
|
|
10439
|
+
timestamp: hyperbridgeFinality.timestamp,
|
|
10440
|
+
calldata
|
|
10441
|
+
}
|
|
10442
|
+
};
|
|
10055
10443
|
}
|
|
10444
|
+
finality = await waitOrAbort(this.ctx, {
|
|
10445
|
+
signal,
|
|
10446
|
+
promise: () => this.queries.queryStateMachineUpdateByHeight({
|
|
10447
|
+
statemachineId: stateMachineId,
|
|
10448
|
+
height: Number(neededHeight),
|
|
10449
|
+
chain: request.source
|
|
10450
|
+
})
|
|
10451
|
+
});
|
|
10056
10452
|
const proof = await hyperbridge.queryProof(
|
|
10057
10453
|
{ Responses: [response?.commitment] },
|
|
10058
10454
|
request.source,
|
|
10059
10455
|
BigInt(finality.height)
|
|
10060
10456
|
);
|
|
10061
|
-
const calldata = sourceChain.encode({
|
|
10062
|
-
kind: "GetResponse",
|
|
10063
|
-
proof: {
|
|
10064
|
-
stateMachine: stateMachineId,
|
|
10065
|
-
consensusStateId: this.ctx.config.hyperbridge.config.consensusStateId,
|
|
10066
|
-
proof,
|
|
10067
|
-
height: BigInt(finality.height)
|
|
10068
|
-
},
|
|
10069
|
-
responses: [
|
|
10070
|
-
{
|
|
10071
|
-
get: request,
|
|
10072
|
-
values: request.keys.map((key, index) => ({
|
|
10073
|
-
key,
|
|
10074
|
-
value: response?.values[index] || "0x"
|
|
10075
|
-
}))
|
|
10076
|
-
}
|
|
10077
|
-
],
|
|
10078
|
-
signer: viem.pad("0x")
|
|
10079
|
-
});
|
|
10080
10457
|
return {
|
|
10081
10458
|
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10082
10459
|
metadata: {
|
|
@@ -10084,7 +10461,7 @@ var GetRequestClient = class {
|
|
|
10084
10461
|
blockNumber: finality.height,
|
|
10085
10462
|
transactionHash: finality.transactionHash,
|
|
10086
10463
|
timestamp: finality.timestamp,
|
|
10087
|
-
calldata
|
|
10464
|
+
calldata: encodeGetResponse(BigInt(finality.height), proof)
|
|
10088
10465
|
}
|
|
10089
10466
|
};
|
|
10090
10467
|
}
|
|
@@ -10587,7 +10964,7 @@ var PostRequestClient = class {
|
|
|
10587
10964
|
const finality = await this.queries.queryStateMachineUpdateByHeight({
|
|
10588
10965
|
statemachineId: config.stateMachineId,
|
|
10589
10966
|
height: hyperbridgeDelivered.metadata.blockNumber,
|
|
10590
|
-
chain:
|
|
10967
|
+
chain: request.dest
|
|
10591
10968
|
});
|
|
10592
10969
|
if (finality) {
|
|
10593
10970
|
const proof = await hyperbridge.queryProof(
|
|
@@ -10642,14 +11019,19 @@ var PostRequestClient = class {
|
|
|
10642
11019
|
requests: [request],
|
|
10643
11020
|
signer: viem.pad("0x")
|
|
10644
11021
|
});
|
|
11022
|
+
const hyperbridgeFinality = await this.queries.queryStateMachineUpdateByHeight({
|
|
11023
|
+
statemachineId: config.stateMachineId,
|
|
11024
|
+
height: hyperbridgeDelivered.metadata.blockNumber,
|
|
11025
|
+
chain: config.stateMachineId
|
|
11026
|
+
});
|
|
11027
|
+
if (!hyperbridgeFinality) return void 0;
|
|
10645
11028
|
return {
|
|
10646
11029
|
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10647
11030
|
metadata: {
|
|
10648
|
-
blockHash:
|
|
10649
|
-
blockNumber:
|
|
10650
|
-
transactionHash:
|
|
10651
|
-
|
|
10652
|
-
timestamp: hyperbridgeDelivered.metadata.timestamp,
|
|
11031
|
+
blockHash: hyperbridgeFinality.blockHash,
|
|
11032
|
+
blockNumber: hyperbridgeFinality.height,
|
|
11033
|
+
transactionHash: hyperbridgeFinality.transactionHash,
|
|
11034
|
+
timestamp: hyperbridgeFinality.timestamp,
|
|
10653
11035
|
calldata
|
|
10654
11036
|
}
|
|
10655
11037
|
};
|
|
@@ -10672,7 +11054,7 @@ var PostRequestClient = class {
|
|
|
10672
11054
|
let finality = await this.queries.queryStateMachineUpdateByHeight({
|
|
10673
11055
|
statemachineId: stateMachineId,
|
|
10674
11056
|
height: Number(neededHeight),
|
|
10675
|
-
chain:
|
|
11057
|
+
chain: request.dest
|
|
10676
11058
|
});
|
|
10677
11059
|
if (!finality && destChain instanceof EvmChain) {
|
|
10678
11060
|
const hyperbridgeSubstrate = hyperbridge;
|
|
@@ -10700,14 +11082,21 @@ var PostRequestClient = class {
|
|
|
10700
11082
|
requests: [request],
|
|
10701
11083
|
signer: viem.pad("0x")
|
|
10702
11084
|
});
|
|
11085
|
+
const hyperbridgeFinality = await waitOrAbort(this.ctx, {
|
|
11086
|
+
signal,
|
|
11087
|
+
promise: () => this.queries.queryStateMachineUpdateByHeight({
|
|
11088
|
+
statemachineId: stateMachineId,
|
|
11089
|
+
height: Number(neededHeight),
|
|
11090
|
+
chain: stateMachineId
|
|
11091
|
+
})
|
|
11092
|
+
});
|
|
10703
11093
|
return {
|
|
10704
11094
|
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
10705
11095
|
metadata: {
|
|
10706
|
-
blockHash:
|
|
10707
|
-
blockNumber:
|
|
10708
|
-
transactionHash:
|
|
10709
|
-
|
|
10710
|
-
timestamp: request.statuses[hyperbridgeDeliveredIndex].metadata.timestamp,
|
|
11096
|
+
blockHash: hyperbridgeFinality.blockHash,
|
|
11097
|
+
blockNumber: hyperbridgeFinality.height,
|
|
11098
|
+
transactionHash: hyperbridgeFinality.transactionHash,
|
|
11099
|
+
timestamp: hyperbridgeFinality.timestamp,
|
|
10711
11100
|
calldata: calldata2
|
|
10712
11101
|
}
|
|
10713
11102
|
};
|
|
@@ -10718,7 +11107,7 @@ var PostRequestClient = class {
|
|
|
10718
11107
|
promise: () => this.queries.queryStateMachineUpdateByHeight({
|
|
10719
11108
|
statemachineId: stateMachineId,
|
|
10720
11109
|
height: Number(neededHeight),
|
|
10721
|
-
chain:
|
|
11110
|
+
chain: request.dest
|
|
10722
11111
|
})
|
|
10723
11112
|
});
|
|
10724
11113
|
}
|
|
@@ -14613,16 +15002,6 @@ var CryptoUtils = class _CryptoUtils {
|
|
|
14613
15002
|
}
|
|
14614
15003
|
}
|
|
14615
15004
|
};
|
|
14616
|
-
var FEE_TOKEN_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
14617
|
-
async function getFeeToken(ctx, chainId, chain) {
|
|
14618
|
-
const cached = ctx.feeTokenCache.get(chainId);
|
|
14619
|
-
if (cached && Date.now() - cached.cachedAt < FEE_TOKEN_CACHE_TTL_MS) {
|
|
14620
|
-
return cached;
|
|
14621
|
-
}
|
|
14622
|
-
const fresh = await chain.getFeeTokenWithDecimals();
|
|
14623
|
-
ctx.feeTokenCache.set(chainId, { ...fresh, cachedAt: Date.now() });
|
|
14624
|
-
return fresh;
|
|
14625
|
-
}
|
|
14626
15005
|
function encodeERC7821ExecuteBatch(calls) {
|
|
14627
15006
|
const executionData = viem.encodeAbiParameters(
|
|
14628
15007
|
[{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
|
|
@@ -14634,6 +15013,36 @@ function encodeERC7821ExecuteBatch(calls) {
|
|
|
14634
15013
|
args: [ERC7821_BATCH_MODE, executionData]
|
|
14635
15014
|
});
|
|
14636
15015
|
}
|
|
15016
|
+
function decodeERC7821ExecuteBatch(callData) {
|
|
15017
|
+
try {
|
|
15018
|
+
const decoded = viem.decodeFunctionData({ abi: erc7281_default.ABI, data: callData });
|
|
15019
|
+
if (decoded.functionName !== "execute" || !decoded.args || decoded.args.length < 2) return null;
|
|
15020
|
+
const executionData = decoded.args[1];
|
|
15021
|
+
const [calls] = viem.decodeAbiParameters(
|
|
15022
|
+
[{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
|
|
15023
|
+
executionData
|
|
15024
|
+
);
|
|
15025
|
+
return calls.map((call) => ({
|
|
15026
|
+
target: call.target,
|
|
15027
|
+
value: call.value,
|
|
15028
|
+
data: call.data
|
|
15029
|
+
}));
|
|
15030
|
+
} catch {
|
|
15031
|
+
return null;
|
|
15032
|
+
}
|
|
15033
|
+
}
|
|
15034
|
+
|
|
15035
|
+
// src/protocols/intents/utils.ts
|
|
15036
|
+
var FEE_TOKEN_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
15037
|
+
async function getFeeToken(ctx, chainId, chain) {
|
|
15038
|
+
const cached = ctx.feeTokenCache.get(chainId);
|
|
15039
|
+
if (cached && Date.now() - cached.cachedAt < FEE_TOKEN_CACHE_TTL_MS) {
|
|
15040
|
+
return cached;
|
|
15041
|
+
}
|
|
15042
|
+
const fresh = await chain.getFeeTokenWithDecimals();
|
|
15043
|
+
ctx.feeTokenCache.set(chainId, { ...fresh, cachedAt: Date.now() });
|
|
15044
|
+
return fresh;
|
|
15045
|
+
}
|
|
14637
15046
|
async function fetchSourceProof(commitment, source, sourceStateMachine, sourceConsensusStateId, sourceHeight) {
|
|
14638
15047
|
const { slot1, slot2 } = requestCommitmentKey(commitment);
|
|
14639
15048
|
const proofHex = await source.queryStateProof(sourceHeight, [slot1, slot2]);
|
|
@@ -18513,6 +18922,11 @@ var HyperFungibleTokenABI = [
|
|
|
18513
18922
|
name: "context",
|
|
18514
18923
|
type: "bytes",
|
|
18515
18924
|
internalType: "bytes"
|
|
18925
|
+
},
|
|
18926
|
+
{
|
|
18927
|
+
name: "payer",
|
|
18928
|
+
type: "address",
|
|
18929
|
+
internalType: "address"
|
|
18516
18930
|
}
|
|
18517
18931
|
]
|
|
18518
18932
|
}
|
|
@@ -19634,6 +20048,11 @@ var WrappedHyperFungibleTokenABI = [
|
|
|
19634
20048
|
name: "context",
|
|
19635
20049
|
type: "bytes",
|
|
19636
20050
|
internalType: "bytes"
|
|
20051
|
+
},
|
|
20052
|
+
{
|
|
20053
|
+
name: "payer",
|
|
20054
|
+
type: "address",
|
|
20055
|
+
internalType: "address"
|
|
19637
20056
|
}
|
|
19638
20057
|
]
|
|
19639
20058
|
}
|
|
@@ -21471,6 +21890,11 @@ var ABI8 = [
|
|
|
21471
21890
|
internalType: "bytes",
|
|
21472
21891
|
name: "context",
|
|
21473
21892
|
type: "bytes"
|
|
21893
|
+
},
|
|
21894
|
+
{
|
|
21895
|
+
internalType: "address",
|
|
21896
|
+
name: "payer",
|
|
21897
|
+
type: "address"
|
|
21474
21898
|
}
|
|
21475
21899
|
],
|
|
21476
21900
|
internalType: "struct DispatchGet",
|
|
@@ -21739,6 +22163,11 @@ var ABI8 = [
|
|
|
21739
22163
|
internalType: "bytes",
|
|
21740
22164
|
name: "context",
|
|
21741
22165
|
type: "bytes"
|
|
22166
|
+
},
|
|
22167
|
+
{
|
|
22168
|
+
internalType: "address",
|
|
22169
|
+
name: "payer",
|
|
22170
|
+
type: "address"
|
|
21742
22171
|
}
|
|
21743
22172
|
],
|
|
21744
22173
|
internalType: "struct DispatchGet",
|
|
@@ -22168,6 +22597,7 @@ exports.convertStateMachineEnumToString = convertStateMachineEnumToString;
|
|
|
22168
22597
|
exports.convertStateMachineIdToEnum = convertStateMachineIdToEnum;
|
|
22169
22598
|
exports.createEvmChain = createEvmChain;
|
|
22170
22599
|
exports.createQueryClient = createQueryClient;
|
|
22600
|
+
exports.decodeERC7821ExecuteBatch = decodeERC7821ExecuteBatch;
|
|
22171
22601
|
exports.decodeUserOpScale = decodeUserOpScale;
|
|
22172
22602
|
exports.encodeERC7821ExecuteBatch = encodeERC7821ExecuteBatch;
|
|
22173
22603
|
exports.encodeISMPMessage = encodeISMPMessage;
|