@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/node/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/node/index.js
CHANGED
|
@@ -3362,8 +3362,8 @@ var assets = {
|
|
|
3362
3362
|
},
|
|
3363
3363
|
["EVM-10200" /* GNOSIS_CHIADO */]: {
|
|
3364
3364
|
WETH: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3365
|
-
|
|
3366
|
-
|
|
3365
|
+
USDC: "0x50B1d3c7c073c9caa1Ef207365A2c9C976bD70b9".toLowerCase(),
|
|
3366
|
+
DAI: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3367
3367
|
USDT: "0x0000000000000000000000000000000000000000".toLowerCase()
|
|
3368
3368
|
},
|
|
3369
3369
|
["EVM-11155111" /* SEPOLIA */]: {
|
|
@@ -3606,7 +3606,7 @@ var ChainConfigService = class {
|
|
|
3606
3606
|
return {
|
|
3607
3607
|
chainId: chainIds[chain],
|
|
3608
3608
|
rpcUrl: this.rpcUrls[chain],
|
|
3609
|
-
intentGatewayAddress:
|
|
3609
|
+
intentGatewayAddress: this.getIntentGatewayAddress(chain)
|
|
3610
3610
|
};
|
|
3611
3611
|
}
|
|
3612
3612
|
getIntentGatewayAddress(chain) {
|
|
@@ -6818,6 +6818,31 @@ query GetRequestDetails($commitment: String!) {
|
|
|
6818
6818
|
}`;
|
|
6819
6819
|
var STATE_MACHINE_UPDATES_BY_HEIGHT = `
|
|
6820
6820
|
query StateMachineUpdatesByHeight($statemachineId: String!, $height: Int!, $chain: String!) {
|
|
6821
|
+
stateMachineUpdateEvents(
|
|
6822
|
+
filter: {
|
|
6823
|
+
and: [
|
|
6824
|
+
{ stateMachineId: { equalTo: $statemachineId } }
|
|
6825
|
+
{ height: { greaterThanOrEqualTo: $height } }
|
|
6826
|
+
{ chain: { equalTo: $chain } }
|
|
6827
|
+
]
|
|
6828
|
+
}
|
|
6829
|
+
orderBy: HEIGHT_ASC
|
|
6830
|
+
first: 1
|
|
6831
|
+
) {
|
|
6832
|
+
nodes {
|
|
6833
|
+
height
|
|
6834
|
+
stateMachineId
|
|
6835
|
+
chain
|
|
6836
|
+
blockHash
|
|
6837
|
+
blockNumber
|
|
6838
|
+
transactionHash
|
|
6839
|
+
createdAt
|
|
6840
|
+
}
|
|
6841
|
+
}
|
|
6842
|
+
}
|
|
6843
|
+
`;
|
|
6844
|
+
var STATE_MACHINE_UPDATES_BY_HEIGHT_DESC = `
|
|
6845
|
+
query StateMachineUpdatesByHeightDesc($statemachineId: String!, $height: Int!, $chain: String!) {
|
|
6821
6846
|
stateMachineUpdateEvents(
|
|
6822
6847
|
filter: {
|
|
6823
6848
|
and: [
|
|
@@ -6938,6 +6963,7 @@ query OrderStatus($commitment: String!) {
|
|
|
6938
6963
|
outputAmounts
|
|
6939
6964
|
outputBeneficiaries
|
|
6940
6965
|
calldata
|
|
6966
|
+
referrer
|
|
6941
6967
|
status
|
|
6942
6968
|
referrer
|
|
6943
6969
|
createdAt
|
|
@@ -7272,22 +7298,47 @@ var IndexerClient = class {
|
|
|
7272
7298
|
}) {
|
|
7273
7299
|
const logger = this.logger.withTag("[queryStateMachineUpdateByHeight]()");
|
|
7274
7300
|
const message = `querying StateMachineId(${statemachineId}) update by Height(${height}) in chain Chain(${chain})`;
|
|
7275
|
-
const
|
|
7276
|
-
(
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7301
|
+
const [ascResponse, descResponse] = await Promise.all([
|
|
7302
|
+
this.withRetry(
|
|
7303
|
+
() => {
|
|
7304
|
+
return this.client.request(STATE_MACHINE_UPDATES_BY_HEIGHT, {
|
|
7305
|
+
statemachineId,
|
|
7306
|
+
height,
|
|
7307
|
+
chain
|
|
7308
|
+
});
|
|
7309
|
+
},
|
|
7310
|
+
{ logger, logMessage: `${message} (ASC)` }
|
|
7311
|
+
),
|
|
7312
|
+
this.withRetry(
|
|
7313
|
+
() => {
|
|
7314
|
+
return this.client.request(STATE_MACHINE_UPDATES_BY_HEIGHT_DESC, {
|
|
7315
|
+
statemachineId,
|
|
7316
|
+
height,
|
|
7317
|
+
chain
|
|
7318
|
+
});
|
|
7319
|
+
},
|
|
7320
|
+
{ logger, logMessage: `${message} (DESC)` }
|
|
7321
|
+
)
|
|
7322
|
+
]);
|
|
7323
|
+
const ascNode = ascResponse?.stateMachineUpdateEvents?.nodes[0];
|
|
7324
|
+
const descNode = descResponse?.stateMachineUpdateEvents?.nodes[0];
|
|
7325
|
+
if (!ascNode) {
|
|
7326
|
+
return void 0;
|
|
7327
|
+
}
|
|
7328
|
+
const timestamp = Math.floor(dateStringtoTimestamp(ascNode.createdAt) / 1e3);
|
|
7329
|
+
const stateMachineHeight = descNode?.height ?? ascNode.height;
|
|
7330
|
+
const combined = {
|
|
7331
|
+
height: stateMachineHeight,
|
|
7332
|
+
chain: ascNode.chain,
|
|
7333
|
+
blockHash: ascNode.blockHash,
|
|
7334
|
+
blockNumber: ascNode.blockNumber,
|
|
7335
|
+
transactionHash: ascNode.transactionHash,
|
|
7336
|
+
transactionIndex: ascNode.transactionIndex,
|
|
7337
|
+
stateMachineId: ascNode.stateMachineId,
|
|
7338
|
+
timestamp
|
|
7339
|
+
};
|
|
7340
|
+
logger.trace("Response >", combined);
|
|
7341
|
+
return combined;
|
|
7291
7342
|
}
|
|
7292
7343
|
/**
|
|
7293
7344
|
* Query for a single state machine update event greater than or equal to the given timestamp.
|
|
@@ -12451,14 +12502,25 @@ var IntentGateway = class {
|
|
|
12451
12502
|
* Creates a new IntentGateway instance for cross-chain operations.
|
|
12452
12503
|
* @param source - The source EVM chain
|
|
12453
12504
|
* @param dest - The destination EVM chain
|
|
12505
|
+
* @param destIntentGatewayAddress - Optional custom IntentGateway address for the destination chain.
|
|
12506
|
+
* If provided, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
12507
|
+
* If not provided, uses the default address from the chain configuration.
|
|
12454
12508
|
*/
|
|
12455
|
-
constructor(source, dest) {
|
|
12509
|
+
constructor(source, dest, destIntentGatewayAddress) {
|
|
12456
12510
|
this.source = source;
|
|
12457
12511
|
this.dest = dest;
|
|
12458
12512
|
this.swap = new Swap();
|
|
12513
|
+
this.destIntentGatewayAddress = destIntentGatewayAddress;
|
|
12459
12514
|
}
|
|
12460
12515
|
swap;
|
|
12461
12516
|
storage = createCancellationStorage();
|
|
12517
|
+
/**
|
|
12518
|
+
* Optional custom IntentGateway address for the destination chain.
|
|
12519
|
+
* If set, this address will be used when fetching destination proofs in `cancelOrder`.
|
|
12520
|
+
* If not set, uses the default address from the chain configuration.
|
|
12521
|
+
* This allows using different IntentGateway contract versions (e.g., old vs new contracts).
|
|
12522
|
+
*/
|
|
12523
|
+
destIntentGatewayAddress;
|
|
12462
12524
|
/**
|
|
12463
12525
|
* Estimates the total cost required to fill an order, including gas fees, relayer fees,
|
|
12464
12526
|
* protocol fees, and swap operations.
|
|
@@ -12761,6 +12823,40 @@ var IntentGateway = class {
|
|
|
12761
12823
|
});
|
|
12762
12824
|
return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
12763
12825
|
}
|
|
12826
|
+
/**
|
|
12827
|
+
* Checks if an order has been refunded by verifying the escrowed token amounts on-chain.
|
|
12828
|
+
* Reads the storage slots for the `_orders` mapping on the source chain (where the escrow is held).
|
|
12829
|
+
* An order is considered refunded when all input token amounts in the `_orders` mapping are 0.
|
|
12830
|
+
*
|
|
12831
|
+
* @param order - The order to check
|
|
12832
|
+
* @returns True if the order has been refunded (all token amounts are 0), false otherwise
|
|
12833
|
+
*/
|
|
12834
|
+
async isOrderRefunded(order) {
|
|
12835
|
+
order = transformOrder(order);
|
|
12836
|
+
const intentGatewayAddress = this.destIntentGatewayAddress ?? this.source.configService.getIntentGatewayAddress(order.sourceChain);
|
|
12837
|
+
const commitment = order.id;
|
|
12838
|
+
const ORDERS_MAPPING_SLOT = 4n;
|
|
12839
|
+
const firstLevelSlot = keccak256(
|
|
12840
|
+
encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [commitment, ORDERS_MAPPING_SLOT])
|
|
12841
|
+
);
|
|
12842
|
+
for (const input of order.inputs) {
|
|
12843
|
+
const tokenAddress = bytes32ToBytes20(input.token);
|
|
12844
|
+
const storageSlot = keccak256(
|
|
12845
|
+
encodeAbiParameters(
|
|
12846
|
+
[{ type: "address" }, { type: "bytes32" }],
|
|
12847
|
+
[tokenAddress, firstLevelSlot]
|
|
12848
|
+
)
|
|
12849
|
+
);
|
|
12850
|
+
const escrowedAmount = await this.source.client.getStorageAt({
|
|
12851
|
+
address: intentGatewayAddress,
|
|
12852
|
+
slot: storageSlot
|
|
12853
|
+
});
|
|
12854
|
+
if (escrowedAmount !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
12855
|
+
return false;
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
return true;
|
|
12859
|
+
}
|
|
12764
12860
|
async submitAndConfirmReceipt(hyperbridge, commitment, message) {
|
|
12765
12861
|
let storageValue = await hyperbridge.queryRequestReceipt(commitment);
|
|
12766
12862
|
if (!storageValue) {
|
|
@@ -12864,6 +12960,21 @@ var IntentGateway = class {
|
|
|
12864
12960
|
*
|
|
12865
12961
|
* @example
|
|
12866
12962
|
* ```typescript
|
|
12963
|
+
* // Using default IntentGateway address
|
|
12964
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
12965
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
12966
|
+
*
|
|
12967
|
+
* // Using custom IntentGateway address (e.g., for old contract version)
|
|
12968
|
+
* const intentGateway = new IntentGateway(
|
|
12969
|
+
* sourceChain,
|
|
12970
|
+
* destChain,
|
|
12971
|
+
* "0xd54165e45926720b062C192a5bacEC64d5bB08DA"
|
|
12972
|
+
* );
|
|
12973
|
+
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
12974
|
+
*
|
|
12975
|
+
* // Or set it after instantiation
|
|
12976
|
+
* const intentGateway = new IntentGateway(sourceChain, destChain);
|
|
12977
|
+
* intentGateway.destIntentGatewayAddress = "0xd54165e45926720b062C192a5bacEC64d5bB08DA";
|
|
12867
12978
|
* const cancelStream = intentGateway.cancelOrder(order, indexerClient);
|
|
12868
12979
|
*
|
|
12869
12980
|
* for await (const event of cancelStream) {
|
|
@@ -12966,6 +13077,8 @@ var IntentGateway = class {
|
|
|
12966
13077
|
}
|
|
12967
13078
|
/**
|
|
12968
13079
|
* Fetches proof for the destination chain.
|
|
13080
|
+
* @param order - The order to fetch proof for
|
|
13081
|
+
* @param indexerClient - Client for querying the indexer
|
|
12969
13082
|
*/
|
|
12970
13083
|
async *fetchDestinationProof(order, indexerClient) {
|
|
12971
13084
|
let latestHeight = 0n;
|
|
@@ -12982,9 +13095,7 @@ var IntentGateway = class {
|
|
|
12982
13095
|
continue;
|
|
12983
13096
|
}
|
|
12984
13097
|
try {
|
|
12985
|
-
const intentGatewayAddress = this.dest.configService.getIntentGatewayAddress(
|
|
12986
|
-
this.dest.config.stateMachineId
|
|
12987
|
-
);
|
|
13098
|
+
const intentGatewayAddress = this.destIntentGatewayAddress ?? this.dest.configService.getIntentGatewayAddress(this.dest.config.stateMachineId);
|
|
12988
13099
|
const orderId = orderCommitment(order);
|
|
12989
13100
|
const slotHash = await this.dest.client.readContract({
|
|
12990
13101
|
abi: IntentGateway_default.ABI,
|