@hyperbridge/sdk 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +22 -18
- package/dist/browser/index.js +107 -74
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +22 -18
- package/dist/node/index.js +107 -74
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -717,8 +717,8 @@ declare class EvmChain implements IChain {
|
|
|
717
717
|
* @param request - The post request to calculate the fee for
|
|
718
718
|
* @returns The total fee in wei required to send the post request
|
|
719
719
|
*/
|
|
720
|
-
quote(request: IPostRequest): Promise<bigint>;
|
|
721
|
-
quoteNative(request: IPostRequest, fee: bigint): Promise<bigint>;
|
|
720
|
+
quote(request: IPostRequest | IGetRequest): Promise<bigint>;
|
|
721
|
+
quoteNative(request: IPostRequest | IGetRequest, fee: bigint): Promise<bigint>;
|
|
722
722
|
private getAmountsIn;
|
|
723
723
|
/**
|
|
724
724
|
* Estimates the gas required for a post request execution on this chain.
|
|
@@ -2994,6 +2994,11 @@ declare class IntentGateway {
|
|
|
2994
2994
|
*/
|
|
2995
2995
|
isOrderFilled(order: Order): Promise<boolean>;
|
|
2996
2996
|
private submitAndConfirmReceipt;
|
|
2997
|
+
/**
|
|
2998
|
+
* Returns the native token amount required to dispatch a cancellation GET request for the given order.
|
|
2999
|
+
* Internally constructs the IGetRequest and calls quoteNative.
|
|
3000
|
+
*/
|
|
3001
|
+
quoteCancelNative(order: Order): Promise<bigint>;
|
|
2997
3002
|
/**
|
|
2998
3003
|
* Cancels an order through the cross-chain protocol by generating and submitting proofs.
|
|
2999
3004
|
* This is an async generator function that yields status updates throughout the cancellation process.
|
|
@@ -3123,7 +3128,7 @@ type HyperbridgeTxEvents = {
|
|
|
3123
3128
|
error: unknown;
|
|
3124
3129
|
};
|
|
3125
3130
|
/**
|
|
3126
|
-
* Parameters for teleporting DOT from
|
|
3131
|
+
* Parameters for teleporting DOT from AssetHub to EVM-based destination
|
|
3127
3132
|
*/
|
|
3128
3133
|
type XcmGatewayParams = {
|
|
3129
3134
|
/**
|
|
@@ -3152,33 +3157,32 @@ type XcmGatewayParams = {
|
|
|
3152
3157
|
paraId: number;
|
|
3153
3158
|
};
|
|
3154
3159
|
/**
|
|
3155
|
-
* Teleports DOT tokens from
|
|
3156
|
-
* using XCM
|
|
3157
|
-
*
|
|
3160
|
+
* Teleports DOT tokens from AssetHub to Hyperbridge parachain
|
|
3161
|
+
* using XCM V3 with transferAssetsUsingTypeAndThen.
|
|
3162
|
+
*
|
|
3163
|
+
* This function uses transferAssetsUsingTypeAndThen to construct XCM V3 transfers with a custom
|
|
3164
|
+
* beneficiary structure that embeds Hyperbridge-specific parameters (sender account, recipient EVM address,
|
|
3165
|
+
* timeout, and nonce) within an X4 junction. The beneficiary is wrapped in a DepositAsset XCM V3 instruction
|
|
3166
|
+
* that deposits all transferred assets. The assets are transferred using LocalReserve transfer type.
|
|
3158
3167
|
*
|
|
3159
|
-
* This function initiates a teleport transaction, monitors its status through the indexer,
|
|
3160
|
-
* and yields events about the transaction's progress through a ReadableStream.
|
|
3161
3168
|
* It handles the complete lifecycle of a teleport operation:
|
|
3162
|
-
* 1.
|
|
3163
|
-
* 2.
|
|
3164
|
-
* 3.
|
|
3165
|
-
* 4.
|
|
3169
|
+
* 1. Encoding Hyperbridge parameters into the beneficiary X4 junction
|
|
3170
|
+
* 2. Wrapping the beneficiary in a DepositAsset XCM V3 instruction using sourceApi.createType
|
|
3171
|
+
* 3. Constructing the XCM V3 transfer transaction using polkadotXcm.transferAssetsUsingTypeAndThen
|
|
3172
|
+
* 4. Transaction signing and broadcasting
|
|
3173
|
+
* 5. Yielding events about transaction status through a ReadableStream
|
|
3166
3174
|
*
|
|
3167
3175
|
* Note: There is no guarantee that both Dispatched and Finalized events will be yielded.
|
|
3168
3176
|
* Consumers should listen for either one of these events instead of expecting both.
|
|
3169
3177
|
*
|
|
3170
|
-
* @param sourceApi - Polkadot API instance connected to
|
|
3171
|
-
* @param sourceIsAssetHub - If `true` uses AssetHub Network for teleport
|
|
3178
|
+
* @param sourceApi - Polkadot API instance connected to AssetHub
|
|
3172
3179
|
* @param who - Sender's SS58Address address
|
|
3173
3180
|
* @param options - Transaction signing options
|
|
3174
|
-
* @param params - Teleport parameters including destination, recipient, and
|
|
3175
|
-
* @param indexerClient - The indexer client to track the transaction
|
|
3176
|
-
* @param pollInterval - Optional polling interval in milliseconds (default: 2000)
|
|
3181
|
+
* @param params - Teleport parameters including destination, recipient, amount, timeout, and paraId
|
|
3177
3182
|
* @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
|
|
3178
3183
|
*/
|
|
3179
3184
|
declare function teleportDot(param_: {
|
|
3180
3185
|
sourceApi: ApiPromise;
|
|
3181
|
-
sourceIsAssetHub: boolean;
|
|
3182
3186
|
who: string;
|
|
3183
3187
|
xcmGatewayParams: XcmGatewayParams;
|
|
3184
3188
|
options: Partial<SignerOptions>;
|
package/dist/browser/index.js
CHANGED
|
@@ -6081,13 +6081,14 @@ var EvmChain = class {
|
|
|
6081
6081
|
* @returns The total fee in wei required to send the post request
|
|
6082
6082
|
*/
|
|
6083
6083
|
async quote(request) {
|
|
6084
|
+
const bodyByteLength = "body" in request ? Math.floor((request.body.length - 2) / 2) : Math.floor((request.context.length - 2) / 2);
|
|
6085
|
+
const args = "body" in request ? [toHex(request.dest)] : [toHex(request.source)];
|
|
6084
6086
|
const perByteFee = await this.publicClient.readContract({
|
|
6085
6087
|
address: this.params.host,
|
|
6086
6088
|
abi: evmHost_default.ABI,
|
|
6087
6089
|
functionName: "perByteFee",
|
|
6088
|
-
args
|
|
6090
|
+
args
|
|
6089
6091
|
});
|
|
6090
|
-
const bodyByteLength = Math.floor((request.body.length - 2) / 2);
|
|
6091
6092
|
const length = bodyByteLength < 32 ? 32 : bodyByteLength;
|
|
6092
6093
|
return perByteFee * BigInt(length);
|
|
6093
6094
|
}
|
|
@@ -6923,7 +6924,7 @@ query GetResponseByRequestId($requestId: String!) {
|
|
|
6923
6924
|
`;
|
|
6924
6925
|
var ORDER_STATUS = `
|
|
6925
6926
|
query OrderStatus($commitment: String!) {
|
|
6926
|
-
|
|
6927
|
+
orders(
|
|
6927
6928
|
filter: { commitment: { equalTo: $commitment } }
|
|
6928
6929
|
) {
|
|
6929
6930
|
nodes {
|
|
@@ -6944,6 +6945,7 @@ query OrderStatus($commitment: String!) {
|
|
|
6944
6945
|
outputBeneficiaries
|
|
6945
6946
|
calldata
|
|
6946
6947
|
status
|
|
6948
|
+
referrer
|
|
6947
6949
|
createdAt
|
|
6948
6950
|
blockNumber
|
|
6949
6951
|
blockTimestamp
|
|
@@ -12782,6 +12784,60 @@ var IntentGateway = class {
|
|
|
12782
12784
|
}
|
|
12783
12785
|
console.log("Hyperbridge Receipt confirmed.");
|
|
12784
12786
|
}
|
|
12787
|
+
/**
|
|
12788
|
+
* Returns the native token amount required to dispatch a cancellation GET request for the given order.
|
|
12789
|
+
* Internally constructs the IGetRequest and calls quoteNative.
|
|
12790
|
+
*/
|
|
12791
|
+
async quoteCancelNative(order) {
|
|
12792
|
+
const orderWithCommitment = transformOrder(order);
|
|
12793
|
+
const height = orderWithCommitment.deadline + 1n;
|
|
12794
|
+
const destIntentGateway = this.dest.configService.getIntentGatewayAddress(orderWithCommitment.destChain);
|
|
12795
|
+
const slotHash = await this.dest.client.readContract({
|
|
12796
|
+
abi: IntentGateway_default.ABI,
|
|
12797
|
+
address: destIntentGateway,
|
|
12798
|
+
functionName: "calculateCommitmentSlotHash",
|
|
12799
|
+
args: [orderWithCommitment.id]
|
|
12800
|
+
});
|
|
12801
|
+
const key = concatHex([destIntentGateway, slotHash]);
|
|
12802
|
+
const context = encodeAbiParameters(
|
|
12803
|
+
[
|
|
12804
|
+
{
|
|
12805
|
+
name: "requestBody",
|
|
12806
|
+
type: "tuple",
|
|
12807
|
+
components: [
|
|
12808
|
+
{ name: "commitment", type: "bytes32" },
|
|
12809
|
+
{ name: "beneficiary", type: "bytes32" },
|
|
12810
|
+
{
|
|
12811
|
+
name: "tokens",
|
|
12812
|
+
type: "tuple[]",
|
|
12813
|
+
components: [
|
|
12814
|
+
{ name: "token", type: "bytes32" },
|
|
12815
|
+
{ name: "amount", type: "uint256" }
|
|
12816
|
+
]
|
|
12817
|
+
}
|
|
12818
|
+
]
|
|
12819
|
+
}
|
|
12820
|
+
],
|
|
12821
|
+
[
|
|
12822
|
+
{
|
|
12823
|
+
commitment: orderWithCommitment.id,
|
|
12824
|
+
beneficiary: orderWithCommitment.user,
|
|
12825
|
+
tokens: orderWithCommitment.inputs
|
|
12826
|
+
}
|
|
12827
|
+
]
|
|
12828
|
+
);
|
|
12829
|
+
const getRequest = {
|
|
12830
|
+
source: orderWithCommitment.sourceChain,
|
|
12831
|
+
dest: orderWithCommitment.destChain,
|
|
12832
|
+
from: this.source.configService.getIntentGatewayAddress(orderWithCommitment.destChain),
|
|
12833
|
+
nonce: await this.source.getHostNonce(),
|
|
12834
|
+
height,
|
|
12835
|
+
keys: [key],
|
|
12836
|
+
timeoutTimestamp: 0n,
|
|
12837
|
+
context
|
|
12838
|
+
};
|
|
12839
|
+
return await this.source.quoteNative(getRequest, 0n);
|
|
12840
|
+
}
|
|
12785
12841
|
/**
|
|
12786
12842
|
* Cancels an order through the cross-chain protocol by generating and submitting proofs.
|
|
12787
12843
|
* This is an async generator function that yields status updates throughout the cancellation process.
|
|
@@ -13116,7 +13172,7 @@ var MultiAccount = Struct({
|
|
|
13116
13172
|
});
|
|
13117
13173
|
var DECIMALS = 10;
|
|
13118
13174
|
async function teleportDot(param_) {
|
|
13119
|
-
const { sourceApi,
|
|
13175
|
+
const { sourceApi, who, options, xcmGatewayParams: params } = param_;
|
|
13120
13176
|
const { nonce: accountNonce } = await sourceApi.query.system.account(who);
|
|
13121
13177
|
const encoded_message = MultiAccount.enc({
|
|
13122
13178
|
substrate_account: decodeAddress(who),
|
|
@@ -13127,7 +13183,7 @@ async function teleportDot(param_) {
|
|
|
13127
13183
|
});
|
|
13128
13184
|
const message_id = keccakAsHex(encoded_message);
|
|
13129
13185
|
const beneficiary = {
|
|
13130
|
-
|
|
13186
|
+
V4: {
|
|
13131
13187
|
parents: 0,
|
|
13132
13188
|
interior: {
|
|
13133
13189
|
X4: [
|
|
@@ -13157,81 +13213,58 @@ async function teleportDot(param_) {
|
|
|
13157
13213
|
}
|
|
13158
13214
|
}
|
|
13159
13215
|
};
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
parents: 1,
|
|
13166
|
-
interior: {
|
|
13167
|
-
X1: {
|
|
13168
|
-
Parachain: params.paraId
|
|
13169
|
-
}
|
|
13170
|
-
}
|
|
13216
|
+
const destination = {
|
|
13217
|
+
V4: {
|
|
13218
|
+
parents: 1,
|
|
13219
|
+
interior: {
|
|
13220
|
+
X1: [{ Parachain: params.paraId }]
|
|
13171
13221
|
}
|
|
13172
|
-
}
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13184
|
-
}
|
|
13185
|
-
}
|
|
13186
|
-
]
|
|
13187
|
-
};
|
|
13188
|
-
} else {
|
|
13189
|
-
destination = {
|
|
13190
|
-
V3: {
|
|
13191
|
-
parents: 0,
|
|
13192
|
-
interior: {
|
|
13193
|
-
X1: {
|
|
13194
|
-
Parachain: params.paraId
|
|
13195
|
-
}
|
|
13222
|
+
}
|
|
13223
|
+
};
|
|
13224
|
+
const assets2 = {
|
|
13225
|
+
V4: [
|
|
13226
|
+
{
|
|
13227
|
+
id: {
|
|
13228
|
+
parents: 1,
|
|
13229
|
+
interior: "Here"
|
|
13230
|
+
},
|
|
13231
|
+
fun: {
|
|
13232
|
+
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13196
13233
|
}
|
|
13197
13234
|
}
|
|
13198
|
-
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
|
|
13235
|
+
]
|
|
13236
|
+
};
|
|
13237
|
+
const weightLimit = "Unlimited";
|
|
13238
|
+
const feeAssetId = {
|
|
13239
|
+
V4: assets2.V4[0].id
|
|
13240
|
+
};
|
|
13241
|
+
const customXcmOnDest = {
|
|
13242
|
+
V4: [
|
|
13243
|
+
{
|
|
13244
|
+
DepositAsset: {
|
|
13245
|
+
assets: {
|
|
13246
|
+
Wild: {
|
|
13247
|
+
AllCounted: 1
|
|
13206
13248
|
}
|
|
13207
13249
|
},
|
|
13208
|
-
|
|
13209
|
-
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13210
|
-
}
|
|
13250
|
+
beneficiary: beneficiary.V4
|
|
13211
13251
|
}
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
}
|
|
13215
|
-
const
|
|
13216
|
-
|
|
13217
|
-
|
|
13218
|
-
|
|
13219
|
-
|
|
13220
|
-
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
|
|
13227
|
-
|
|
13228
|
-
destination,
|
|
13229
|
-
beneficiary,
|
|
13230
|
-
assets2,
|
|
13231
|
-
feeAssetItem,
|
|
13232
|
-
weightLimit
|
|
13233
|
-
);
|
|
13234
|
-
}
|
|
13252
|
+
}
|
|
13253
|
+
]
|
|
13254
|
+
};
|
|
13255
|
+
const tx = sourceApi.tx.polkadotXcm.transferAssetsUsingTypeAndThen(
|
|
13256
|
+
destination,
|
|
13257
|
+
assets2,
|
|
13258
|
+
{ LocalReserve: null },
|
|
13259
|
+
// Assets transfer type
|
|
13260
|
+
feeAssetId,
|
|
13261
|
+
// Fee asset ID wrapped as VersionedAssetId
|
|
13262
|
+
{ LocalReserve: null },
|
|
13263
|
+
// Remote fee transfer type
|
|
13264
|
+
customXcmOnDest,
|
|
13265
|
+
// XCM instruction with DepositAsset containing custom beneficiary
|
|
13266
|
+
weightLimit
|
|
13267
|
+
);
|
|
13235
13268
|
let closed = false;
|
|
13236
13269
|
let unsubscribe;
|
|
13237
13270
|
const stream = new ReadableStream(
|