@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,16 @@
|
|
|
1
|
+
import * as hyperliquid from '@nktkas/hyperliquid';
|
|
2
|
+
import { SuccessResponse } from '@nktkas/hyperliquid/api/exchange';
|
|
3
|
+
export type SendPerpUsdcResult = {
|
|
4
|
+
sendResult: SuccessResponse | hyperliquid.ErrorResponse;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Send USDC from your perp account to another Hyperliquid perp account
|
|
8
|
+
*/
|
|
9
|
+
export declare function sendPerpUsdc({ transport, pkpPublicKey, destination, amount, useTestnet, }: {
|
|
10
|
+
transport: hyperliquid.HttpTransport;
|
|
11
|
+
pkpPublicKey: string;
|
|
12
|
+
destination: string;
|
|
13
|
+
amount: string;
|
|
14
|
+
useTestnet?: boolean;
|
|
15
|
+
}): Promise<SendPerpUsdcResult>;
|
|
16
|
+
//# sourceMappingURL=send-perp-usdc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-perp-usdc.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-perp-usdc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAGL,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,CAAC,EACjC,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,EACN,UAAkB,GACnB,EAAE;IACD,SAAS,EAAE,WAAW,CAAC,aAAa,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6C9B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendPerpUsdc = sendPerpUsdc;
|
|
4
|
+
const exchange_1 = require("@nktkas/hyperliquid/api/exchange");
|
|
5
|
+
const signing_1 = require("@nktkas/hyperliquid/signing");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
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
|
+
const get_hyperliquid_chain_id_1 = require("./get-hyperliquid-chain-id");
|
|
11
|
+
/**
|
|
12
|
+
* Send USDC from your perp account to another Hyperliquid perp account
|
|
13
|
+
*/
|
|
14
|
+
async function sendPerpUsdc({ transport, pkpPublicKey, destination, amount, useTestnet = false, }) {
|
|
15
|
+
const pkpWallet = new lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet(pkpPublicKey);
|
|
16
|
+
const nonce = await (0, get_hyperliquid_nonce_1.getHyperliquidNonce)();
|
|
17
|
+
// Construct send action
|
|
18
|
+
// UsdSend uses standard 6 decimals for USDC (not Hyperliquid's 8 decimal precision)
|
|
19
|
+
const sendAction = (0, exchange_1.parser)(exchange_1.UsdSendRequest.entries.action)({
|
|
20
|
+
type: 'usdSend',
|
|
21
|
+
signatureChainId: (0, get_hyperliquid_chain_id_1.getHyperliquidChainId)(useTestnet),
|
|
22
|
+
hyperliquidChain: (0, get_hyperliquid_chain_id_1.getHyperliquidChainName)(useTestnet),
|
|
23
|
+
destination,
|
|
24
|
+
// Convert amount from micro-units (6 decimals) to human-readable format
|
|
25
|
+
// e.g., "1000000" -> "1.0"
|
|
26
|
+
amount: ethers_1.ethers.utils.formatUnits(amount, 6),
|
|
27
|
+
time: nonce,
|
|
28
|
+
});
|
|
29
|
+
// UsdSend is a user-signed action that uses EIP-712 typed data
|
|
30
|
+
const signature = await (0, signing_1.signUserSignedAction)({
|
|
31
|
+
wallet: pkpWallet,
|
|
32
|
+
action: sendAction,
|
|
33
|
+
types: exchange_1.UsdSendTypes,
|
|
34
|
+
});
|
|
35
|
+
const sendResult = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidSendPerpUsdcRequest' }, async () => {
|
|
36
|
+
return JSON.stringify({
|
|
37
|
+
result: await transport.request('exchange', {
|
|
38
|
+
action: sendAction,
|
|
39
|
+
signature,
|
|
40
|
+
nonce,
|
|
41
|
+
}),
|
|
42
|
+
}, vincent_ability_sdk_1.bigIntReplacer, 2);
|
|
43
|
+
});
|
|
44
|
+
const parsedSendResult = JSON.parse(sendResult);
|
|
45
|
+
return {
|
|
46
|
+
sendResult: parsedSendResult.result,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=send-perp-usdc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-perp-usdc.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-perp-usdc.ts"],"names":[],"mappings":";;AAsBA,oCAyDC;AA9ED,+DAK0C;AAC1C,yDAAmE;AACnE,mCAAgC;AAChC,2EAAmE;AAEnE,iFAA0E;AAC1E,mEAA8D;AAC9D,yEAA4F;AAM5F;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,EACjC,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,EACN,UAAU,GAAG,KAAK,GAOnB;IACC,MAAM,SAAS,GAAG,IAAI,uDAAwB,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,MAAM,IAAA,2CAAmB,GAAE,CAAC;IAE1C,wBAAwB;IACxB,oFAAoF;IACpF,MAAM,UAAU,GAAG,IAAA,iBAAM,EAAC,yBAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvD,IAAI,EAAE,SAAS;QACf,gBAAgB,EAAE,IAAA,gDAAqB,EAAC,UAAU,CAAC;QACnD,gBAAgB,EAAE,IAAA,kDAAuB,EAAC,UAAU,CAAC;QACrD,WAAW;QACX,wEAAwE;QACxE,2BAA2B;QAC3B,MAAM,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,EAAE,KAAK;KACZ,CAAC,CAAC;IAEH,+DAA+D;IAC/D,MAAM,SAAS,GAAG,MAAM,IAAA,8BAAoB,EAAC;QAC3C,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,uBAAY;KACpB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAC1C,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,gCAAgC,EAAE,EACjE,KAAK,IAAI,EAAE;QACT,OAAO,IAAI,CAAC,SAAS,CACnB;YACE,MAAM,EAAE,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE;gBAC1C,MAAM,EAAE,UAAU;gBAClB,SAAS;gBACT,KAAK;aACN,CAAC;SACH,EACD,oCAAc,EACd,CAAC,CACF,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO;QACL,UAAU,EAAE,gBAAgB,CAAC,MAAqD;KACnF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as hyperliquid from '@nktkas/hyperliquid';
|
|
2
|
+
import { SuccessResponse } from '@nktkas/hyperliquid/api/exchange';
|
|
3
|
+
export type SendSpotAssetResult = {
|
|
4
|
+
sendResult: SuccessResponse | hyperliquid.ErrorResponse;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Send spot assets (USDC or other tokens) to another Hyperliquid spot account
|
|
8
|
+
*/
|
|
9
|
+
export declare function sendSpotAsset({ transport, pkpPublicKey, destination, token, amount, useTestnet, }: {
|
|
10
|
+
transport: hyperliquid.HttpTransport;
|
|
11
|
+
pkpPublicKey: string;
|
|
12
|
+
destination: string;
|
|
13
|
+
token: string;
|
|
14
|
+
amount: string;
|
|
15
|
+
useTestnet?: boolean;
|
|
16
|
+
}): Promise<SendSpotAssetResult>;
|
|
17
|
+
//# sourceMappingURL=send-spot-asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-spot-asset.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-spot-asset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAGL,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,YAAY,EACZ,WAAW,EACX,KAAK,EACL,MAAM,EACN,UAAkB,GACnB,EAAE;IACD,SAAS,EAAE,WAAW,CAAC,aAAa,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAyD/B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendSpotAsset = sendSpotAsset;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const hyperliquid = tslib_1.__importStar(require("@nktkas/hyperliquid"));
|
|
6
|
+
const exchange_1 = require("@nktkas/hyperliquid/api/exchange");
|
|
7
|
+
const signing_1 = require("@nktkas/hyperliquid/signing");
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
10
|
+
const lit_action_pkp_ethers_wallet_1 = require("./lit-action-pkp-ethers-wallet");
|
|
11
|
+
const get_hyperliquid_nonce_1 = require("./get-hyperliquid-nonce");
|
|
12
|
+
const get_hyperliquid_chain_id_1 = require("./get-hyperliquid-chain-id");
|
|
13
|
+
/**
|
|
14
|
+
* Send spot assets (USDC or other tokens) to another Hyperliquid spot account
|
|
15
|
+
*/
|
|
16
|
+
async function sendSpotAsset({ transport, pkpPublicKey, destination, token, amount, useTestnet = false, }) {
|
|
17
|
+
const pkpWallet = new lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet(pkpPublicKey);
|
|
18
|
+
const nonce = await (0, get_hyperliquid_nonce_1.getHyperliquidNonce)();
|
|
19
|
+
// Fetch token metadata to get the correct decimal places
|
|
20
|
+
const infoClient = new hyperliquid.InfoClient({ transport });
|
|
21
|
+
const spotMeta = await infoClient.spotMeta();
|
|
22
|
+
// Find the token in the metadata
|
|
23
|
+
const tokenInfo = spotMeta.tokens.find((t) => t.name === token);
|
|
24
|
+
if (!tokenInfo) {
|
|
25
|
+
throw new Error(`Token ${token} not found in spot metadata`);
|
|
26
|
+
}
|
|
27
|
+
console.log('[sendAsset] Token info:', tokenInfo);
|
|
28
|
+
// Construct send action
|
|
29
|
+
const sendAction = (0, exchange_1.parser)(exchange_1.SpotSendRequest.entries.action)({
|
|
30
|
+
type: 'spotSend',
|
|
31
|
+
signatureChainId: (0, get_hyperliquid_chain_id_1.getHyperliquidChainId)(useTestnet),
|
|
32
|
+
hyperliquidChain: (0, get_hyperliquid_chain_id_1.getHyperliquidChainName)(useTestnet),
|
|
33
|
+
destination,
|
|
34
|
+
// Construct token identifier in the format expected by SpotSend: "name:0xaddress"
|
|
35
|
+
token: `${tokenInfo.name}:${tokenInfo.tokenId}`,
|
|
36
|
+
// Convert amount from smallest units (micro-units) to human-readable format
|
|
37
|
+
// using weiDecimals which represents the exchange precision for amounts
|
|
38
|
+
amount: ethers_1.ethers.utils.formatUnits(amount, tokenInfo.weiDecimals),
|
|
39
|
+
time: nonce,
|
|
40
|
+
});
|
|
41
|
+
// SpotSend is a user-signed action that uses EIP-712 typed data
|
|
42
|
+
const signature = await (0, signing_1.signUserSignedAction)({
|
|
43
|
+
wallet: pkpWallet,
|
|
44
|
+
action: sendAction,
|
|
45
|
+
types: exchange_1.SpotSendTypes,
|
|
46
|
+
});
|
|
47
|
+
const sendResult = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidSendAssetRequest' }, async () => {
|
|
48
|
+
return JSON.stringify({
|
|
49
|
+
result: await transport.request('exchange', {
|
|
50
|
+
action: sendAction,
|
|
51
|
+
signature,
|
|
52
|
+
nonce,
|
|
53
|
+
}),
|
|
54
|
+
}, vincent_ability_sdk_1.bigIntReplacer, 2);
|
|
55
|
+
});
|
|
56
|
+
const parsedSendResult = JSON.parse(sendResult);
|
|
57
|
+
return {
|
|
58
|
+
sendResult: parsedSendResult.result,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=send-spot-asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-spot-asset.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-spot-asset.ts"],"names":[],"mappings":";;AAsBA,sCAuEC;;AA7FD,yEAAmD;AACnD,+DAK0C;AAC1C,yDAAmE;AACnE,mCAAgC;AAChC,2EAAmE;AAEnE,iFAA0E;AAC1E,mEAA8D;AAC9D,yEAA4F;AAM5F;;GAEG;AACI,KAAK,UAAU,aAAa,CAAC,EAClC,SAAS,EACT,YAAY,EACZ,WAAW,EACX,KAAK,EACL,MAAM,EACN,UAAU,GAAG,KAAK,GAQnB;IACC,MAAM,SAAS,GAAG,IAAI,uDAAwB,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,MAAM,IAAA,2CAAmB,GAAE,CAAC;IAE1C,yDAAyD;IACzD,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAE7C,iCAAiC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;IAChE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,SAAS,KAAK,6BAA6B,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,yBAAyB,E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":"sign-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/sign-tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,MAAM,GACjB,cAAc,MAAM,EACpB,IAAI,MAAM,CAAC,mBAAmB,EAC9B,SAAS,MAAM,oBA4BhB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signTx = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const signTx = async (pkpPublicKey, tx, sigName) => {
|
|
6
|
+
// Remove 0x prefix if it exists, Lit expects a hex string without 0x prefix
|
|
7
|
+
const publicKeyForLit = pkpPublicKey.replace(/^0x/, '');
|
|
8
|
+
console.log(`Signing using PKP Public Key: ${publicKeyForLit} (signTx)`);
|
|
9
|
+
const unsignedSerializedTx = ethers_1.ethers.utils.serializeTransaction(tx);
|
|
10
|
+
const txHash = ethers_1.ethers.utils.keccak256(unsignedSerializedTx);
|
|
11
|
+
console.log('Tx hash (signTx)', txHash);
|
|
12
|
+
const signatureResponse = await Lit.Actions.signAndCombineEcdsa({
|
|
13
|
+
toSign: ethers_1.ethers.utils.arrayify(txHash),
|
|
14
|
+
publicKey: publicKeyForLit,
|
|
15
|
+
sigName,
|
|
16
|
+
});
|
|
17
|
+
const { r, s, v } = JSON.parse(signatureResponse);
|
|
18
|
+
const ethersJoinedSignature = ethers_1.ethers.utils.joinSignature({
|
|
19
|
+
r: '0x' + r.substring(2),
|
|
20
|
+
s: '0x' + s,
|
|
21
|
+
v: v,
|
|
22
|
+
});
|
|
23
|
+
const signedSerializedTx = ethers_1.ethers.utils.serializeTransaction(tx, ethersJoinedSignature);
|
|
24
|
+
console.log('Signed serialized tx (signTx)', signedSerializedTx);
|
|
25
|
+
return signedSerializedTx;
|
|
26
|
+
};
|
|
27
|
+
exports.signTx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B,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,kBAAkB,CAAC,CAAC;IAEjE,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AA/BW,QAAA,MAAM,UA+BjB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as hyperliquid from '@nktkas/hyperliquid';
|
|
2
|
+
import { SuccessResponse } from '@nktkas/hyperliquid/api/exchange';
|
|
3
|
+
export type TransferUsdcResult = {
|
|
4
|
+
transferResult: SuccessResponse | hyperliquid.ErrorResponse;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Transfer funds between spot and perpetuals accounts on Hyperliquid
|
|
8
|
+
*/
|
|
9
|
+
export declare function transferUsdcTo({ transport, pkpPublicKey, amount, to, useTestnet, }: {
|
|
10
|
+
transport: hyperliquid.HttpTransport;
|
|
11
|
+
pkpPublicKey: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
to: 'spot' | 'perp';
|
|
14
|
+
useTestnet?: boolean;
|
|
15
|
+
}): Promise<TransferUsdcResult>;
|
|
16
|
+
//# sourceMappingURL=transfer-usdc-to.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-usdc-to.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/transfer-usdc-to.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAGL,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAkB,GACnB,EAAE;IACD,SAAS,EAAE,WAAW,CAAC,aAAa,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAiD9B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferUsdcTo = transferUsdcTo;
|
|
4
|
+
const exchange_1 = require("@nktkas/hyperliquid/api/exchange");
|
|
5
|
+
const signing_1 = require("@nktkas/hyperliquid/signing");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
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
|
+
const get_hyperliquid_chain_id_1 = require("./get-hyperliquid-chain-id");
|
|
11
|
+
/**
|
|
12
|
+
* Transfer funds between spot and perpetuals accounts on Hyperliquid
|
|
13
|
+
*/
|
|
14
|
+
async function transferUsdcTo({ transport, pkpPublicKey, amount, to, useTestnet = false, }) {
|
|
15
|
+
if (to !== 'spot' && to !== 'perp') {
|
|
16
|
+
throw new Error('[transferUsdcTo] Invalid transfer destination. Must be either "spot" or "perp".');
|
|
17
|
+
}
|
|
18
|
+
const nonce = await (0, get_hyperliquid_nonce_1.getHyperliquidNonce)();
|
|
19
|
+
const transferAction = (0, exchange_1.parser)(exchange_1.UsdClassTransferRequest.entries.action)({
|
|
20
|
+
type: 'usdClassTransfer',
|
|
21
|
+
// Convert amount from raw units (e.g., "1000000" for 1.0 USDC) to formatted string (e.g., "1.0")
|
|
22
|
+
// Hyperliquid expects the amount as a string in human-readable format
|
|
23
|
+
amount: ethers_1.ethers.utils.formatUnits(amount, 6),
|
|
24
|
+
signatureChainId: (0, get_hyperliquid_chain_id_1.getHyperliquidChainId)(useTestnet),
|
|
25
|
+
hyperliquidChain: (0, get_hyperliquid_chain_id_1.getHyperliquidChainName)(useTestnet),
|
|
26
|
+
toPerp: to === 'perp',
|
|
27
|
+
nonce,
|
|
28
|
+
});
|
|
29
|
+
// UsdClassTransfer is a user-signed action that uses EIP-712 typed data
|
|
30
|
+
const pkpEthersWallet = new lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet(pkpPublicKey);
|
|
31
|
+
const signature = await (0, signing_1.signUserSignedAction)({
|
|
32
|
+
wallet: pkpEthersWallet,
|
|
33
|
+
action: transferAction,
|
|
34
|
+
types: exchange_1.UsdClassTransferTypes,
|
|
35
|
+
});
|
|
36
|
+
const transferResult = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidTransferRequest' }, async () => {
|
|
37
|
+
return JSON.stringify({
|
|
38
|
+
result: await transport.request('exchange', {
|
|
39
|
+
action: transferAction,
|
|
40
|
+
signature,
|
|
41
|
+
nonce,
|
|
42
|
+
}),
|
|
43
|
+
}, vincent_ability_sdk_1.bigIntReplacer, 2);
|
|
44
|
+
});
|
|
45
|
+
const parsedTransferResult = JSON.parse(transferResult);
|
|
46
|
+
return {
|
|
47
|
+
transferResult: parsedTransferResult.result,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=transfer-usdc-to.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-usdc-to.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/transfer-usdc-to.ts"],"names":[],"mappings":";;AAsBA,wCA6DC;AAlFD,+DAK0C;AAC1C,yDAAmE;AACnE,mCAAgC;AAChC,2EAAmE;AAEnE,iFAA0E;AAC1E,mEAA8D;AAC9D,yEAA4F;AAM5F;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,EACnC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,GAAG,KAAK,GAOnB;IACC,IAAI,EAAE,KAAK,M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,EAAE,oBAAoB,CAAC,MAAqD;KAC3F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as hyperliquid from '@nktkas/hyperliquid';
|
|
2
|
+
import { SuccessResponse } from '@nktkas/hyperliquid/api/exchange';
|
|
3
|
+
export type WithdrawUsdcResult = {
|
|
4
|
+
withdrawResult: SuccessResponse | hyperliquid.ErrorResponse;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Withdraw funds from Hyperliquid Perp account to L1 (Arbitrum)
|
|
8
|
+
*/
|
|
9
|
+
export declare function withdrawUsdc({ transport, pkpPublicKey, amount, destination, useTestnet, }: {
|
|
10
|
+
transport: hyperliquid.HttpTransport;
|
|
11
|
+
pkpPublicKey: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
destination: string;
|
|
14
|
+
useTestnet?: boolean;
|
|
15
|
+
}): Promise<WithdrawUsdcResult>;
|
|
16
|
+
//# sourceMappingURL=withdraw-usdc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdraw-usdc.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/withdraw-usdc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAGL,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,CAAC,EACjC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAkB,GACnB,EAAE;IACD,SAAS,EAAE,WAAW,CAAC,aAAa,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6C9B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withdrawUsdc = withdrawUsdc;
|
|
4
|
+
const exchange_1 = require("@nktkas/hyperliquid/api/exchange");
|
|
5
|
+
const signing_1 = require("@nktkas/hyperliquid/signing");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
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
|
+
const get_hyperliquid_chain_id_1 = require("./get-hyperliquid-chain-id");
|
|
11
|
+
/**
|
|
12
|
+
* Withdraw funds from Hyperliquid Perp account to L1 (Arbitrum)
|
|
13
|
+
*/
|
|
14
|
+
async function withdrawUsdc({ transport, pkpPublicKey, amount, destination, useTestnet = false, }) {
|
|
15
|
+
// Create PKP wallet
|
|
16
|
+
const pkpWallet = new lit_action_pkp_ethers_wallet_1.LitActionPkpEthersWallet(pkpPublicKey);
|
|
17
|
+
const nonce = await (0, get_hyperliquid_nonce_1.getHyperliquidNonce)();
|
|
18
|
+
// Construct withdraw action
|
|
19
|
+
const withdrawAction = (0, exchange_1.parser)(exchange_1.Withdraw3Request.entries.action)({
|
|
20
|
+
type: 'withdraw3',
|
|
21
|
+
signatureChainId: (0, get_hyperliquid_chain_id_1.getHyperliquidChainId)(useTestnet),
|
|
22
|
+
hyperliquidChain: (0, get_hyperliquid_chain_id_1.getHyperliquidChainName)(useTestnet),
|
|
23
|
+
destination,
|
|
24
|
+
// Convert amount from raw units (e.g., "1000000" for 1.0 USDC) to formatted string (e.g., "1.0")
|
|
25
|
+
// Hyperliquid expects the amount as a string in human-readable format
|
|
26
|
+
amount: ethers_1.ethers.utils.formatUnits(amount, 6),
|
|
27
|
+
time: nonce,
|
|
28
|
+
});
|
|
29
|
+
// Withdraw3 is a user-signed action that uses EIP-712 typed data
|
|
30
|
+
const signature = await (0, signing_1.signUserSignedAction)({
|
|
31
|
+
wallet: pkpWallet,
|
|
32
|
+
action: withdrawAction,
|
|
33
|
+
types: exchange_1.Withdraw3Types,
|
|
34
|
+
});
|
|
35
|
+
const withdrawResult = await Lit.Actions.runOnce({ waitForResponse: true, name: 'HyperLiquidWithdrawRequest' }, async () => {
|
|
36
|
+
return JSON.stringify({
|
|
37
|
+
result: await transport.request('exchange', {
|
|
38
|
+
action: withdrawAction,
|
|
39
|
+
signature,
|
|
40
|
+
nonce,
|
|
41
|
+
}),
|
|
42
|
+
}, vincent_ability_sdk_1.bigIntReplacer, 2);
|
|
43
|
+
});
|
|
44
|
+
const parsedWithdrawResult = JSON.parse(withdrawResult);
|
|
45
|
+
return {
|
|
46
|
+
withdrawResult: parsedWithdrawResult.result,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=withdraw-usdc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdraw-usdc.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/withdraw-usdc.ts"],"names":[],"mappings":";;AAsBA,oCAyDC;AA9ED,+DAK0C;AAC1C,yDAAmE;AACnE,mCAAgC;AAChC,2EAAmE;AAEnE,iFAA0E;AAC1E,mEAA8D;AAC9D,yEAA4F;AAM5F;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,EACjC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAU,GAAG,KAAK,GAOnB;IACC,oBAAoB;IACpB,MAAM,SAAS,GAAG,IAAI,uDAAwB,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,MAAM,IAAA,2CAAmB,GAAE,CAAC;IAE1C,4BAA4B;IAC5B,MAAM,cAAc,GAAG,IAAA,iBAAM,EAAC,2BAAgB,C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
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HYPERLIQUID_BUILDER_FEE_RATE = exports.HYPERLIQUID_BUILDER_ADDRESS = void 0;
|
|
4
|
+
exports.HYPERLIQUID_BUILDER_ADDRESS = '0x132Db5f531Ba38628F1640683354229daE04E8e6';
|
|
5
|
+
exports.HYPERLIQUID_BUILDER_FEE_RATE = '0.05'; // Percentage as string (e.g., "0.05" = 0.05%)
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,4CAA4C,CAAC;AAC3E,QAAA,4BAA4B,GAAG,MAAM,CAAC,CAAC,8CAA8C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-action.d.ts","sourceRoot":"","sources":["../../../src/lib/lit-action.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
4
|
+
// FIXME: This should be generated code
|
|
5
|
+
const vincent_ability_1 = require("./vincent-ability");
|
|
6
|
+
(async () => {
|
|
7
|
+
const func = (0, vincent_ability_sdk_1.vincentAbilityHandler)({
|
|
8
|
+
vincentAbility: vincent_ability_1.vincentAbility,
|
|
9
|
+
context: {
|
|
10
|
+
delegatorPkpEthAddress: context.delegatorPkpEthAddress,
|
|
11
|
+
},
|
|
12
|
+
abilityParams,
|
|
13
|
+
});
|
|
14
|
+
await func();
|
|
15
|
+
})();
|
|
16
|
+
//# sourceMappingURL=lit-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-action.js","sourceRoot":"","sources":["../../../src/lib/lit-action.ts"],"names":[],"mappings":";;AAAA,2EAA0E;AAG1E,uCAAuC;AAEvC,uDAAmD;AAQnD,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,IAAI,GAAG,IAAA,2CAAqB,EAAC;QACjC,cAAc,EAAE,gCAAc;QAC9B,OAAO,EAAE;YACP,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;SACvD;QACD,aAAa;KACd,CAAC,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;AACf,CAAC,CAAC,EAAE,CAAC"}
|