@hyperbridge/sdk 2.2.2 → 2.3.0
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 +70 -19
- package/dist/browser/index.js +230 -47
- package/dist/browser/index.js.map +1 -1
- package/dist/node/IntentGatewayV2-C55Aitcb.d.cts +5717 -0
- package/dist/node/IntentGatewayV2-C55Aitcb.d.ts +5717 -0
- package/dist/node/index.cjs +230 -45
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1478 -5742
- package/dist/node/index.d.ts +1478 -5742
- package/dist/node/index.js +230 -47
- 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 +15 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createConsola, LogLevels } from 'consola';
|
|
2
|
-
import { defineChain, keccak256, toHex, createPublicClient, http, hexToBytes, toFunctionSelector, bytesToHex, encodeFunctionData, erc20Abi, bytesToBigInt, pad, toBytes, numberToBytes, getAddress, encodeAbiParameters, isHex, maxUint256, parseAbiParameters, encodePacked, parseAbiItem, concat, decodeFunctionData,
|
|
2
|
+
import { defineChain, keccak256, toHex, createPublicClient, http, hexToBytes, toFunctionSelector, bytesToHex, encodeFunctionData, erc20Abi, bytesToBigInt, pad, toBytes, numberToBytes, decodeAbiParameters, getAddress, encodeAbiParameters, isHex, maxUint256, parseAbiParameters, encodePacked, parseAbiItem, concat, decodeFunctionData, hexToString as hexToString$1, decodeEventLog, parseEventLogs, parseUnits, concatHex, zeroAddress, decodeFunctionResult, formatUnits } from 'viem';
|
|
3
3
|
import { baseSepolia, optimismSepolia, arbitrumSepolia, soneium, gnosis, optimism, polygonAmoy, polygon, base, arbitrum, bsc, mainnet, sepolia, gnosisChiado, bscTestnet, tron, unichain } from 'viem/chains';
|
|
4
4
|
import { TronWeb } from 'tronweb';
|
|
5
5
|
import { flatten, zip, capitalize, maxBy, isNil } from 'lodash-es';
|
|
@@ -8,6 +8,7 @@ import { WsProvider, ApiPromise, Keyring } from '@polkadot/api';
|
|
|
8
8
|
import { Struct, Vector, u8, Bytes, Enum, Tuple, _void, u64, u32, Option, bool, u128 } from 'scale-ts';
|
|
9
9
|
import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a, blake2AsU8a } from '@polkadot/util-crypto';
|
|
10
10
|
import { hexToU8a, u8aToHex, u8aConcat } from '@polkadot/util';
|
|
11
|
+
import PQueue from 'p-queue';
|
|
11
12
|
import { hasWindow, isNode, env } from 'std-env';
|
|
12
13
|
import mergeRace from '@async-generator/merge-race';
|
|
13
14
|
import { GraphQLClient } from 'graphql-request';
|
|
@@ -564,6 +565,11 @@ var ABI = [
|
|
|
564
565
|
name: "context",
|
|
565
566
|
type: "bytes",
|
|
566
567
|
internalType: "bytes"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
name: "payer",
|
|
571
|
+
type: "address",
|
|
572
|
+
internalType: "address"
|
|
567
573
|
}
|
|
568
574
|
]
|
|
569
575
|
}
|
|
@@ -2619,9 +2625,9 @@ var chainConfigs = {
|
|
|
2619
2625
|
USDT: { balanceSlot: 151, allowanceSlot: 152 }
|
|
2620
2626
|
},
|
|
2621
2627
|
addresses: {
|
|
2622
|
-
IntentGateway: "
|
|
2628
|
+
IntentGateway: "0x6CF42FA9BecbC5b6a26884964956b113530f7cFA",
|
|
2623
2629
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2624
|
-
Host: "
|
|
2630
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
2625
2631
|
UniswapRouter02: "0x9639379819420704457B07A0C33B678D9E0F8Df0",
|
|
2626
2632
|
UniswapV2Factory: "0x12e036669DA18F4A2777853d6e2136b32AceEC86",
|
|
2627
2633
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -2629,7 +2635,7 @@ var chainConfigs = {
|
|
|
2629
2635
|
UniswapV3Quoter: "0x0000000000000000000000000000000000000000",
|
|
2630
2636
|
UniswapV4Quoter: "0x0000000000000000000000000000000000000000",
|
|
2631
2637
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
2632
|
-
SolverAccount: "
|
|
2638
|
+
SolverAccount: "0x07FeC66d967800998060194EaECDd7C66dA4a1B1"
|
|
2633
2639
|
},
|
|
2634
2640
|
rpcEnvKey: "BSC_CHAPEL",
|
|
2635
2641
|
defaultRpcUrl: "https://bnb-testnet.api.onfinality.io/public",
|
|
@@ -2660,7 +2666,7 @@ var chainConfigs = {
|
|
|
2660
2666
|
addresses: {
|
|
2661
2667
|
IntentGateway: "0x016b6ffC9f890d1e28f9Fdb9eaDA776b02F89509",
|
|
2662
2668
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2663
|
-
Host: "
|
|
2669
|
+
Host: "0x58A41B89F4871725E5D898d98eF4BF917601c5eB",
|
|
2664
2670
|
UniswapRouter02: "0x0000000000000000000000000000000000000000",
|
|
2665
2671
|
UniswapV2Factory: "0x0000000000000000000000000000000000000000",
|
|
2666
2672
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -2699,7 +2705,7 @@ var chainConfigs = {
|
|
|
2699
2705
|
addresses: {
|
|
2700
2706
|
IntentGateway: "0x016b6ffC9f890d1e28f9Fdb9eaDA776b02F89509",
|
|
2701
2707
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
2702
|
-
Host: "
|
|
2708
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
2703
2709
|
UniswapRouter02: "0x0000000000000000000000000000000000000000",
|
|
2704
2710
|
UniswapV2Factory: "0x0000000000000000000000000000000000000000",
|
|
2705
2711
|
UniswapV3Factory: "0x0000000000000000000000000000000000000000",
|
|
@@ -3045,13 +3051,13 @@ var chainConfigs = {
|
|
|
3045
3051
|
USDC: { balanceSlot: 1, allowanceSlot: 2 }
|
|
3046
3052
|
},
|
|
3047
3053
|
addresses: {
|
|
3048
|
-
IntentGateway: "
|
|
3054
|
+
IntentGateway: "0x6CF42FA9BecbC5b6a26884964956b113530f7cFA",
|
|
3049
3055
|
TokenGateway: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
|
|
3050
|
-
Host: "
|
|
3056
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3051
3057
|
Calldispatcher: "0x876F1891982E260026630c233A4897160A281Fb8",
|
|
3052
3058
|
Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
3053
3059
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
3054
|
-
SolverAccount: "
|
|
3060
|
+
SolverAccount: "0x07FeC66d967800998060194EaECDd7C66dA4a1B1"
|
|
3055
3061
|
},
|
|
3056
3062
|
rpcEnvKey: "POLYGON_AMOY",
|
|
3057
3063
|
defaultRpcUrl: "https://rpc-amoy.polygon.technology",
|
|
@@ -3167,7 +3173,7 @@ var chainConfigs = {
|
|
|
3167
3173
|
},
|
|
3168
3174
|
addresses: {
|
|
3169
3175
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3170
|
-
Host: "
|
|
3176
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3171
3177
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3172
3178
|
},
|
|
3173
3179
|
defaultRpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
@@ -3191,7 +3197,7 @@ var chainConfigs = {
|
|
|
3191
3197
|
},
|
|
3192
3198
|
addresses: {
|
|
3193
3199
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3194
|
-
Host: "
|
|
3200
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3195
3201
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3196
3202
|
},
|
|
3197
3203
|
defaultRpcUrl: "https://sepolia.optimism.io",
|
|
@@ -3215,7 +3221,7 @@ var chainConfigs = {
|
|
|
3215
3221
|
},
|
|
3216
3222
|
addresses: {
|
|
3217
3223
|
TokenGateway: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3218
|
-
Host: "
|
|
3224
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3219
3225
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3220
3226
|
},
|
|
3221
3227
|
defaultRpcUrl: "https://sepolia.base.org",
|
|
@@ -3241,7 +3247,7 @@ var chainConfigs = {
|
|
|
3241
3247
|
addresses: {
|
|
3242
3248
|
IntentGateway: "0x606ba811aa6cb424ce2108e8977c5284686f0d1f",
|
|
3243
3249
|
TokenGateway: "0x1c1e5be83df4a54c7a2230c337e4a3e8b7354b1c",
|
|
3244
|
-
Host: "
|
|
3250
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3245
3251
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108"
|
|
3246
3252
|
},
|
|
3247
3253
|
defaultRpcUrl: "https://testnet-asset-hub-eth-rpc.polkadot.io",
|
|
@@ -3291,7 +3297,7 @@ var chainConfigs = {
|
|
|
3291
3297
|
wrappedNativeDecimals: 18,
|
|
3292
3298
|
addresses: {
|
|
3293
3299
|
TokenGateway: "0x451bDd8273839AD0Ec7F4Fa798E8B3DABb223fD8",
|
|
3294
|
-
Host: "
|
|
3300
|
+
Host: "0x9AA003594d59C62EE17A73A569Fd7B1DbdBd71E1",
|
|
3295
3301
|
IntentGateway: "0xb8039832c6c9266F928d038eA49A8a169300C670"
|
|
3296
3302
|
},
|
|
3297
3303
|
consensusStateId: "PHAR",
|
|
@@ -4423,6 +4429,11 @@ var ABI3 = [
|
|
|
4423
4429
|
name: "context",
|
|
4424
4430
|
type: "bytes",
|
|
4425
4431
|
internalType: "bytes"
|
|
4432
|
+
},
|
|
4433
|
+
{
|
|
4434
|
+
name: "payer",
|
|
4435
|
+
type: "address",
|
|
4436
|
+
internalType: "address"
|
|
4426
4437
|
}
|
|
4427
4438
|
]
|
|
4428
4439
|
}
|
|
@@ -7583,6 +7594,7 @@ function encodeISMPMessage(message) {
|
|
|
7583
7594
|
}
|
|
7584
7595
|
}
|
|
7585
7596
|
var OFFCHAIN_BID_PREFIX = new TextEncoder().encode("intents::bid::");
|
|
7597
|
+
var OFFCHAIN_PHANTOM_PREFIX = new TextEncoder().encode("intents::phantom::order::");
|
|
7586
7598
|
var BidCodec = Struct({ filler: Bytes(32), user_op: Vector(u8) });
|
|
7587
7599
|
var PackedUserOperationCodec = Struct({
|
|
7588
7600
|
sender: Bytes(20),
|
|
@@ -7643,6 +7655,11 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7643
7655
|
ownsConnection;
|
|
7644
7656
|
/** Cached result of whether the node exposes intents_* RPC methods */
|
|
7645
7657
|
hasIntentsRpc = null;
|
|
7658
|
+
// Serialises every extrinsic submission on this instance's substrate account. All submit/retract
|
|
7659
|
+
// methods funnel through signAndSendExtrinsic, each using the API's auto-nonce; fired in parallel
|
|
7660
|
+
// (bids for orders on different chains, or several phantom orders in one interval) they would grab
|
|
7661
|
+
// the same nonce and all but one would fail. Concurrency 1 sequences them.
|
|
7662
|
+
submissionQueue = new PQueue({ concurrency: 1 });
|
|
7646
7663
|
/**
|
|
7647
7664
|
* Creates and connects an IntentsCoprocessor to a Hyperbridge node.
|
|
7648
7665
|
* This creates and manages its own API connection.
|
|
@@ -7695,14 +7712,17 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7695
7712
|
}
|
|
7696
7713
|
}
|
|
7697
7714
|
/**
|
|
7698
|
-
* Creates a Substrate keypair from the configured private key
|
|
7699
|
-
* Supports
|
|
7715
|
+
* Creates a Substrate keypair from the configured private key.
|
|
7716
|
+
* Supports hex seed (with or without 0x), mnemonic phrases, and URI derivation paths (//Alice).
|
|
7700
7717
|
*/
|
|
7701
7718
|
getKeyPair() {
|
|
7702
7719
|
if (!this.substratePrivateKey) {
|
|
7703
7720
|
throw new Error("Substrate PrivateKey Required");
|
|
7704
7721
|
}
|
|
7705
7722
|
const keyring = new Keyring({ type: "sr25519" });
|
|
7723
|
+
if (this.substratePrivateKey.startsWith("//")) {
|
|
7724
|
+
return keyring.addFromUri(this.substratePrivateKey);
|
|
7725
|
+
}
|
|
7706
7726
|
if (this.substratePrivateKey.includes(" ")) {
|
|
7707
7727
|
return keyring.addFromMnemonic(this.substratePrivateKey);
|
|
7708
7728
|
}
|
|
@@ -7711,10 +7731,19 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7711
7731
|
return keyring.addFromSeed(seedBytes);
|
|
7712
7732
|
}
|
|
7713
7733
|
/**
|
|
7714
|
-
* Signs and sends an extrinsic
|
|
7715
|
-
*
|
|
7734
|
+
* Signs and sends an extrinsic. Submissions are serialised through {@link submissionQueue} so
|
|
7735
|
+
* concurrent calls never collide on the substrate account nonce — each extrinsic reaches a block
|
|
7736
|
+
* before the next is signed.
|
|
7716
7737
|
*/
|
|
7717
7738
|
async signAndSendExtrinsic(extrinsic, maxRetries = 3, timeoutMs = 3e4) {
|
|
7739
|
+
const result = await this.submissionQueue.add(() => this.sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs));
|
|
7740
|
+
return result ?? { success: false, error: "Submission queue returned no result" };
|
|
7741
|
+
}
|
|
7742
|
+
/**
|
|
7743
|
+
* Signs and sends an extrinsic, handling status updates and errors.
|
|
7744
|
+
* Implements retry logic with progressive tip increases for stuck transactions.
|
|
7745
|
+
*/
|
|
7746
|
+
async sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs) {
|
|
7718
7747
|
const keyPair = this.getKeyPair();
|
|
7719
7748
|
let baseTip = 500000000000n;
|
|
7720
7749
|
let attempt = 0;
|
|
@@ -7759,20 +7788,34 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7759
7788
|
}, timeoutMs);
|
|
7760
7789
|
extrinsic.signAndSend(keyPair, { tip }, (result) => {
|
|
7761
7790
|
if (resolved) return;
|
|
7762
|
-
if (result.status.isInBlock || result.status.isFinalized) {
|
|
7791
|
+
if (result.dispatchError && (result.status.isInBlock || result.status.isFinalized)) {
|
|
7763
7792
|
resolved = true;
|
|
7764
7793
|
clearTimeout(timeoutId);
|
|
7794
|
+
let errorMsg;
|
|
7795
|
+
if (result.dispatchError.isModule) {
|
|
7796
|
+
const decoded = this.api.registry.findMetaError(result.dispatchError.asModule);
|
|
7797
|
+
errorMsg = `Dispatch error: ${decoded.section}::${decoded.name}`;
|
|
7798
|
+
} else {
|
|
7799
|
+
errorMsg = `Dispatch error: ${result.dispatchError.toString()}`;
|
|
7800
|
+
}
|
|
7765
7801
|
resolve({
|
|
7766
|
-
success:
|
|
7767
|
-
|
|
7768
|
-
extrinsicHash: extrinsic.hash.toHex()
|
|
7802
|
+
success: false,
|
|
7803
|
+
error: errorMsg
|
|
7769
7804
|
});
|
|
7770
|
-
} else if (result.
|
|
7805
|
+
} else if (result.status.isDropped || result.status.isInvalid || result.status.isUsurped || result.status.isFinalityTimeout) {
|
|
7771
7806
|
resolved = true;
|
|
7772
7807
|
clearTimeout(timeoutId);
|
|
7773
7808
|
resolve({
|
|
7774
7809
|
success: false,
|
|
7775
|
-
error: `
|
|
7810
|
+
error: `Transaction ${result.status.type.toLowerCase()}`
|
|
7811
|
+
});
|
|
7812
|
+
} else if (result.status.isInBlock || result.status.isFinalized) {
|
|
7813
|
+
resolved = true;
|
|
7814
|
+
clearTimeout(timeoutId);
|
|
7815
|
+
resolve({
|
|
7816
|
+
success: true,
|
|
7817
|
+
blockHash: (result.status.isInBlock ? result.status.asInBlock : result.status.asFinalized).toHex(),
|
|
7818
|
+
extrinsicHash: extrinsic.hash.toHex()
|
|
7776
7819
|
});
|
|
7777
7820
|
}
|
|
7778
7821
|
}).then((unsub) => {
|
|
@@ -7827,6 +7870,31 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7827
7870
|
};
|
|
7828
7871
|
}
|
|
7829
7872
|
}
|
|
7873
|
+
/**
|
|
7874
|
+
* Retracts a previous bid and places a new one in a single transaction via utility.batch.
|
|
7875
|
+
* The retraction runs first, so the old deposit is reclaimed even if the new bid then fails
|
|
7876
|
+
* (batch is non-atomic — a failing call interrupts the batch without reverting the calls that
|
|
7877
|
+
* already succeeded, unlike batchAll which would roll the retraction back too).
|
|
7878
|
+
*
|
|
7879
|
+
* @param retractCommitment - The order commitment of the bid to retract (bytes32)
|
|
7880
|
+
* @param bidCommitment - The order commitment of the new bid (bytes32)
|
|
7881
|
+
* @param userOp - The encoded PackedUserOperation as hex string
|
|
7882
|
+
* @returns BidSubmissionResult with success status and block/extrinsic hash
|
|
7883
|
+
*/
|
|
7884
|
+
async submitBidWithRetraction(retractCommitment, bidCommitment, userOp) {
|
|
7885
|
+
try {
|
|
7886
|
+
const batch = this.api.tx.utility.batch([
|
|
7887
|
+
this.api.tx.intentsCoprocessor.retractBid(retractCommitment),
|
|
7888
|
+
this.api.tx.intentsCoprocessor.placeBid(bidCommitment, userOp)
|
|
7889
|
+
]);
|
|
7890
|
+
return await this.signAndSendExtrinsic(batch);
|
|
7891
|
+
} catch (error) {
|
|
7892
|
+
return {
|
|
7893
|
+
success: false,
|
|
7894
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
7895
|
+
};
|
|
7896
|
+
}
|
|
7897
|
+
}
|
|
7830
7898
|
/**
|
|
7831
7899
|
* Fetches all bid storage entries for a given order commitment.
|
|
7832
7900
|
* Returns the on-chain data only (filler addresses and deposits).
|
|
@@ -7911,6 +7979,80 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7911
7979
|
buildOffchainBidKey(commitment, filler) {
|
|
7912
7980
|
return u8aConcat(OFFCHAIN_BID_PREFIX, hexToU8a(commitment), decodeAddress(filler));
|
|
7913
7981
|
}
|
|
7982
|
+
/**
|
|
7983
|
+
* Fetches the ABI-encoded phantom order from offchain storage and decodes it
|
|
7984
|
+
* into an `Order` object. The pallet writes the order bytes under the key
|
|
7985
|
+
* `intents::phantom::order::<commitment>` when it calls `on_initialize`.
|
|
7986
|
+
*
|
|
7987
|
+
* Returns `null` if the key is absent (e.g. the node is not an offchain worker
|
|
7988
|
+
* or the commitment has expired and been cleared).
|
|
7989
|
+
*/
|
|
7990
|
+
async fetchPhantomOrder(commitment) {
|
|
7991
|
+
const key = u8aConcat(OFFCHAIN_PHANTOM_PREFIX, hexToU8a(commitment));
|
|
7992
|
+
const result = await this.api.rpc.offchain.localStorageGet("PERSISTENT", u8aToHex(key));
|
|
7993
|
+
if (!result || result.isNone) return null;
|
|
7994
|
+
const rawHex = result.unwrap().toHex();
|
|
7995
|
+
if (rawHex === "0x" || rawHex === "0x00") return null;
|
|
7996
|
+
const placeOrderAbi = IntentGatewayV2_default.ABI.find(
|
|
7997
|
+
(item) => item.type === "function" && item.name === "placeOrder"
|
|
7998
|
+
);
|
|
7999
|
+
const orderType = placeOrderAbi?.inputs?.[0];
|
|
8000
|
+
if (!orderType) return null;
|
|
8001
|
+
const [decoded] = decodeAbiParameters([orderType], rawHex);
|
|
8002
|
+
const d = decoded;
|
|
8003
|
+
const textDecoder = new TextDecoder();
|
|
8004
|
+
return {
|
|
8005
|
+
id: commitment,
|
|
8006
|
+
user: d.user,
|
|
8007
|
+
source: textDecoder.decode(hexToBytes(d.source)),
|
|
8008
|
+
destination: textDecoder.decode(hexToBytes(d.destination)),
|
|
8009
|
+
deadline: d.deadline,
|
|
8010
|
+
nonce: d.nonce,
|
|
8011
|
+
fees: d.fees,
|
|
8012
|
+
session: d.session,
|
|
8013
|
+
predispatch: {
|
|
8014
|
+
assets: d.predispatch.assets.map((a) => ({
|
|
8015
|
+
token: a.token,
|
|
8016
|
+
amount: a.amount
|
|
8017
|
+
})),
|
|
8018
|
+
call: d.predispatch.call
|
|
8019
|
+
},
|
|
8020
|
+
inputs: d.inputs.map((i) => ({
|
|
8021
|
+
token: i.token,
|
|
8022
|
+
amount: i.amount
|
|
8023
|
+
})),
|
|
8024
|
+
output: {
|
|
8025
|
+
beneficiary: d.output.beneficiary,
|
|
8026
|
+
assets: d.output.assets.map((a) => ({
|
|
8027
|
+
token: a.token,
|
|
8028
|
+
amount: a.amount
|
|
8029
|
+
})),
|
|
8030
|
+
call: d.output.call
|
|
8031
|
+
}
|
|
8032
|
+
};
|
|
8033
|
+
}
|
|
8034
|
+
/**
|
|
8035
|
+
* Subscribes to PhantomOrderRegistered events from the intents coprocessor pallet.
|
|
8036
|
+
* Calls the callback for each new phantom order as blocks arrive.
|
|
8037
|
+
* Returns an unsubscribe function to stop the subscription.
|
|
8038
|
+
*/
|
|
8039
|
+
async subscribePhantomOrders(callback) {
|
|
8040
|
+
const unsub = await this.api.query.system.events((records) => {
|
|
8041
|
+
for (const { event } of records) {
|
|
8042
|
+
if (event.section !== "intentsCoprocessor" || event.method !== "PhantomOrderRegistered") continue;
|
|
8043
|
+
const [commitment, chain, createdAt, tokenA, tokenB, standardAmount] = event.data;
|
|
8044
|
+
callback({
|
|
8045
|
+
commitment: commitment.toHex(),
|
|
8046
|
+
chain: new TextDecoder().decode(hexToU8a(chain.toHex())),
|
|
8047
|
+
createdAt: createdAt.toNumber(),
|
|
8048
|
+
tokenA: tokenA.toHex(),
|
|
8049
|
+
tokenB: tokenB.toHex(),
|
|
8050
|
+
standardAmount: BigInt(standardAmount.toString())
|
|
8051
|
+
});
|
|
8052
|
+
}
|
|
8053
|
+
});
|
|
8054
|
+
return unsub;
|
|
8055
|
+
}
|
|
7914
8056
|
};
|
|
7915
8057
|
var TronChain = class _TronChain {
|
|
7916
8058
|
constructor(params, evm) {
|
|
@@ -10312,26 +10454,27 @@ var PostRequestClient = class {
|
|
|
10312
10454
|
* accompanying timeout-proof calldata.
|
|
10313
10455
|
*/
|
|
10314
10456
|
async addTimeoutFinalityEvents(request) {
|
|
10315
|
-
const destChain = this.ctx.config.dest;
|
|
10316
|
-
const hyperbridge = this.ctx.config.hyperbridge;
|
|
10317
10457
|
const events = [];
|
|
10318
|
-
const commitment = postRequestCommitment(request).commitment;
|
|
10319
|
-
const receipt = await destChain.queryRequestReceipt(commitment);
|
|
10320
|
-
const destTimestamp = await destChain.timestamp();
|
|
10321
10458
|
const commit = (req) => {
|
|
10322
10459
|
this.logger.trace(`Added ${events.length} timeout events`, events);
|
|
10323
10460
|
request.statuses = [...req.statuses, ...events];
|
|
10324
10461
|
return request;
|
|
10325
10462
|
};
|
|
10326
10463
|
if (request.timeoutTimestamp === 0n) return commit(request);
|
|
10464
|
+
if (request.statuses.some(
|
|
10465
|
+
(item) => item.status === RequestStatus.DESTINATION || item.status === TimeoutStatus.TIMED_OUT
|
|
10466
|
+
))
|
|
10467
|
+
return commit(request);
|
|
10468
|
+
const destChain = this.ctx.config.dest;
|
|
10469
|
+
const hyperbridge = this.ctx.config.hyperbridge;
|
|
10470
|
+
const commitment = postRequestCommitment(request).commitment;
|
|
10471
|
+
const receipt = await destChain.queryRequestReceipt(commitment);
|
|
10472
|
+
const destTimestamp = await destChain.timestamp();
|
|
10327
10473
|
if (receipt || request.timeoutTimestamp > destTimestamp) return commit(request);
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
metadata: { blockHash: "0x", blockNumber: 0, transactionHash: "0x" }
|
|
10333
|
-
});
|
|
10334
|
-
}
|
|
10474
|
+
events.push({
|
|
10475
|
+
status: TimeoutStatus.PENDING_TIMEOUT,
|
|
10476
|
+
metadata: { blockHash: "0x", blockNumber: 0, transactionHash: "0x" }
|
|
10477
|
+
});
|
|
10335
10478
|
const delivered = request.statuses.find((item) => item.status === RequestStatus.HYPERBRIDGE_DELIVERED);
|
|
10336
10479
|
let hyperbridgeFinalized;
|
|
10337
10480
|
if (!delivered) {
|
|
@@ -14662,16 +14805,6 @@ var CryptoUtils = class _CryptoUtils {
|
|
|
14662
14805
|
}
|
|
14663
14806
|
}
|
|
14664
14807
|
};
|
|
14665
|
-
var FEE_TOKEN_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
14666
|
-
async function getFeeToken(ctx, chainId, chain) {
|
|
14667
|
-
const cached = ctx.feeTokenCache.get(chainId);
|
|
14668
|
-
if (cached && Date.now() - cached.cachedAt < FEE_TOKEN_CACHE_TTL_MS) {
|
|
14669
|
-
return cached;
|
|
14670
|
-
}
|
|
14671
|
-
const fresh = await chain.getFeeTokenWithDecimals();
|
|
14672
|
-
ctx.feeTokenCache.set(chainId, { ...fresh, cachedAt: Date.now() });
|
|
14673
|
-
return fresh;
|
|
14674
|
-
}
|
|
14675
14808
|
function encodeERC7821ExecuteBatch(calls) {
|
|
14676
14809
|
const executionData = encodeAbiParameters(
|
|
14677
14810
|
[{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
|
|
@@ -14683,6 +14816,36 @@ function encodeERC7821ExecuteBatch(calls) {
|
|
|
14683
14816
|
args: [ERC7821_BATCH_MODE, executionData]
|
|
14684
14817
|
});
|
|
14685
14818
|
}
|
|
14819
|
+
function decodeERC7821ExecuteBatch(callData) {
|
|
14820
|
+
try {
|
|
14821
|
+
const decoded = decodeFunctionData({ abi: erc7281_default.ABI, data: callData });
|
|
14822
|
+
if (decoded.functionName !== "execute" || !decoded.args || decoded.args.length < 2) return null;
|
|
14823
|
+
const executionData = decoded.args[1];
|
|
14824
|
+
const [calls] = decodeAbiParameters(
|
|
14825
|
+
[{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
|
|
14826
|
+
executionData
|
|
14827
|
+
);
|
|
14828
|
+
return calls.map((call) => ({
|
|
14829
|
+
target: call.target,
|
|
14830
|
+
value: call.value,
|
|
14831
|
+
data: call.data
|
|
14832
|
+
}));
|
|
14833
|
+
} catch {
|
|
14834
|
+
return null;
|
|
14835
|
+
}
|
|
14836
|
+
}
|
|
14837
|
+
|
|
14838
|
+
// src/protocols/intents/utils.ts
|
|
14839
|
+
var FEE_TOKEN_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
14840
|
+
async function getFeeToken(ctx, chainId, chain) {
|
|
14841
|
+
const cached = ctx.feeTokenCache.get(chainId);
|
|
14842
|
+
if (cached && Date.now() - cached.cachedAt < FEE_TOKEN_CACHE_TTL_MS) {
|
|
14843
|
+
return cached;
|
|
14844
|
+
}
|
|
14845
|
+
const fresh = await chain.getFeeTokenWithDecimals();
|
|
14846
|
+
ctx.feeTokenCache.set(chainId, { ...fresh, cachedAt: Date.now() });
|
|
14847
|
+
return fresh;
|
|
14848
|
+
}
|
|
14686
14849
|
async function fetchSourceProof(commitment, source, sourceStateMachine, sourceConsensusStateId, sourceHeight) {
|
|
14687
14850
|
const { slot1, slot2 } = requestCommitmentKey(commitment);
|
|
14688
14851
|
const proofHex = await source.queryStateProof(sourceHeight, [slot1, slot2]);
|
|
@@ -18562,6 +18725,11 @@ var HyperFungibleTokenABI = [
|
|
|
18562
18725
|
name: "context",
|
|
18563
18726
|
type: "bytes",
|
|
18564
18727
|
internalType: "bytes"
|
|
18728
|
+
},
|
|
18729
|
+
{
|
|
18730
|
+
name: "payer",
|
|
18731
|
+
type: "address",
|
|
18732
|
+
internalType: "address"
|
|
18565
18733
|
}
|
|
18566
18734
|
]
|
|
18567
18735
|
}
|
|
@@ -19683,6 +19851,11 @@ var WrappedHyperFungibleTokenABI = [
|
|
|
19683
19851
|
name: "context",
|
|
19684
19852
|
type: "bytes",
|
|
19685
19853
|
internalType: "bytes"
|
|
19854
|
+
},
|
|
19855
|
+
{
|
|
19856
|
+
name: "payer",
|
|
19857
|
+
type: "address",
|
|
19858
|
+
internalType: "address"
|
|
19686
19859
|
}
|
|
19687
19860
|
]
|
|
19688
19861
|
}
|
|
@@ -21520,6 +21693,11 @@ var ABI8 = [
|
|
|
21520
21693
|
internalType: "bytes",
|
|
21521
21694
|
name: "context",
|
|
21522
21695
|
type: "bytes"
|
|
21696
|
+
},
|
|
21697
|
+
{
|
|
21698
|
+
internalType: "address",
|
|
21699
|
+
name: "payer",
|
|
21700
|
+
type: "address"
|
|
21523
21701
|
}
|
|
21524
21702
|
],
|
|
21525
21703
|
internalType: "struct DispatchGet",
|
|
@@ -21788,6 +21966,11 @@ var ABI8 = [
|
|
|
21788
21966
|
internalType: "bytes",
|
|
21789
21967
|
name: "context",
|
|
21790
21968
|
type: "bytes"
|
|
21969
|
+
},
|
|
21970
|
+
{
|
|
21971
|
+
internalType: "address",
|
|
21972
|
+
name: "payer",
|
|
21973
|
+
type: "address"
|
|
21791
21974
|
}
|
|
21792
21975
|
],
|
|
21793
21976
|
internalType: "struct DispatchGet",
|
|
@@ -22150,6 +22333,6 @@ async function teleportDot(param_) {
|
|
|
22150
22333
|
return stream;
|
|
22151
22334
|
}
|
|
22152
22335
|
|
|
22153
|
-
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, IsmpClient, 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, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
22336
|
+
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, IsmpClient, 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, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeERC7821ExecuteBatch, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
22154
22337
|
//# sourceMappingURL=index.js.map
|
|
22155
22338
|
//# sourceMappingURL=index.js.map
|