@hyperbridge/sdk 1.4.8 → 1.4.10
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 +38 -2
- package/dist/browser/index.js +134 -23
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +38 -2
- package/dist/node/index.js +134 -23
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -3012,12 +3012,22 @@ declare class IntentGateway {
|
|
|
3012
3012
|
readonly dest: EvmChain;
|
|
3013
3013
|
readonly swap: Swap;
|
|
3014
3014
|
private readonly storage;
|
|
3015
|
+
/**
|
|
3016
|
+
* Optional custom IntentGateway address for the destination chain.
|
|
3017
|
+
* If set, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
3018
|
+
* If not set, uses the default address from the chain configuration.
|
|
3019
|
+
* This allows using different IntentGateway contract versions (e.g., old vs new contracts).
|
|
3020
|
+
*/
|
|
3021
|
+
destIntentGatewayAddress?: HexString;
|
|
3015
3022
|
/**
|
|
3016
3023
|
* Creates a new IntentGateway instance for cross-chain operations.
|
|
3017
3024
|
* @param source - The source EVM chain
|
|
3018
3025
|
* @param dest - The destination EVM chain
|
|
3026
|
+
* @param destIntentGatewayAddress - Optional custom IntentGateway address for the destination chain.
|
|
3027
|
+
* If provided, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
3028
|
+
* If not provided, uses the default address from the chain configuration.
|
|
3019
3029
|
*/
|
|
3020
|
-
constructor(source: EvmChain, dest: EvmChain);
|
|
3030
|
+
constructor(source: EvmChain, dest: EvmChain, destIntentGatewayAddress?: HexString);
|
|
3021
3031
|
/**
|
|
3022
3032
|
* Estimates the total cost required to fill an order, including gas fees, relayer fees,
|
|
3023
3033
|
* protocol fees, and swap operations.
|
|
@@ -3069,6 +3079,15 @@ declare class IntentGateway {
|
|
|
3069
3079
|
* @returns True if the order has been filled, false otherwise
|
|
3070
3080
|
*/
|
|
3071
3081
|
isOrderFilled(order: Order): Promise<boolean>;
|
|
3082
|
+
/**
|
|
3083
|
+
* Checks if an order has been refunded by verifying the escrowed token amounts on-chain.
|
|
3084
|
+
* Reads the storage slots for the `_orders` mapping on the source chain (where the escrow is held).
|
|
3085
|
+
* An order is considered refunded when all input token amounts in the `_orders` mapping are 0.
|
|
3086
|
+
*
|
|
3087
|
+
* @param order - The order to check
|
|
3088
|
+
* @returns True if the order has been refunded (all token amounts are 0), false otherwise
|
|
3089
|
+
*/
|
|
3090
|
+
isOrderRefunded(order: Order): Promise<boolean>;
|
|
3072
3091
|
private submitAndConfirmReceipt;
|
|
3073
3092
|
/**
|
|
3074
3093
|
* Returns the native token amount required to dispatch a cancellation GET request for the given order.
|
|
@@ -3102,6 +3121,21 @@ declare class IntentGateway {
|
|
|
3102
3121
|
*
|
|
3103
3122
|
* @example
|
|
3104
3123
|
* ```typescript
|
|
3124
|
+
* // Using default IntentGateway address
|
|
3125
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
3126
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
3127
|
+
*
|
|
3128
|
+
* // Using custom IntentGateway address (e.g., for old contract version)
|
|
3129
|
+
* const intentGateway = new IntentGateway(
|
|
3130
|
+
* sourceChain,
|
|
3131
|
+
* destChain,
|
|
3132
|
+
* "0xd54165e45926720b062C192a5bacEC64d5bB08DA"
|
|
3133
|
+
* );
|
|
3134
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
3135
|
+
*
|
|
3136
|
+
* // Or set it after instantiation
|
|
3137
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
3138
|
+
* intentGateway.destIntentGatewayAddress = "0xd54165e45926720b062C192a5bacEC64d5bB08DA";
|
|
3105
3139
|
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
3106
3140
|
*
|
|
3107
3141
|
* for await (const event of cancelStream) {
|
|
@@ -3119,6 +3153,8 @@ declare class IntentGateway {
|
|
|
3119
3153
|
cancelOrder(order: Order, indexerClient: IndexerClient): AsyncGenerator<CancelEvent>;
|
|
3120
3154
|
/**
|
|
3121
3155
|
* Fetches proof for the destination chain.
|
|
3156
|
+
* @param order - The order to fetch proof for
|
|
3157
|
+
* @param indexerClient - Client for querying the indexer
|
|
3122
3158
|
*/
|
|
3123
3159
|
private fetchDestinationProof;
|
|
3124
3160
|
}
|
|
@@ -3390,8 +3426,8 @@ declare const assets: {
|
|
|
3390
3426
|
};
|
|
3391
3427
|
"EVM-10200": {
|
|
3392
3428
|
WETH: string;
|
|
3393
|
-
DAI: string;
|
|
3394
3429
|
USDC: string;
|
|
3430
|
+
DAI: string;
|
|
3395
3431
|
USDT: string;
|
|
3396
3432
|
};
|
|
3397
3433
|
"EVM-11155111": {
|
package/dist/browser/index.js
CHANGED
|
@@ -3412,8 +3412,8 @@ var assets = {
|
|
|
3412
3412
|
},
|
|
3413
3413
|
["EVM-10200" /* GNOSIS_CHIADO */]: {
|
|
3414
3414
|
WETH: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3415
|
-
|
|
3416
|
-
|
|
3415
|
+
USDC: "0x50B1d3c7c073c9caa1Ef207365A2c9C976bD70b9".toLowerCase(),
|
|
3416
|
+
DAI: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3417
3417
|
USDT: "0x0000000000000000000000000000000000000000".toLowerCase()
|
|
3418
3418
|
},
|
|
3419
3419
|
["EVM-11155111" /* SEPOLIA */]: {
|
|
@@ -3656,7 +3656,7 @@ var ChainConfigService = class {
|
|
|
3656
3656
|
return {
|
|
3657
3657
|
chainId: chainIds[chain],
|
|
3658
3658
|
rpcUrl: this.rpcUrls[chain],
|
|
3659
|
-
intentGatewayAddress:
|
|
3659
|
+
intentGatewayAddress: this.getIntentGatewayAddress(chain)
|
|
3660
3660
|
};
|
|
3661
3661
|
}
|
|
3662
3662
|
getIntentGatewayAddress(chain) {
|
|
@@ -6868,6 +6868,31 @@ query GetRequestDetails($commitment: String!) {
|
|
|
6868
6868
|
}`;
|
|
6869
6869
|
var STATE_MACHINE_UPDATES_BY_HEIGHT = `
|
|
6870
6870
|
query StateMachineUpdatesByHeight($statemachineId: String!, $height: Int!, $chain: String!) {
|
|
6871
|
+
stateMachineUpdateEvents(
|
|
6872
|
+
filter: {
|
|
6873
|
+
and: [
|
|
6874
|
+
{ stateMachineId: { equalTo: $statemachineId } }
|
|
6875
|
+
{ height: { greaterThanOrEqualTo: $height } }
|
|
6876
|
+
{ chain: { equalTo: $chain } }
|
|
6877
|
+
]
|
|
6878
|
+
}
|
|
6879
|
+
orderBy: HEIGHT_ASC
|
|
6880
|
+
first: 1
|
|
6881
|
+
) {
|
|
6882
|
+
nodes {
|
|
6883
|
+
height
|
|
6884
|
+
stateMachineId
|
|
6885
|
+
chain
|
|
6886
|
+
blockHash
|
|
6887
|
+
blockNumber
|
|
6888
|
+
transactionHash
|
|
6889
|
+
createdAt
|
|
6890
|
+
}
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
`;
|
|
6894
|
+
var STATE_MACHINE_UPDATES_BY_HEIGHT_DESC = `
|
|
6895
|
+
query StateMachineUpdatesByHeightDesc($statemachineId: String!, $height: Int!, $chain: String!) {
|
|
6871
6896
|
stateMachineUpdateEvents(
|
|
6872
6897
|
filter: {
|
|
6873
6898
|
and: [
|
|
@@ -6988,6 +7013,7 @@ query OrderStatus($commitment: String!) {
|
|
|
6988
7013
|
outputAmounts
|
|
6989
7014
|
outputBeneficiaries
|
|
6990
7015
|
calldata
|
|
7016
|
+
referrer
|
|
6991
7017
|
status
|
|
6992
7018
|
referrer
|
|
6993
7019
|
createdAt
|
|
@@ -7322,22 +7348,47 @@ var IndexerClient = class {
|
|
|
7322
7348
|
}) {
|
|
7323
7349
|
const logger = this.logger.withTag("[queryStateMachineUpdateByHeight]()");
|
|
7324
7350
|
const message = `querying StateMachineId(${statemachineId}) update by Height(${height}) in chain Chain(${chain})`;
|
|
7325
|
-
const
|
|
7326
|
-
(
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7351
|
+
const [ascResponse, descResponse] = await Promise.all([
|
|
7352
|
+
this.withRetry(
|
|
7353
|
+
() => {
|
|
7354
|
+
return this.client.request(STATE_MACHINE_UPDATES_BY_HEIGHT, {
|
|
7355
|
+
statemachineId,
|
|
7356
|
+
height,
|
|
7357
|
+
chain
|
|
7358
|
+
});
|
|
7359
|
+
},
|
|
7360
|
+
{ logger, logMessage: `${message} (ASC)` }
|
|
7361
|
+
),
|
|
7362
|
+
this.withRetry(
|
|
7363
|
+
() => {
|
|
7364
|
+
return this.client.request(STATE_MACHINE_UPDATES_BY_HEIGHT_DESC, {
|
|
7365
|
+
statemachineId,
|
|
7366
|
+
height,
|
|
7367
|
+
chain
|
|
7368
|
+
});
|
|
7369
|
+
},
|
|
7370
|
+
{ logger, logMessage: `${message} (DESC)` }
|
|
7371
|
+
)
|
|
7372
|
+
]);
|
|
7373
|
+
const ascNode = ascResponse?.stateMachineUpdateEvents?.nodes[0];
|
|
7374
|
+
const descNode = descResponse?.stateMachineUpdateEvents?.nodes[0];
|
|
7375
|
+
if (!ascNode) {
|
|
7376
|
+
return void 0;
|
|
7377
|
+
}
|
|
7378
|
+
const timestamp = Math.floor(dateStringtoTimestamp(ascNode.createdAt) / 1e3);
|
|
7379
|
+
const stateMachineHeight = descNode?.height ?? ascNode.height;
|
|
7380
|
+
const combined = {
|
|
7381
|
+
height: stateMachineHeight,
|
|
7382
|
+
chain: ascNode.chain,
|
|
7383
|
+
blockHash: ascNode.blockHash,
|
|
7384
|
+
blockNumber: ascNode.blockNumber,
|
|
7385
|
+
transactionHash: ascNode.transactionHash,
|
|
7386
|
+
transactionIndex: ascNode.transactionIndex,
|
|
7387
|
+
stateMachineId: ascNode.stateMachineId,
|
|
7388
|
+
timestamp
|
|
7389
|
+
};
|
|
7390
|
+
logger.trace("Response >", combined);
|
|
7391
|
+
return combined;
|
|
7341
7392
|
}
|
|
7342
7393
|
/**
|
|
7343
7394
|
* Query for a single state machine update event greater than or equal to the given timestamp.
|
|
@@ -12511,14 +12562,25 @@ var IntentGateway = class {
|
|
|
12511
12562
|
* Creates a new IntentGateway instance for cross-chain operations.
|
|
12512
12563
|
* @param source - The source EVM chain
|
|
12513
12564
|
* @param dest - The destination EVM chain
|
|
12565
|
+
* @param destIntentGatewayAddress - Optional custom IntentGateway address for the destination chain.
|
|
12566
|
+
* If provided, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
12567
|
+
* If not provided, uses the default address from the chain configuration.
|
|
12514
12568
|
*/
|
|
12515
|
-
constructor(source, dest) {
|
|
12569
|
+
constructor(source, dest, destIntentGatewayAddress) {
|
|
12516
12570
|
this.source = source;
|
|
12517
12571
|
this.dest = dest;
|
|
12518
12572
|
this.swap = new Swap();
|
|
12573
|
+
this.destIntentGatewayAddress = destIntentGatewayAddress;
|
|
12519
12574
|
}
|
|
12520
12575
|
swap;
|
|
12521
12576
|
storage = createCancellationStorage();
|
|
12577
|
+
/**
|
|
12578
|
+
* Optional custom IntentGateway address for the destination chain.
|
|
12579
|
+
* If set, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
12580
|
+
* If not set, uses the default address from the chain configuration.
|
|
12581
|
+
* This allows using different IntentGateway contract versions (e.g., old vs new contracts).
|
|
12582
|
+
*/
|
|
12583
|
+
destIntentGatewayAddress;
|
|
12522
12584
|
/**
|
|
12523
12585
|
* Estimates the total cost required to fill an order, including gas fees, relayer fees,
|
|
12524
12586
|
* protocol fees, and swap operations.
|
|
@@ -12821,6 +12883,40 @@ var IntentGateway = class {
|
|
|
12821
12883
|
});
|
|
12822
12884
|
return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
12823
12885
|
}
|
|
12886
|
+
/**
|
|
12887
|
+
* Checks if an order has been refunded by verifying the escrowed token amounts on-chain.
|
|
12888
|
+
* Reads the storage slots for the `_orders` mapping on the source chain (where the escrow is held).
|
|
12889
|
+
* An order is considered refunded when all input token amounts in the `_orders` mapping are 0.
|
|
12890
|
+
*
|
|
12891
|
+
* @param order - The order to check
|
|
12892
|
+
* @returns True if the order has been refunded (all token amounts are 0), false otherwise
|
|
12893
|
+
*/
|
|
12894
|
+
async isOrderRefunded(order) {
|
|
12895
|
+
order = transformOrder(order);
|
|
12896
|
+
const intentGatewayAddress = this.destIntentGatewayAddress ?? this.source.configService.getIntentGatewayAddress(order.sourceChain);
|
|
12897
|
+
const commitment = order.id;
|
|
12898
|
+
const ORDERS_MAPPING_SLOT = 4n;
|
|
12899
|
+
const firstLevelSlot = keccak256(
|
|
12900
|
+
encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [commitment, ORDERS_MAPPING_SLOT])
|
|
12901
|
+
);
|
|
12902
|
+
for (const input of order.inputs) {
|
|
12903
|
+
const tokenAddress = bytes32ToBytes20(input.token);
|
|
12904
|
+
const storageSlot = keccak256(
|
|
12905
|
+
encodeAbiParameters(
|
|
12906
|
+
[{ type: "address" }, { type: "bytes32" }],
|
|
12907
|
+
[tokenAddress, firstLevelSlot]
|
|
12908
|
+
)
|
|
12909
|
+
);
|
|
12910
|
+
const escrowedAmount = await this.source.client.getStorageAt({
|
|
12911
|
+
address: intentGatewayAddress,
|
|
12912
|
+
slot: storageSlot
|
|
12913
|
+
});
|
|
12914
|
+
if (escrowedAmount !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
12915
|
+
return false;
|
|
12916
|
+
}
|
|
12917
|
+
}
|
|
12918
|
+
return true;
|
|
12919
|
+
}
|
|
12824
12920
|
async submitAndConfirmReceipt(hyperbridge, commitment, message) {
|
|
12825
12921
|
let storageValue = await hyperbridge.queryRequestReceipt(commitment);
|
|
12826
12922
|
if (!storageValue) {
|
|
@@ -12924,6 +13020,21 @@ var IntentGateway = class {
|
|
|
12924
13020
|
*
|
|
12925
13021
|
* @example
|
|
12926
13022
|
* ```typescript
|
|
13023
|
+
* // Using default IntentGateway address
|
|
13024
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
13025
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
13026
|
+
*
|
|
13027
|
+
* // Using custom IntentGateway address (e.g., for old contract version)
|
|
13028
|
+
* const intentGateway = new IntentGateway(
|
|
13029
|
+
* sourceChain,
|
|
13030
|
+
* destChain,
|
|
13031
|
+
* "0xd54165e45926720b062C192a5bacEC64d5bB08DA"
|
|
13032
|
+
* );
|
|
13033
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
13034
|
+
*
|
|
13035
|
+
* // Or set it after instantiation
|
|
13036
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
13037
|
+
* intentGateway.destIntentGatewayAddress = "0xd54165e45926720b062C192a5bacEC64d5bB08DA";
|
|
12927
13038
|
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
12928
13039
|
*
|
|
12929
13040
|
* for await (const event of cancelStream) {
|
|
@@ -13026,6 +13137,8 @@ var IntentGateway = class {
|
|
|
13026
13137
|
}
|
|
13027
13138
|
/**
|
|
13028
13139
|
* Fetches proof for the destination chain.
|
|
13140
|
+
* @param order - The order to fetch proof for
|
|
13141
|
+
* @param indexerClient - Client for querying the indexer
|
|
13029
13142
|
*/
|
|
13030
13143
|
async *fetchDestinationProof(order, indexerClient) {
|
|
13031
13144
|
let latestHeight = 0n;
|
|
@@ -13042,9 +13155,7 @@ var IntentGateway = class {
|
|
|
13042
13155
|
continue;
|
|
13043
13156
|
}
|
|
13044
13157
|
try {
|
|
13045
|
-
const intentGatewayAddress = this.dest.configService.getIntentGatewayAddress(
|
|
13046
|
-
this.dest.config.stateMachineId
|
|
13047
|
-
);
|
|
13158
|
+
const intentGatewayAddress = this.destIntentGatewayAddress ?? this.dest.configService.getIntentGatewayAddress(this.dest.config.stateMachineId);
|
|
13048
13159
|
const orderId = orderCommitment(order);
|
|
13049
13160
|
const slotHash = await this.dest.client.readContract({
|
|
13050
13161
|
abi: IntentGateway_default.ABI,
|