@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/node/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/node/index.js
CHANGED
|
@@ -6032,13 +6032,14 @@ var EvmChain = class {
|
|
|
6032
6032
|
* @returns The total fee in wei required to send the post request
|
|
6033
6033
|
*/
|
|
6034
6034
|
async quote(request) {
|
|
6035
|
+
const bodyByteLength = "body" in request ? Math.floor((request.body.length - 2) / 2) : Math.floor((request.context.length - 2) / 2);
|
|
6036
|
+
const args = "body" in request ? [toHex(request.dest)] : [toHex(request.source)];
|
|
6035
6037
|
const perByteFee = await this.publicClient.readContract({
|
|
6036
6038
|
address: this.params.host,
|
|
6037
6039
|
abi: evmHost_default.ABI,
|
|
6038
6040
|
functionName: "perByteFee",
|
|
6039
|
-
args
|
|
6041
|
+
args
|
|
6040
6042
|
});
|
|
6041
|
-
const bodyByteLength = Math.floor((request.body.length - 2) / 2);
|
|
6042
6043
|
const length = bodyByteLength < 32 ? 32 : bodyByteLength;
|
|
6043
6044
|
return perByteFee * BigInt(length);
|
|
6044
6045
|
}
|
|
@@ -6874,7 +6875,7 @@ query GetResponseByRequestId($requestId: String!) {
|
|
|
6874
6875
|
`;
|
|
6875
6876
|
var ORDER_STATUS = `
|
|
6876
6877
|
query OrderStatus($commitment: String!) {
|
|
6877
|
-
|
|
6878
|
+
orders(
|
|
6878
6879
|
filter: { commitment: { equalTo: $commitment } }
|
|
6879
6880
|
) {
|
|
6880
6881
|
nodes {
|
|
@@ -6895,6 +6896,7 @@ query OrderStatus($commitment: String!) {
|
|
|
6895
6896
|
outputBeneficiaries
|
|
6896
6897
|
calldata
|
|
6897
6898
|
status
|
|
6899
|
+
referrer
|
|
6898
6900
|
createdAt
|
|
6899
6901
|
blockNumber
|
|
6900
6902
|
blockTimestamp
|
|
@@ -12733,6 +12735,60 @@ var IntentGateway = class {
|
|
|
12733
12735
|
}
|
|
12734
12736
|
console.log("Hyperbridge Receipt confirmed.");
|
|
12735
12737
|
}
|
|
12738
|
+
/**
|
|
12739
|
+
* Returns the native token amount required to dispatch a cancellation GET request for the given order.
|
|
12740
|
+
* Internally constructs the IGetRequest and calls quoteNative.
|
|
12741
|
+
*/
|
|
12742
|
+
async quoteCancelNative(order) {
|
|
12743
|
+
const orderWithCommitment = transformOrder(order);
|
|
12744
|
+
const height = orderWithCommitment.deadline + 1n;
|
|
12745
|
+
const destIntentGateway = this.dest.configService.getIntentGatewayAddress(orderWithCommitment.destChain);
|
|
12746
|
+
const slotHash = await this.dest.client.readContract({
|
|
12747
|
+
abi: IntentGateway_default.ABI,
|
|
12748
|
+
address: destIntentGateway,
|
|
12749
|
+
functionName: "calculateCommitmentSlotHash",
|
|
12750
|
+
args: [orderWithCommitment.id]
|
|
12751
|
+
});
|
|
12752
|
+
const key = concatHex([destIntentGateway, slotHash]);
|
|
12753
|
+
const context = encodeAbiParameters(
|
|
12754
|
+
[
|
|
12755
|
+
{
|
|
12756
|
+
name: "requestBody",
|
|
12757
|
+
type: "tuple",
|
|
12758
|
+
components: [
|
|
12759
|
+
{ name: "commitment", type: "bytes32" },
|
|
12760
|
+
{ name: "beneficiary", type: "bytes32" },
|
|
12761
|
+
{
|
|
12762
|
+
name: "tokens",
|
|
12763
|
+
type: "tuple[]",
|
|
12764
|
+
components: [
|
|
12765
|
+
{ name: "token", type: "bytes32" },
|
|
12766
|
+
{ name: "amount", type: "uint256" }
|
|
12767
|
+
]
|
|
12768
|
+
}
|
|
12769
|
+
]
|
|
12770
|
+
}
|
|
12771
|
+
],
|
|
12772
|
+
[
|
|
12773
|
+
{
|
|
12774
|
+
commitment: orderWithCommitment.id,
|
|
12775
|
+
beneficiary: orderWithCommitment.user,
|
|
12776
|
+
tokens: orderWithCommitment.inputs
|
|
12777
|
+
}
|
|
12778
|
+
]
|
|
12779
|
+
);
|
|
12780
|
+
const getRequest = {
|
|
12781
|
+
source: orderWithCommitment.sourceChain,
|
|
12782
|
+
dest: orderWithCommitment.destChain,
|
|
12783
|
+
from: this.source.configService.getIntentGatewayAddress(orderWithCommitment.destChain),
|
|
12784
|
+
nonce: await this.source.getHostNonce(),
|
|
12785
|
+
height,
|
|
12786
|
+
keys: [key],
|
|
12787
|
+
timeoutTimestamp: 0n,
|
|
12788
|
+
context
|
|
12789
|
+
};
|
|
12790
|
+
return await this.source.quoteNative(getRequest, 0n);
|
|
12791
|
+
}
|
|
12736
12792
|
/**
|
|
12737
12793
|
* Cancels an order through the cross-chain protocol by generating and submitting proofs.
|
|
12738
12794
|
* This is an async generator function that yields status updates throughout the cancellation process.
|
|
@@ -13067,7 +13123,7 @@ var MultiAccount = Struct({
|
|
|
13067
13123
|
});
|
|
13068
13124
|
var DECIMALS = 10;
|
|
13069
13125
|
async function teleportDot(param_) {
|
|
13070
|
-
const { sourceApi,
|
|
13126
|
+
const { sourceApi, who, options, xcmGatewayParams: params } = param_;
|
|
13071
13127
|
const { nonce: accountNonce } = await sourceApi.query.system.account(who);
|
|
13072
13128
|
const encoded_message = MultiAccount.enc({
|
|
13073
13129
|
substrate_account: decodeAddress(who),
|
|
@@ -13078,7 +13134,7 @@ async function teleportDot(param_) {
|
|
|
13078
13134
|
});
|
|
13079
13135
|
const message_id = keccakAsHex(encoded_message);
|
|
13080
13136
|
const beneficiary = {
|
|
13081
|
-
|
|
13137
|
+
V4: {
|
|
13082
13138
|
parents: 0,
|
|
13083
13139
|
interior: {
|
|
13084
13140
|
X4: [
|
|
@@ -13108,81 +13164,58 @@ async function teleportDot(param_) {
|
|
|
13108
13164
|
}
|
|
13109
13165
|
}
|
|
13110
13166
|
};
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
parents: 1,
|
|
13117
|
-
interior: {
|
|
13118
|
-
X1: {
|
|
13119
|
-
Parachain: params.paraId
|
|
13120
|
-
}
|
|
13121
|
-
}
|
|
13167
|
+
const destination = {
|
|
13168
|
+
V4: {
|
|
13169
|
+
parents: 1,
|
|
13170
|
+
interior: {
|
|
13171
|
+
X1: [{ Parachain: params.paraId }]
|
|
13122
13172
|
}
|
|
13123
|
-
}
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13135
|
-
}
|
|
13136
|
-
}
|
|
13137
|
-
]
|
|
13138
|
-
};
|
|
13139
|
-
} else {
|
|
13140
|
-
destination = {
|
|
13141
|
-
V3: {
|
|
13142
|
-
parents: 0,
|
|
13143
|
-
interior: {
|
|
13144
|
-
X1: {
|
|
13145
|
-
Parachain: params.paraId
|
|
13146
|
-
}
|
|
13173
|
+
}
|
|
13174
|
+
};
|
|
13175
|
+
const assets2 = {
|
|
13176
|
+
V4: [
|
|
13177
|
+
{
|
|
13178
|
+
id: {
|
|
13179
|
+
parents: 1,
|
|
13180
|
+
interior: "Here"
|
|
13181
|
+
},
|
|
13182
|
+
fun: {
|
|
13183
|
+
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13147
13184
|
}
|
|
13148
13185
|
}
|
|
13149
|
-
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13186
|
+
]
|
|
13187
|
+
};
|
|
13188
|
+
const weightLimit = "Unlimited";
|
|
13189
|
+
const feeAssetId = {
|
|
13190
|
+
V4: assets2.V4[0].id
|
|
13191
|
+
};
|
|
13192
|
+
const customXcmOnDest = {
|
|
13193
|
+
V4: [
|
|
13194
|
+
{
|
|
13195
|
+
DepositAsset: {
|
|
13196
|
+
assets: {
|
|
13197
|
+
Wild: {
|
|
13198
|
+
AllCounted: 1
|
|
13157
13199
|
}
|
|
13158
13200
|
},
|
|
13159
|
-
|
|
13160
|
-
Fungible: parseUnits(params.amount.toString(), DECIMALS)
|
|
13161
|
-
}
|
|
13201
|
+
beneficiary: beneficiary.V4
|
|
13162
13202
|
}
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
}
|
|
13166
|
-
const
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
destination,
|
|
13180
|
-
beneficiary,
|
|
13181
|
-
assets2,
|
|
13182
|
-
feeAssetItem,
|
|
13183
|
-
weightLimit
|
|
13184
|
-
);
|
|
13185
|
-
}
|
|
13203
|
+
}
|
|
13204
|
+
]
|
|
13205
|
+
};
|
|
13206
|
+
const tx = sourceApi.tx.polkadotXcm.transferAssetsUsingTypeAndThen(
|
|
13207
|
+
destination,
|
|
13208
|
+
assets2,
|
|
13209
|
+
{ LocalReserve: null },
|
|
13210
|
+
// Assets transfer type
|
|
13211
|
+
feeAssetId,
|
|
13212
|
+
// Fee asset ID wrapped as VersionedAssetId
|
|
13213
|
+
{ LocalReserve: null },
|
|
13214
|
+
// Remote fee transfer type
|
|
13215
|
+
customXcmOnDest,
|
|
13216
|
+
// XCM instruction with DepositAsset containing custom beneficiary
|
|
13217
|
+
weightLimit
|
|
13218
|
+
);
|
|
13186
13219
|
let closed = false;
|
|
13187
13220
|
let unsubscribe;
|
|
13188
13221
|
const stream = new ReadableStream(
|