@lit-protocol/vincent-ability-hyperliquid 3.0.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/CHANGELOG.md +21 -0
- package/CONTRIBUTING.md +5 -0
- package/README.md +922 -0
- package/dist/CHANGELOG.md +21 -0
- package/dist/CONTRIBUTING.md +5 -0
- package/dist/README.md +922 -0
- package/dist/package.json +35 -0
- package/dist/src/generated/lit-action.js +9 -0
- package/dist/src/generated/vincent-ability-metadata.json +3 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts +483 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.js +15 -0
- package/dist/src/generated/vincent-bundled-ability.js.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.ts +13 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +14 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/ability-checks/cancel.d.ts +41 -0
- package/dist/src/lib/ability-checks/cancel.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/cancel.js +58 -0
- package/dist/src/lib/ability-checks/cancel.js.map +1 -0
- package/dist/src/lib/ability-checks/deposit-usdc.d.ts +18 -0
- package/dist/src/lib/ability-checks/deposit-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/deposit-usdc.js +40 -0
- package/dist/src/lib/ability-checks/deposit-usdc.js.map +1 -0
- package/dist/src/lib/ability-checks/hyperliquid-account-exists.d.ts +6 -0
- package/dist/src/lib/ability-checks/hyperliquid-account-exists.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/hyperliquid-account-exists.js +22 -0
- package/dist/src/lib/ability-checks/hyperliquid-account-exists.js.map +1 -0
- package/dist/src/lib/ability-checks/index.d.ts +11 -0
- package/dist/src/lib/ability-checks/index.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/index.js +25 -0
- package/dist/src/lib/ability-checks/index.js.map +1 -0
- package/dist/src/lib/ability-checks/is-builder-code-approved.d.ts +14 -0
- package/dist/src/lib/ability-checks/is-builder-code-approved.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/is-builder-code-approved.js +29 -0
- package/dist/src/lib/ability-checks/is-builder-code-approved.js.map +1 -0
- package/dist/src/lib/ability-checks/perp.d.ts +23 -0
- package/dist/src/lib/ability-checks/perp.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/perp.js +47 -0
- package/dist/src/lib/ability-checks/perp.js.map +1 -0
- package/dist/src/lib/ability-checks/send-perp-usdc.d.ts +26 -0
- package/dist/src/lib/ability-checks/send-perp-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/send-perp-usdc.js +38 -0
- package/dist/src/lib/ability-checks/send-perp-usdc.js.map +1 -0
- package/dist/src/lib/ability-checks/send-spot-asset.d.ts +27 -0
- package/dist/src/lib/ability-checks/send-spot-asset.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/send-spot-asset.js +59 -0
- package/dist/src/lib/ability-checks/send-spot-asset.js.map +1 -0
- package/dist/src/lib/ability-checks/spot.d.ts +24 -0
- package/dist/src/lib/ability-checks/spot.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/spot.js +98 -0
- package/dist/src/lib/ability-checks/spot.js.map +1 -0
- package/dist/src/lib/ability-checks/transfer-usdc.d.ts +26 -0
- package/dist/src/lib/ability-checks/transfer-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/transfer-usdc.js +64 -0
- package/dist/src/lib/ability-checks/transfer-usdc.js.map +1 -0
- package/dist/src/lib/ability-checks/withdraw-usdc.d.ts +25 -0
- package/dist/src/lib/ability-checks/withdraw-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/withdraw-usdc.js +39 -0
- package/dist/src/lib/ability-checks/withdraw-usdc.js.map +1 -0
- package/dist/src/lib/ability-helpers/approve-builder-code.d.ts +22 -0
- package/dist/src/lib/ability-helpers/approve-builder-code.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/approve-builder-code.js +53 -0
- package/dist/src/lib/ability-helpers/approve-builder-code.js.map +1 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-all-orders.d.ts +21 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-all-orders.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-all-orders.js +69 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-all-orders.js.map +1 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-order.d.ts +25 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-order.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-order.js +63 -0
- package/dist/src/lib/ability-helpers/cancel-order/cancel-order.js.map +1 -0
- package/dist/src/lib/ability-helpers/execute-perp-order.d.ts +65 -0
- package/dist/src/lib/ability-helpers/execute-perp-order.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/execute-perp-order.js +110 -0
- package/dist/src/lib/ability-helpers/execute-perp-order.js.map +1 -0
- package/dist/src/lib/ability-helpers/execute-spot-order.d.ts +50 -0
- package/dist/src/lib/ability-helpers/execute-spot-order.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/execute-spot-order.js +84 -0
- package/dist/src/lib/ability-helpers/execute-spot-order.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-chain-id.d.ts +3 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-chain-id.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-chain-id.js +15 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-chain-id.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-nonce.d.ts +2 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-nonce.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-nonce.js +10 -0
- package/dist/src/lib/ability-helpers/get-hyperliquid-nonce.js.map +1 -0
- package/dist/src/lib/ability-helpers/index.d.ts +12 -0
- package/dist/src/lib/ability-helpers/index.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/index.js +26 -0
- package/dist/src/lib/ability-helpers/index.js.map +1 -0
- package/dist/src/lib/ability-helpers/lit-action-pkp-ethers-wallet.d.ts +74 -0
- package/dist/src/lib/ability-helpers/lit-action-pkp-ethers-wallet.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/lit-action-pkp-ethers-wallet.js +192 -0
- package/dist/src/lib/ability-helpers/lit-action-pkp-ethers-wallet.js.map +1 -0
- package/dist/src/lib/ability-helpers/send-deposit-tx.d.ts +15 -0
- package/dist/src/lib/ability-helpers/send-deposit-tx.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/send-deposit-tx.js +82 -0
- package/dist/src/lib/ability-helpers/send-deposit-tx.js.map +1 -0
- package/dist/src/lib/ability-helpers/send-perp-usdc.d.ts +16 -0
- package/dist/src/lib/ability-helpers/send-perp-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/send-perp-usdc.js +49 -0
- package/dist/src/lib/ability-helpers/send-perp-usdc.js.map +1 -0
- package/dist/src/lib/ability-helpers/send-spot-asset.d.ts +17 -0
- package/dist/src/lib/ability-helpers/send-spot-asset.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/send-spot-asset.js +61 -0
- package/dist/src/lib/ability-helpers/send-spot-asset.js.map +1 -0
- package/dist/src/lib/ability-helpers/sign-tx.d.ts +3 -0
- package/dist/src/lib/ability-helpers/sign-tx.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/sign-tx.js +28 -0
- package/dist/src/lib/ability-helpers/sign-tx.js.map +1 -0
- package/dist/src/lib/ability-helpers/transfer-usdc-to.d.ts +16 -0
- package/dist/src/lib/ability-helpers/transfer-usdc-to.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/transfer-usdc-to.js +50 -0
- package/dist/src/lib/ability-helpers/transfer-usdc-to.js.map +1 -0
- package/dist/src/lib/ability-helpers/withdraw-usdc.d.ts +16 -0
- package/dist/src/lib/ability-helpers/withdraw-usdc.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/withdraw-usdc.js +49 -0
- package/dist/src/lib/ability-helpers/withdraw-usdc.js.map +1 -0
- package/dist/src/lib/constants.d.ts +3 -0
- package/dist/src/lib/constants.d.ts.map +1 -0
- package/dist/src/lib/constants.js +6 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/lit-action.d.ts +2 -0
- package/dist/src/lib/lit-action.d.ts.map +1 -0
- package/dist/src/lib/lit-action.js +16 -0
- package/dist/src/lib/lit-action.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +687 -0
- package/dist/src/lib/schemas.d.ts.map +1 -0
- package/dist/src/lib/schemas.js +233 -0
- package/dist/src/lib/schemas.js.map +1 -0
- package/dist/src/lib/types.d.ts +39 -0
- package/dist/src/lib/types.d.ts.map +1 -0
- package/dist/src/lib/types.js +45 -0
- package/dist/src/lib/types.js.map +1 -0
- package/dist/src/lib/vincent-ability.d.ts +480 -0
- package/dist/src/lib/vincent-ability.d.ts.map +1 -0
- package/dist/src/lib/vincent-ability.js +595 -0
- package/dist/src/lib/vincent-ability.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as hyperliquid from '@nktkas/hyperliquid';
|
|
2
|
+
import { OrderResponse } from '@nktkas/hyperliquid/api/exchange';
|
|
3
|
+
export type TimeInForce = 'Gtc' | 'Ioc' | 'Alo';
|
|
4
|
+
export interface SpotTradeParams {
|
|
5
|
+
symbol: string;
|
|
6
|
+
price: string;
|
|
7
|
+
size: string;
|
|
8
|
+
isBuy: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Order type configuration.
|
|
11
|
+
* - For limit orders: specify { type: 'limit', tif: 'Gtc' | 'Ioc' | 'Alo' }
|
|
12
|
+
* - For market orders: specify { type: 'market' }
|
|
13
|
+
* @default { type: 'limit', tif: 'Gtc' }
|
|
14
|
+
*/
|
|
15
|
+
orderType?: {
|
|
16
|
+
type: 'limit';
|
|
17
|
+
tif: TimeInForce;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'market';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Builder fee configuration.
|
|
23
|
+
* Only applies to sell orders (builder codes do not apply to buying side of spot trades).
|
|
24
|
+
* Fee is specified in tenths of basis points (e.g., 50 = 0.05% = 5 basis points).
|
|
25
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#builder-codes
|
|
26
|
+
*/
|
|
27
|
+
builderFee?: {
|
|
28
|
+
builderAddress: string;
|
|
29
|
+
feeInTenthsOfBps: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type SpotOrderResult = SpotOrderResultSuccess | SpotOrderResultFailure;
|
|
33
|
+
export interface SpotOrderResultSuccess {
|
|
34
|
+
status: 'success';
|
|
35
|
+
orderResult: OrderResponse;
|
|
36
|
+
}
|
|
37
|
+
export interface SpotOrderResultFailure {
|
|
38
|
+
status: 'error';
|
|
39
|
+
error: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Execute a spot trade on Hyperliquid
|
|
43
|
+
*/
|
|
44
|
+
export declare function executeSpotOrder({ transport, pkpPublicKey, params, useTestnet, }: {
|
|
45
|
+
transport: hyperliquid.HttpTransport;
|
|
46
|
+
pkpPublicKey: string;
|
|
47
|
+
params: SpotTradeParams;
|
|
48
|
+
useTestnet?: boolean;
|
|
49
|
+
}): Promise<SpotOrderResult>;
|
|
50
|
+
//# sourceMappingURL=execute-spot-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-spot-order.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/execute-spot-order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAgB,aAAa,EAAU,MAAM,kCAAkC,CAAC;AAOvF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,WAAW,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC;IACrE;;;;;OAKG;IACH,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAED,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,sBAAsB,CAAC;AAE9E,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,aAAa,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,UAAkB,GACnB,EAAE;IACD,SAAS,EAAE,WAAW,CAAC,aAAa,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,CA0G3B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeSpotOrder = executeSpotOrder;
|
|
4
|
+
const utils_1 = require("@nktkas/hyperliquid/utils");
|
|
5
|
+
const exchange_1 = require("@nktkas/hyperliquid/api/exchange");
|
|
6
|
+
const signing_1 = require("@nktkas/hyperliquid/signing");
|
|
7
|
+
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
8
|
+
const lit_action_pkp_ethers_wallet_1 = require("./lit-action-pkp-ethers-wallet");
|
|
9
|
+
const get_hyperliquid_nonce_1 = require("./get-hyperliquid-nonce");
|
|
10
|
+
/**
|
|
11
|
+
* Execute a spot trade on Hyperliquid
|
|
12
|
+
*/
|
|
13
|
+
async function executeSpotOrder({ transport, pkpPublicKey, params, useTestnet = false, }) {
|
|
14
|
+
// Get converter for symbol to asset ID
|
|
15
|
+
const converter = await utils_1.SymbolConverter.create({ transport });
|
|
16
|
+
const assetId = converter.getAssetId(params.symbol);
|
|
17
|
+
if (assetId === undefined) {
|
|
18
|
+
throw new Error(`Failed to get asset ID for ${params.symbol}. The trading pair may not exist.`);
|
|
19
|
+
}
|
|
20
|
+
// Create PKP wallet
|
|
21
|
+
const pkpWallet = new lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet(pkpPublicKey);
|
|
22
|
+
const nonce = await (0, get_hyperliquid_nonce_1.getHyperliquidNonce)();
|
|
23
|
+
// Determine order type configuration
|
|
24
|
+
const orderType = params.orderType || { type: 'limit', tif: 'Gtc' };
|
|
25
|
+
// Construct order type field based on orderType
|
|
26
|
+
const orderTypeField = orderType.type === 'market'
|
|
27
|
+
? { limit: { tif: 'FrontendMarket' } }
|
|
28
|
+
: { limit: { tif: orderType.tif } };
|
|
29
|
+
// Construct order action
|
|
30
|
+
// Note: Builder codes only apply to sell orders (not buy orders) for spot trades
|
|
31
|
+
const orderActionParams = {
|
|
32
|
+
type: 'order',
|
|
33
|
+
orders: [
|
|
34
|
+
{
|
|
35
|
+
a: assetId,
|
|
36
|
+
b: params.isBuy, // true for buy, false for sell
|
|
37
|
+
p: params.price,
|
|
38
|
+
s: params.size,
|
|
39
|
+
r: false, // reduce only (false for spot)
|
|
40
|
+
t: orderTypeField,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
grouping: 'na',
|
|
44
|
+
};
|
|
45
|
+
// Add builder fee if provided and this is a sell order
|
|
46
|
+
// Builder codes do not apply to the buying side of spot trades
|
|
47
|
+
if (params.builderFee && !params.isBuy) {
|
|
48
|
+
orderActionParams.builder = {
|
|
49
|
+
b: params.builderFee.builderAddress,
|
|
50
|
+
f: params.builderFee.feeInTenthsOfBps,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const orderAction = (0, exchange_1.parser)(exchange_1.OrderRequest.entries.action)(orderActionParams);
|
|
54
|
+
// Sign and send
|
|
55
|
+
const signature = await (0, signing_1.signL1Action)({
|
|
56
|
+
wallet: pkpWallet,
|
|
57
|
+
action: orderAction,
|
|
58
|
+
nonce,
|
|
59
|
+
isTestnet: useTestnet,
|
|
60
|
+
});
|
|
61
|
+
const orderResult = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidSpotOrderRequest' }, async () => {
|
|
62
|
+
return JSON.stringify({
|
|
63
|
+
result: await transport.request('exchange', {
|
|
64
|
+
action: orderAction,
|
|
65
|
+
signature,
|
|
66
|
+
nonce,
|
|
67
|
+
}),
|
|
68
|
+
}, vincent_ability_sdk_1.bigIntReplacer, 2);
|
|
69
|
+
});
|
|
70
|
+
const parsedOrderResult = JSON.parse(orderResult);
|
|
71
|
+
console.log('[executeSpotTrade] Order result', parsedOrderResult);
|
|
72
|
+
const spotOrderStatus = parsedOrderResult.result.response.data.statuses[0];
|
|
73
|
+
if (spotOrderStatus.error !== undefined) {
|
|
74
|
+
return {
|
|
75
|
+
status: 'error',
|
|
76
|
+
error: spotOrderStatus.error,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
status: 'success',
|
|
81
|
+
orderResult: parsedOrderResult.result,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=execute-spot-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-spot-order.js","sourceRoot":"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AC;IAElE,MAAM,eAAe,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE3E,IAAI,eAAe,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO;YACL,MAAM,EAAE,OAAO;YACf,KAAK,EAAE,eAAe,CAAC,KAAK;SAC7B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE,iBAAiB,CAAC,MAAuB;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hyperliquid-chain-id.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-hyperliquid-chain-id.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAAI,YAAY,OAAO,KAAG,MAK3D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,YAAY,OAAO,KAAG,MAE7D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHyperliquidChainName = exports.getHyperliquidChainId = void 0;
|
|
4
|
+
const getHyperliquidChainId = (useTestnet) => {
|
|
5
|
+
// Select chain ID and network based on testnet flag
|
|
6
|
+
return useTestnet
|
|
7
|
+
? '0x66eee' // Arbitrum Sepolia testnet chain ID: 421614
|
|
8
|
+
: '0xa4b1'; // Arbitrum mainnet chain ID: 42161
|
|
9
|
+
};
|
|
10
|
+
exports.getHyperliquidChainId = getHyperliquidChainId;
|
|
11
|
+
const getHyperliquidChainName = (useTestnet) => {
|
|
12
|
+
return useTestnet ? 'Testnet' : 'Mainnet';
|
|
13
|
+
};
|
|
14
|
+
exports.getHyperliquidChainName = getHyperliquidChainName;
|
|
15
|
+
//# sourceMappingURL=get-hyperliquid-chain-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hyperliquid-chain-id.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-hyperliquid-chain-id.ts"],"names":[],"mappings":";;;AAAO,MAAM,qBAAqB,GAAG,CAAC,UAAmB,EAAU,EAAE;IACnE,oDAAoD;IACpD,OAAO,UAAU;QACf,CAAC,CAAC,SAAS,CAAC,4CAA4C;QACxD,CAAC,CAAC,QAAQ,CAAC,CAAC,mCAAmC;AACnD,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC;AAEK,MAAM,uBAAuB,GAAG,CAAC,UAAmB,EAAU,EAAE;IACrE,OAAO,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5C,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hyperliquid-nonce.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-hyperliquid-nonce.ts"],"names":[],"mappings":"AAAA,wBAAsB,mBAAmB,oBAQxC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHyperliquidNonce = getHyperliquidNonce;
|
|
4
|
+
async function getHyperliquidNonce() {
|
|
5
|
+
const nonceResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidWithdrawNonce' }, async () => {
|
|
6
|
+
return Date.now().toString();
|
|
7
|
+
});
|
|
8
|
+
return parseInt(nonceResponse);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get-hyperliquid-nonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hyperliquid-nonce.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-hyperliquid-nonce.ts"],"names":[],"mappings":";;AAAA,kDAQC;AARM,KAAK,UAAU,mBAAmB;IACvC,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAC7C,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,0BAA0B,EAAE,EAC3D,KAAK,IAAI,EAAE;QACT,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { LitActionPkpEthersWallet } from './lit-action-pkp-ethers-wallet';
|
|
2
|
+
export { cancelOrder } from './cancel-order/cancel-order';
|
|
3
|
+
export { cancelAllOrdersForSymbol } from './cancel-order/cancel-all-orders';
|
|
4
|
+
export { sendDepositTx } from './send-deposit-tx';
|
|
5
|
+
export { transferUsdcTo } from './transfer-usdc-to';
|
|
6
|
+
export { executeSpotOrder } from './execute-spot-order';
|
|
7
|
+
export { executePerpOrder } from './execute-perp-order';
|
|
8
|
+
export { withdrawUsdc } from './withdraw-usdc';
|
|
9
|
+
export { sendSpotAsset } from './send-spot-asset';
|
|
10
|
+
export { sendPerpUsdc } from './send-perp-usdc';
|
|
11
|
+
export { approveBuilderCode } from './approve-builder-code';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.approveBuilderCode = exports.sendPerpUsdc = exports.sendSpotAsset = exports.withdrawUsdc = exports.executePerpOrder = exports.executeSpotOrder = exports.transferUsdcTo = exports.sendDepositTx = exports.cancelAllOrdersForSymbol = exports.cancelOrder = exports.LitActionPkpEthersWallet = void 0;
|
|
4
|
+
var lit_action_pkp_ethers_wallet_1 = require("./lit-action-pkp-ethers-wallet");
|
|
5
|
+
Object.defineProperty(exports, "LitActionPkpEthersWallet", { enumerable: true, get: function () { return lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet; } });
|
|
6
|
+
var cancel_order_1 = require("./cancel-order/cancel-order");
|
|
7
|
+
Object.defineProperty(exports, "cancelOrder", { enumerable: true, get: function () { return cancel_order_1.cancelOrder; } });
|
|
8
|
+
var cancel_all_orders_1 = require("./cancel-order/cancel-all-orders");
|
|
9
|
+
Object.defineProperty(exports, "cancelAllOrdersForSymbol", { enumerable: true, get: function () { return cancel_all_orders_1.cancelAllOrdersForSymbol; } });
|
|
10
|
+
var send_deposit_tx_1 = require("./send-deposit-tx");
|
|
11
|
+
Object.defineProperty(exports, "sendDepositTx", { enumerable: true, get: function () { return send_deposit_tx_1.sendDepositTx; } });
|
|
12
|
+
var transfer_usdc_to_1 = require("./transfer-usdc-to");
|
|
13
|
+
Object.defineProperty(exports, "transferUsdcTo", { enumerable: true, get: function () { return transfer_usdc_to_1.transferUsdcTo; } });
|
|
14
|
+
var execute_spot_order_1 = require("./execute-spot-order");
|
|
15
|
+
Object.defineProperty(exports, "executeSpotOrder", { enumerable: true, get: function () { return execute_spot_order_1.executeSpotOrder; } });
|
|
16
|
+
var execute_perp_order_1 = require("./execute-perp-order");
|
|
17
|
+
Object.defineProperty(exports, "executePerpOrder", { enumerable: true, get: function () { return execute_perp_order_1.executePerpOrder; } });
|
|
18
|
+
var withdraw_usdc_1 = require("./withdraw-usdc");
|
|
19
|
+
Object.defineProperty(exports, "withdrawUsdc", { enumerable: true, get: function () { return withdraw_usdc_1.withdrawUsdc; } });
|
|
20
|
+
var send_spot_asset_1 = require("./send-spot-asset");
|
|
21
|
+
Object.defineProperty(exports, "sendSpotAsset", { enumerable: true, get: function () { return send_spot_asset_1.sendSpotAsset; } });
|
|
22
|
+
var send_perp_usdc_1 = require("./send-perp-usdc");
|
|
23
|
+
Object.defineProperty(exports, "sendPerpUsdc", { enumerable: true, get: function () { return send_perp_usdc_1.sendPerpUsdc; } });
|
|
24
|
+
var approve_builder_code_1 = require("./approve-builder-code");
|
|
25
|
+
Object.defineProperty(exports, "approveBuilderCode", { enumerable: true, get: function () { return approve_builder_code_1.approveBuilderCode; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAAjE,wIAAA,wBAAwB,OAAA;AACjC,4DAA0D;AAAjD,2GAAA,WAAW,OAAA;AACpB,sEAA4E;AAAnE,6HAAA,wBAAwB,OAAA;AACjC,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,uDAAoD;AAA3C,kHAAA,cAAc,OAAA;AACvB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,mDAAgD;AAAvC,8GAAA,YAAY,OAAA;AACrB,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AbstractEthersV5Signer } from '@nktkas/hyperliquid/signing';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
/**
|
|
4
|
+
* LitActionPkpEthersWallet - An ethers-compatible wallet implementation for use within Lit Actions
|
|
5
|
+
*
|
|
6
|
+
* This class provides an ethers.js Signer-compatible interface that uses Lit's PKP signing
|
|
7
|
+
* capabilities within a Lit Action execution environment. Unlike PKPEthersWallet which is
|
|
8
|
+
* designed to run outside Lit Actions and uses the Lit SDK to make signing requests,
|
|
9
|
+
* this wallet runs INSIDE a Lit Action and directly calls Lit.Actions.signAndCombineEcdsa.
|
|
10
|
+
*
|
|
11
|
+
* Key differences from PKPEthersWallet:
|
|
12
|
+
* - No provider/RPC logic (runs in Lit Action sandbox)
|
|
13
|
+
* - Direct use of Lit.Actions.signAndCombineEcdsa instead of SDK methods
|
|
14
|
+
* - Simplified constructor (just takes PKP public key)
|
|
15
|
+
* - No transaction population (gas estimation, nonce, etc.)
|
|
16
|
+
*
|
|
17
|
+
* Supports:
|
|
18
|
+
* - signMessage: Sign arbitrary messages (EIP-191)
|
|
19
|
+
* - _signTypedData: Sign EIP-712 typed data
|
|
20
|
+
* - signTransaction: Sign raw Ethereum transactions
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const wallet = new LitActionPkpEthersWallet({
|
|
25
|
+
* pkpPublicKey: '0x04...',
|
|
26
|
+
* sigName: 'my-signature'
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Sign a message
|
|
30
|
+
* const signature = await wallet.signMessage('Hello World');
|
|
31
|
+
*
|
|
32
|
+
* // Sign typed data (EIP-712)
|
|
33
|
+
* const typedSignature = await wallet._signTypedData(domain, types, value);
|
|
34
|
+
*
|
|
35
|
+
* // Sign a transaction
|
|
36
|
+
* const signedTx = await wallet.signTransaction(transaction);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class LitActionPkpEthersWallet implements AbstractEthersV5Signer {
|
|
40
|
+
private readonly pkpPublicKey;
|
|
41
|
+
private readonly sigName;
|
|
42
|
+
readonly address: string;
|
|
43
|
+
constructor(pkpPublicKey: string, sigName?: string);
|
|
44
|
+
/**
|
|
45
|
+
* Sign a message using EIP-191 personal_sign format
|
|
46
|
+
*/
|
|
47
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Get the wallet address (required by AbstractEthersV5Signer)
|
|
50
|
+
*/
|
|
51
|
+
getAddress(): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Sign typed data using EIP-712 (required by AbstractEthersV5Signer)
|
|
54
|
+
* Note: Ethers v5 uses _signTypedData (with underscore)
|
|
55
|
+
*/
|
|
56
|
+
_signTypedData(domain: {
|
|
57
|
+
name: string;
|
|
58
|
+
version: string;
|
|
59
|
+
chainId: number;
|
|
60
|
+
verifyingContract: string;
|
|
61
|
+
}, types: {
|
|
62
|
+
[key: string]: {
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
}[];
|
|
66
|
+
}, value: Record<string, unknown>): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Sign a transaction
|
|
69
|
+
* Note: Transaction must be pre-populated with all fields (gasLimit, nonce, chainId, etc.)
|
|
70
|
+
* as we don't have RPC access in Lit Actions
|
|
71
|
+
*/
|
|
72
|
+
signTransaction(transaction: ethers.providers.TransactionRequest): Promise<string>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=lit-action-pkp-ethers-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-action-pkp-ethers-wallet.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/lit-action-pkp-ethers-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,wBAAyB,YAAW,sBAAsB;IACrE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAEpB,YAAY,EAAE,MAAM,EAAE,OAAO,SAAyB;IAclE;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBhE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;OAGG;IACG,cAAc,CAClB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,EACD,KAAK,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;SACd,EAAE,CAAC;KACL,EACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,MAAM,CAAC;IA8BlB;;;;OAIG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;CAqBzF"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LitActionPkpEthersWallet = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
/**
|
|
6
|
+
* LitActionPkpEthersWallet - An ethers-compatible wallet implementation for use within Lit Actions
|
|
7
|
+
*
|
|
8
|
+
* This class provides an ethers.js Signer-compatible interface that uses Lit's PKP signing
|
|
9
|
+
* capabilities within a Lit Action execution environment. Unlike PKPEthersWallet which is
|
|
10
|
+
* designed to run outside Lit Actions and uses the Lit SDK to make signing requests,
|
|
11
|
+
* this wallet runs INSIDE a Lit Action and directly calls Lit.Actions.signAndCombineEcdsa.
|
|
12
|
+
*
|
|
13
|
+
* Key differences from PKPEthersWallet:
|
|
14
|
+
* - No provider/RPC logic (runs in Lit Action sandbox)
|
|
15
|
+
* - Direct use of Lit.Actions.signAndCombineEcdsa instead of SDK methods
|
|
16
|
+
* - Simplified constructor (just takes PKP public key)
|
|
17
|
+
* - No transaction population (gas estimation, nonce, etc.)
|
|
18
|
+
*
|
|
19
|
+
* Supports:
|
|
20
|
+
* - signMessage: Sign arbitrary messages (EIP-191)
|
|
21
|
+
* - _signTypedData: Sign EIP-712 typed data
|
|
22
|
+
* - signTransaction: Sign raw Ethereum transactions
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const wallet = new LitActionPkpEthersWallet({
|
|
27
|
+
* pkpPublicKey: '0x04...',
|
|
28
|
+
* sigName: 'my-signature'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Sign a message
|
|
32
|
+
* const signature = await wallet.signMessage('Hello World');
|
|
33
|
+
*
|
|
34
|
+
* // Sign typed data (EIP-712)
|
|
35
|
+
* const typedSignature = await wallet._signTypedData(domain, types, value);
|
|
36
|
+
*
|
|
37
|
+
* // Sign a transaction
|
|
38
|
+
* const signedTx = await wallet.signTransaction(transaction);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class LitActionPkpEthersWallet {
|
|
42
|
+
pkpPublicKey;
|
|
43
|
+
sigName;
|
|
44
|
+
address;
|
|
45
|
+
constructor(pkpPublicKey, sigName = 'pkp-ethers-signature') {
|
|
46
|
+
const cleanedKey = pkpPublicKey.replace(/^0x/i, '');
|
|
47
|
+
if (!/^[0-9a-fA-F]{130}$/.test(cleanedKey)) {
|
|
48
|
+
throw new Error(`Invalid PKP public key format: expected 130 hex characters (uncompressed), got ${cleanedKey.length} chars`);
|
|
49
|
+
}
|
|
50
|
+
this.pkpPublicKey = cleanedKey.toLowerCase();
|
|
51
|
+
this.sigName = sigName;
|
|
52
|
+
this.address = ethers_1.ethers.utils.computeAddress('0x' + this.pkpPublicKey);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sign a message using EIP-191 personal_sign format
|
|
56
|
+
*/
|
|
57
|
+
async signMessage(message) {
|
|
58
|
+
// Use ethers' hashMessage which handles EIP-191 formatting
|
|
59
|
+
const messageHash = ethers_1.ethers.utils.hashMessage(message);
|
|
60
|
+
const toSign = ethers_1.ethers.utils.arrayify(messageHash);
|
|
61
|
+
const signatureResponse = await Lit.Actions.signAndCombineEcdsa({
|
|
62
|
+
toSign,
|
|
63
|
+
publicKey: this.pkpPublicKey,
|
|
64
|
+
sigName: this.sigName,
|
|
65
|
+
});
|
|
66
|
+
const parsedSig = JSON.parse(signatureResponse);
|
|
67
|
+
return ethers_1.ethers.utils.joinSignature({
|
|
68
|
+
r: normalizeSignatureComponent(parsedSig.r),
|
|
69
|
+
s: normalizeSignatureComponent(parsedSig.s),
|
|
70
|
+
v: parsedSig.v,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the wallet address (required by AbstractEthersV5Signer)
|
|
75
|
+
*/
|
|
76
|
+
async getAddress() {
|
|
77
|
+
return this.address;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sign typed data using EIP-712 (required by AbstractEthersV5Signer)
|
|
81
|
+
* Note: Ethers v5 uses _signTypedData (with underscore)
|
|
82
|
+
*/
|
|
83
|
+
async _signTypedData(domain, types, value) {
|
|
84
|
+
if (!domain?.verifyingContract || !types || !value) {
|
|
85
|
+
throw new Error('Invalid typed data parameters');
|
|
86
|
+
}
|
|
87
|
+
// Normalize value for deterministic serialization
|
|
88
|
+
const normalizedValue = normalizeTypedDataValue(value, types);
|
|
89
|
+
// Create EIP-712 hash
|
|
90
|
+
const hash = ethers_1.ethers.utils._TypedDataEncoder.hash(domain, types, normalizedValue);
|
|
91
|
+
const toSignBytes = ethers_1.ethers.utils.arrayify(hash);
|
|
92
|
+
const signatureResponse = await Lit.Actions.signAndCombineEcdsa({
|
|
93
|
+
toSign: toSignBytes,
|
|
94
|
+
publicKey: this.pkpPublicKey,
|
|
95
|
+
sigName: this.sigName,
|
|
96
|
+
});
|
|
97
|
+
const parsedSig = JSON.parse(signatureResponse);
|
|
98
|
+
// Convert v from recovery id (0 or 1) to Ethereum format (27 or 28)
|
|
99
|
+
const vEthereum = parsedSig.v === 0 || parsedSig.v === 1 ? parsedSig.v + 27 : parsedSig.v;
|
|
100
|
+
return ethers_1.ethers.utils.joinSignature({
|
|
101
|
+
r: normalizeSignatureComponent(parsedSig.r),
|
|
102
|
+
s: normalizeSignatureComponent(parsedSig.s),
|
|
103
|
+
v: vEthereum,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Sign a transaction
|
|
108
|
+
* Note: Transaction must be pre-populated with all fields (gasLimit, nonce, chainId, etc.)
|
|
109
|
+
* as we don't have RPC access in Lit Actions
|
|
110
|
+
*/
|
|
111
|
+
async signTransaction(transaction) {
|
|
112
|
+
const tx = { ...transaction };
|
|
113
|
+
delete tx.from; // ethers doesn't allow 'from' in unsigned tx
|
|
114
|
+
const serializedTx = ethers_1.ethers.utils.serializeTransaction(tx);
|
|
115
|
+
const toSign = ethers_1.ethers.utils.arrayify(ethers_1.ethers.utils.keccak256(serializedTx));
|
|
116
|
+
const signatureResponse = await Lit.Actions.signAndCombineEcdsa({
|
|
117
|
+
toSign,
|
|
118
|
+
publicKey: this.pkpPublicKey,
|
|
119
|
+
sigName: this.sigName,
|
|
120
|
+
});
|
|
121
|
+
const parsedSig = JSON.parse(signatureResponse);
|
|
122
|
+
return ethers_1.ethers.utils.serializeTransaction(tx, {
|
|
123
|
+
r: normalizeSignatureComponent(parsedSig.r),
|
|
124
|
+
s: normalizeSignatureComponent(parsedSig.s),
|
|
125
|
+
v: parsedSig.v,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.LitActionPkpEthersWallet = LitActionPkpEthersWallet;
|
|
130
|
+
/**
|
|
131
|
+
* Normalize signature component (r or s) from Lit's signAndCombineEcdsa response
|
|
132
|
+
* Lit returns signature components in DER encoding which may have a prefix byte
|
|
133
|
+
*/
|
|
134
|
+
function normalizeSignatureComponent(component) {
|
|
135
|
+
if (typeof component !== 'string') {
|
|
136
|
+
throw new Error(`Invalid signature component type: expected string, got ${typeof component}`);
|
|
137
|
+
}
|
|
138
|
+
// Ensure hex string has 0x prefix for ethers utilities
|
|
139
|
+
const hex = component.startsWith('0x') ? component : '0x' + component;
|
|
140
|
+
const length = ethers_1.ethers.utils.hexDataLength(hex);
|
|
141
|
+
// DER encoding has prefix byte, strip it
|
|
142
|
+
if (length === 33) {
|
|
143
|
+
return ethers_1.ethers.utils.hexDataSlice(hex, 1);
|
|
144
|
+
}
|
|
145
|
+
else if (length === 32) {
|
|
146
|
+
return hex;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new Error(`Invalid signature component length: expected 32 or 33 bytes, got ${length}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Normalize typed data value to ensure deterministic serialization
|
|
154
|
+
*/
|
|
155
|
+
function normalizeTypedDataValue(value, types) {
|
|
156
|
+
const normalized = {};
|
|
157
|
+
const primaryType = Object.keys(types)[0];
|
|
158
|
+
if (!primaryType || !types[primaryType]) {
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
// Build normalized object in type definition order
|
|
162
|
+
const fieldOrder = types[primaryType].map((f) => f.name);
|
|
163
|
+
for (const fieldName of fieldOrder) {
|
|
164
|
+
if (fieldName in value) {
|
|
165
|
+
const fieldValue = value[fieldName];
|
|
166
|
+
// Recursively normalize nested objects
|
|
167
|
+
if (typeof fieldValue === 'object' &&
|
|
168
|
+
fieldValue !== null &&
|
|
169
|
+
!Array.isArray(fieldValue) &&
|
|
170
|
+
!(fieldValue instanceof Uint8Array)) {
|
|
171
|
+
const fieldType = types[primaryType].find((f) => f.name === fieldName)?.type;
|
|
172
|
+
if (fieldType && types[fieldType]) {
|
|
173
|
+
normalized[fieldName] = normalizeTypedDataValue(fieldValue, types);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
normalized[fieldName] = fieldValue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
normalized[fieldName] = fieldValue;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Include any additional fields not in type definition
|
|
185
|
+
for (const key of Object.keys(value)) {
|
|
186
|
+
if (!(key in normalized)) {
|
|
187
|
+
normalized[key] = value[key];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return normalized;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=lit-action-pkp-ethers-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-action-pkp-ethers-wallet.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/lit-action-pkp-ethers-wallet.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,wBAAwB;IAClB,YAAY,CAAS;IACrB,OAAO,CAAS;IACjB,OAAO,CAAS;IAEhC,YAAY,YAAoB,EAAE,OAAO,GAAG,sBAAsB;QAChE,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAA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KAAK,CACN,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;gBACrC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC;YACzB,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const sendDepositTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }: {
|
|
2
|
+
rpcUrl: string;
|
|
3
|
+
chainId: number;
|
|
4
|
+
pkpEthAddress: string;
|
|
5
|
+
pkpPublicKey: string;
|
|
6
|
+
to: string;
|
|
7
|
+
value: string;
|
|
8
|
+
calldata: string;
|
|
9
|
+
gasBufferPercentage?: number;
|
|
10
|
+
baseFeePerGasBufferPercentage?: number;
|
|
11
|
+
alchemyGasSponsor?: boolean;
|
|
12
|
+
alchemyGasSponsorApiKey?: string;
|
|
13
|
+
alchemyGasSponsorPolicyId?: string;
|
|
14
|
+
}) => Promise<string>;
|
|
15
|
+
//# sourceMappingURL=send-deposit-tx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-deposit-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-deposit-tx.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,GAAU,mMAajC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC,KAAG,OAAO,CAAC,MAAM,CA4FjB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendDepositTx = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
6
|
+
const sign_tx_1 = require("./sign-tx");
|
|
7
|
+
const sendDepositTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }) => {
|
|
8
|
+
if (alchemyGasSponsor) {
|
|
9
|
+
console.log('[sendDepositTx] Alchemy gas sponsor is enabled');
|
|
10
|
+
if (!alchemyGasSponsorApiKey || !alchemyGasSponsorPolicyId) {
|
|
11
|
+
throw new Error('[sendDepositTx] Alchemy gas sponsor is enabled, but API key or policy ID is not provided.');
|
|
12
|
+
}
|
|
13
|
+
return await (0, vincent_ability_sdk_1.sponsoredGasRawTransaction)({
|
|
14
|
+
pkpPublicKey,
|
|
15
|
+
to,
|
|
16
|
+
value,
|
|
17
|
+
data: calldata,
|
|
18
|
+
chainId,
|
|
19
|
+
eip7702AlchemyApiKey: alchemyGasSponsorApiKey,
|
|
20
|
+
eip7702AlchemyPolicyId: alchemyGasSponsorPolicyId,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
console.log('[sendDepositTx] Estimating gas for Deposit transaction using pre-computed route');
|
|
24
|
+
const populateTxResponse = await Lit.Actions.runOnce({
|
|
25
|
+
waitForResponse: true,
|
|
26
|
+
name: '[sendDepositTx] Deposit tx gas estimation with pre-computed route',
|
|
27
|
+
}, async () => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.stringify({
|
|
30
|
+
status: 'success',
|
|
31
|
+
populatedTransaction: await (0, vincent_ability_sdk_1.populateTransaction)({
|
|
32
|
+
to,
|
|
33
|
+
from: pkpEthAddress,
|
|
34
|
+
value,
|
|
35
|
+
data: calldata,
|
|
36
|
+
rpcUrl,
|
|
37
|
+
chainId,
|
|
38
|
+
gasBufferPercentage,
|
|
39
|
+
baseFeePerGasBufferPercentage,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return JSON.stringify({
|
|
45
|
+
status: 'error',
|
|
46
|
+
error: error instanceof Error ? error.message : String(error),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const parsedPopulateTxResponse = JSON.parse(populateTxResponse);
|
|
51
|
+
if (parsedPopulateTxResponse.status === 'error') {
|
|
52
|
+
throw new Error(`[sendDepositTx] Error populating transaction for deposit: ${parsedPopulateTxResponse.error}`);
|
|
53
|
+
}
|
|
54
|
+
const { populatedTransaction } = parsedPopulateTxResponse;
|
|
55
|
+
const signedSwapTx = await (0, sign_tx_1.signTx)(pkpPublicKey, populatedTransaction, 'depositTxSig');
|
|
56
|
+
console.log(`[sendDepositTx] Broadcasting deposit transaction with pre-computed route`);
|
|
57
|
+
const swapTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: '[sendDepositTx] Deposit tx sender' }, async () => {
|
|
58
|
+
try {
|
|
59
|
+
const rpcProvider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
|
|
60
|
+
const receipt = await rpcProvider.sendTransaction(signedSwapTx);
|
|
61
|
+
return JSON.stringify({
|
|
62
|
+
status: 'success',
|
|
63
|
+
txHash: receipt.hash,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return JSON.stringify({
|
|
68
|
+
status: 'error',
|
|
69
|
+
error: error instanceof Error ? error.message : String(error),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const parsedSwapTxResponse = JSON.parse(swapTxResponse);
|
|
74
|
+
if (parsedSwapTxResponse.status === 'error') {
|
|
75
|
+
throw new Error(`[sendDepositTx] Error broadcasting deposit transaction: ${parsedSwapTxResponse.error}`);
|
|
76
|
+
}
|
|
77
|
+
const { txHash } = parsedSwapTxResponse;
|
|
78
|
+
console.log(`[sendDepositTx] Deposit transaction broadcasted with pre-computed route: ${txHash}`);
|
|
79
|
+
return txHash;
|
|
80
|
+
};
|
|
81
|
+
exports.sendDepositTx = sendDepositTx;
|
|
82
|
+
//# sourceMappingURL=send-deposit-tx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-deposit-tx.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-deposit-tx.ts"],"names":[],"mappings":";;;AAAA,mCAA0D;AAC1D,2EAAoG;AAEpG,uCAAmC;AAE5B,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,MAAM,EACN,OAAO,EACP,aAAa,EACb,YAAY,EACZ,EAAE,EACF,KAAK,EACL,QAAQ,EACR,mBAAmB,EACnB,6BAA6B,EAC7B,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,GAc1B,EAAmB,EAAE;IACpB,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAE9D,IAAI,CAAC,uBAAuB,IAAI,C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