@pafi-dev/core 0.1.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/README.md +1157 -0
- package/dist/abi/index.cjs +31 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +2479 -0
- package/dist/abi/index.d.ts +2479 -0
- package/dist/abi/index.js +31 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/auth/index.cjs +11 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +60 -0
- package/dist/auth/index.d.ts +60 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/chunk-27V32VNM.cjs +370 -0
- package/dist/chunk-27V32VNM.cjs.map +1 -0
- package/dist/chunk-2PIXFXA2.js +135 -0
- package/dist/chunk-2PIXFXA2.js.map +1 -0
- package/dist/chunk-37BBGXTS.js +149 -0
- package/dist/chunk-37BBGXTS.js.map +1 -0
- package/dist/chunk-4QOWQQCH.cjs +99 -0
- package/dist/chunk-4QOWQQCH.cjs.map +1 -0
- package/dist/chunk-4RYBJLF3.js +370 -0
- package/dist/chunk-4RYBJLF3.js.map +1 -0
- package/dist/chunk-5QJZT7VB.cjs +46 -0
- package/dist/chunk-5QJZT7VB.cjs.map +1 -0
- package/dist/chunk-5YH4D7QF.js +467 -0
- package/dist/chunk-5YH4D7QF.js.map +1 -0
- package/dist/chunk-BNTVOKYT.cjs +101 -0
- package/dist/chunk-BNTVOKYT.cjs.map +1 -0
- package/dist/chunk-C4ZDYG4D.js +101 -0
- package/dist/chunk-C4ZDYG4D.js.map +1 -0
- package/dist/chunk-CAE2BVKI.cjs +136 -0
- package/dist/chunk-CAE2BVKI.cjs.map +1 -0
- package/dist/chunk-CL3QSI4O.cjs +65 -0
- package/dist/chunk-CL3QSI4O.cjs.map +1 -0
- package/dist/chunk-CWP4PFOP.cjs +72 -0
- package/dist/chunk-CWP4PFOP.cjs.map +1 -0
- package/dist/chunk-DSCUHT3F.js +99 -0
- package/dist/chunk-DSCUHT3F.js.map +1 -0
- package/dist/chunk-FGKLDKJK.cjs +467 -0
- package/dist/chunk-FGKLDKJK.cjs.map +1 -0
- package/dist/chunk-FIKTQR7H.js +136 -0
- package/dist/chunk-FIKTQR7H.js.map +1 -0
- package/dist/chunk-FXNG4G22.js +2041 -0
- package/dist/chunk-FXNG4G22.js.map +1 -0
- package/dist/chunk-GWLEEXM4.cjs +163 -0
- package/dist/chunk-GWLEEXM4.cjs.map +1 -0
- package/dist/chunk-IPXARZ6F.cjs +135 -0
- package/dist/chunk-IPXARZ6F.cjs.map +1 -0
- package/dist/chunk-KFWZRL7I.js +65 -0
- package/dist/chunk-KFWZRL7I.js.map +1 -0
- package/dist/chunk-KW6M5FXY.js +129 -0
- package/dist/chunk-KW6M5FXY.js.map +1 -0
- package/dist/chunk-MEREIEE4.cjs +129 -0
- package/dist/chunk-MEREIEE4.cjs.map +1 -0
- package/dist/chunk-O4SMTUOY.js +163 -0
- package/dist/chunk-O4SMTUOY.js.map +1 -0
- package/dist/chunk-O7LQKCBT.cjs +149 -0
- package/dist/chunk-O7LQKCBT.cjs.map +1 -0
- package/dist/chunk-P56TUGTS.js +46 -0
- package/dist/chunk-P56TUGTS.js.map +1 -0
- package/dist/chunk-R4L66ZR5.js +72 -0
- package/dist/chunk-R4L66ZR5.js.map +1 -0
- package/dist/chunk-S2XRFFP3.cjs +2041 -0
- package/dist/chunk-S2XRFFP3.cjs.map +1 -0
- package/dist/contract/index.cjs +27 -0
- package/dist/contract/index.cjs.map +1 -0
- package/dist/contract/index.d.cts +18 -0
- package/dist/contract/index.d.ts +18 -0
- package/dist/contract/index.js +27 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/eip712/index.cjs +20 -0
- package/dist/eip712/index.cjs.map +1 -0
- package/dist/eip712/index.d.cts +83 -0
- package/dist/eip712/index.d.ts +83 -0
- package/dist/eip712/index.js +20 -0
- package/dist/eip712/index.js.map +1 -0
- package/dist/index.cjs +412 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +239 -0
- package/dist/index.d.ts +239 -0
- package/dist/index.js +412 -0
- package/dist/index.js.map +1 -0
- package/dist/quoting/index.cjs +19 -0
- package/dist/quoting/index.cjs.map +1 -0
- package/dist/quoting/index.d.cts +59 -0
- package/dist/quoting/index.d.ts +59 -0
- package/dist/quoting/index.js +19 -0
- package/dist/quoting/index.js.map +1 -0
- package/dist/relay/index.cjs +19 -0
- package/dist/relay/index.cjs.map +1 -0
- package/dist/relay/index.d.cts +62 -0
- package/dist/relay/index.d.ts +62 -0
- package/dist/relay/index.js +19 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/swap/index.cjs +29 -0
- package/dist/swap/index.cjs.map +1 -0
- package/dist/swap/index.d.cts +79 -0
- package/dist/swap/index.d.ts +79 -0
- package/dist/swap/index.js +29 -0
- package/dist/swap/index.js.map +1 -0
- package/dist/types-CkRJzrZr.d.cts +98 -0
- package/dist/types-CkRJzrZr.d.ts +98 -0
- package/package.json +114 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Hex, PublicClient, Address } from 'viem';
|
|
2
|
+
import { e as PathKey, d as SwapParams, c as MintParams } from '../types-CkRJzrZr.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encode extData for ReceiverConsent and MintParams.
|
|
6
|
+
* extData = abi.encode(uint256 minAmountOut, uint256 feeInUsdt)
|
|
7
|
+
*/
|
|
8
|
+
declare function encodeExtData(minAmountOut: bigint, feeInUsdt: bigint): Hex;
|
|
9
|
+
/**
|
|
10
|
+
* Decode extData back to { minAmountOut, feeInUsdt }.
|
|
11
|
+
*/
|
|
12
|
+
declare function decodeExtData(extData: Hex): {
|
|
13
|
+
minAmountOut: bigint;
|
|
14
|
+
feeInUsdt: bigint;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Build SwapParams and extData from a quote result for Relay.mintAndSwap.
|
|
18
|
+
*
|
|
19
|
+
* @param quote - Quote result containing the path
|
|
20
|
+
* @param minAmountOut - Minimum acceptable USDT output (caller applies slippage)
|
|
21
|
+
* @param feeInUsdt - Fixed USDT fee for the relayer
|
|
22
|
+
* @param deadline - Swap deadline (unix timestamp)
|
|
23
|
+
*/
|
|
24
|
+
declare function buildRelaySwapParams(params: {
|
|
25
|
+
quote: {
|
|
26
|
+
path: PathKey[];
|
|
27
|
+
};
|
|
28
|
+
minAmountOut: bigint;
|
|
29
|
+
feeInUsdt: bigint;
|
|
30
|
+
deadline: bigint;
|
|
31
|
+
}): {
|
|
32
|
+
swapParams: SwapParams;
|
|
33
|
+
extData: Hex;
|
|
34
|
+
};
|
|
35
|
+
declare function encodeMintAndSwap(mint: MintParams, swap: SwapParams): Hex;
|
|
36
|
+
declare function decodeMintAndSwap(calldata: Hex): {
|
|
37
|
+
mint: MintParams;
|
|
38
|
+
swap: SwapParams;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface SimulationResult {
|
|
42
|
+
success: boolean;
|
|
43
|
+
gasEstimate: bigint;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Simulate a Relay.mintAndSwap call via eth_call (no gas spent).
|
|
47
|
+
*
|
|
48
|
+
* Runs the full flow — signature verification, minting, swap via PoolManager,
|
|
49
|
+
* fee split — without submitting a transaction. If the simulation reverts,
|
|
50
|
+
* throws a `SimulationError` with the revert reason.
|
|
51
|
+
*
|
|
52
|
+
* Call this AFTER both signatures are collected but BEFORE submitting the tx.
|
|
53
|
+
*
|
|
54
|
+
* @param client - viem PublicClient
|
|
55
|
+
* @param relayAddress - Relay contract address
|
|
56
|
+
* @param mint - MintParams (with real minterSig + receiverSig)
|
|
57
|
+
* @param swap - SwapParams (path + deadline)
|
|
58
|
+
* @param from - Address that will call mintAndSwap (the relayer)
|
|
59
|
+
*/
|
|
60
|
+
declare function simulateMintAndSwap(client: PublicClient, relayAddress: Address, mint: MintParams, swap: SwapParams, from: Address): Promise<SimulationResult>;
|
|
61
|
+
|
|
62
|
+
export { type SimulationResult, buildRelaySwapParams, decodeExtData, decodeMintAndSwap, encodeExtData, encodeMintAndSwap, simulateMintAndSwap };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Hex, PublicClient, Address } from 'viem';
|
|
2
|
+
import { e as PathKey, d as SwapParams, c as MintParams } from '../types-CkRJzrZr.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encode extData for ReceiverConsent and MintParams.
|
|
6
|
+
* extData = abi.encode(uint256 minAmountOut, uint256 feeInUsdt)
|
|
7
|
+
*/
|
|
8
|
+
declare function encodeExtData(minAmountOut: bigint, feeInUsdt: bigint): Hex;
|
|
9
|
+
/**
|
|
10
|
+
* Decode extData back to { minAmountOut, feeInUsdt }.
|
|
11
|
+
*/
|
|
12
|
+
declare function decodeExtData(extData: Hex): {
|
|
13
|
+
minAmountOut: bigint;
|
|
14
|
+
feeInUsdt: bigint;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Build SwapParams and extData from a quote result for Relay.mintAndSwap.
|
|
18
|
+
*
|
|
19
|
+
* @param quote - Quote result containing the path
|
|
20
|
+
* @param minAmountOut - Minimum acceptable USDT output (caller applies slippage)
|
|
21
|
+
* @param feeInUsdt - Fixed USDT fee for the relayer
|
|
22
|
+
* @param deadline - Swap deadline (unix timestamp)
|
|
23
|
+
*/
|
|
24
|
+
declare function buildRelaySwapParams(params: {
|
|
25
|
+
quote: {
|
|
26
|
+
path: PathKey[];
|
|
27
|
+
};
|
|
28
|
+
minAmountOut: bigint;
|
|
29
|
+
feeInUsdt: bigint;
|
|
30
|
+
deadline: bigint;
|
|
31
|
+
}): {
|
|
32
|
+
swapParams: SwapParams;
|
|
33
|
+
extData: Hex;
|
|
34
|
+
};
|
|
35
|
+
declare function encodeMintAndSwap(mint: MintParams, swap: SwapParams): Hex;
|
|
36
|
+
declare function decodeMintAndSwap(calldata: Hex): {
|
|
37
|
+
mint: MintParams;
|
|
38
|
+
swap: SwapParams;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface SimulationResult {
|
|
42
|
+
success: boolean;
|
|
43
|
+
gasEstimate: bigint;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Simulate a Relay.mintAndSwap call via eth_call (no gas spent).
|
|
47
|
+
*
|
|
48
|
+
* Runs the full flow — signature verification, minting, swap via PoolManager,
|
|
49
|
+
* fee split — without submitting a transaction. If the simulation reverts,
|
|
50
|
+
* throws a `SimulationError` with the revert reason.
|
|
51
|
+
*
|
|
52
|
+
* Call this AFTER both signatures are collected but BEFORE submitting the tx.
|
|
53
|
+
*
|
|
54
|
+
* @param client - viem PublicClient
|
|
55
|
+
* @param relayAddress - Relay contract address
|
|
56
|
+
* @param mint - MintParams (with real minterSig + receiverSig)
|
|
57
|
+
* @param swap - SwapParams (path + deadline)
|
|
58
|
+
* @param from - Address that will call mintAndSwap (the relayer)
|
|
59
|
+
*/
|
|
60
|
+
declare function simulateMintAndSwap(client: PublicClient, relayAddress: Address, mint: MintParams, swap: SwapParams, from: Address): Promise<SimulationResult>;
|
|
61
|
+
|
|
62
|
+
export { type SimulationResult, buildRelaySwapParams, decodeExtData, decodeMintAndSwap, encodeExtData, encodeMintAndSwap, simulateMintAndSwap };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildRelaySwapParams,
|
|
3
|
+
decodeExtData,
|
|
4
|
+
decodeMintAndSwap,
|
|
5
|
+
encodeExtData,
|
|
6
|
+
encodeMintAndSwap,
|
|
7
|
+
simulateMintAndSwap
|
|
8
|
+
} from "../chunk-DSCUHT3F.js";
|
|
9
|
+
import "../chunk-4RYBJLF3.js";
|
|
10
|
+
import "../chunk-P56TUGTS.js";
|
|
11
|
+
export {
|
|
12
|
+
buildRelaySwapParams,
|
|
13
|
+
decodeExtData,
|
|
14
|
+
decodeMintAndSwap,
|
|
15
|
+
encodeExtData,
|
|
16
|
+
encodeMintAndSwap,
|
|
17
|
+
simulateMintAndSwap
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkO7LQKCBTcjs = require('../chunk-O7LQKCBT.cjs');
|
|
14
|
+
require('../chunk-IPXARZ6F.cjs');
|
|
15
|
+
require('../chunk-5QJZT7VB.cjs');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.SETTLE_ALL = _chunkO7LQKCBTcjs.SETTLE_ALL; exports.SWAP_EXACT_IN = _chunkO7LQKCBTcjs.SWAP_EXACT_IN; exports.TAKE_ALL = _chunkO7LQKCBTcjs.TAKE_ALL; exports.V4_SWAP = _chunkO7LQKCBTcjs.V4_SWAP; exports.buildErc20ApprovalCalldata = _chunkO7LQKCBTcjs.buildErc20ApprovalCalldata; exports.buildPermit2ApprovalCalldata = _chunkO7LQKCBTcjs.buildPermit2ApprovalCalldata; exports.buildSwapFromQuote = _chunkO7LQKCBTcjs.buildSwapFromQuote; exports.buildUniversalRouterExecuteArgs = _chunkO7LQKCBTcjs.buildUniversalRouterExecuteArgs; exports.buildV4SwapInput = _chunkO7LQKCBTcjs.buildV4SwapInput; exports.checkAllowance = _chunkO7LQKCBTcjs.checkAllowance; exports.simulateSwap = _chunkO7LQKCBTcjs.simulateSwap;
|
|
29
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/swap/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,ksBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/swap/index.cjs"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
import { Q as QuoteResult, e as PathKey } from '../types-CkRJzrZr.cjs';
|
|
3
|
+
|
|
4
|
+
declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
|
|
5
|
+
/**
|
|
6
|
+
* Encode an ERC-20 approve(spender, amount) call.
|
|
7
|
+
*/
|
|
8
|
+
declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
|
|
9
|
+
/**
|
|
10
|
+
* Encode a Permit2 approve(token, spender, amount, expiration) call.
|
|
11
|
+
*/
|
|
12
|
+
declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
|
|
13
|
+
|
|
14
|
+
/** UniversalRouter command byte for V4 swap */
|
|
15
|
+
declare const V4_SWAP: 16;
|
|
16
|
+
declare const SWAP_EXACT_IN: 7;
|
|
17
|
+
declare const SETTLE_ALL: 12;
|
|
18
|
+
declare const TAKE_ALL: 15;
|
|
19
|
+
/**
|
|
20
|
+
* Build the calldata inputs[0] (the V4_SWAP command payload) for
|
|
21
|
+
* UniversalRouter.execute.
|
|
22
|
+
*
|
|
23
|
+
* Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
|
|
24
|
+
*
|
|
25
|
+
* Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
|
|
26
|
+
* are individually ABI-encoded, then wrapped together with the action bytes.
|
|
27
|
+
*/
|
|
28
|
+
declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
|
|
29
|
+
/**
|
|
30
|
+
* Build the full commands + inputs args for UniversalRouter.execute.
|
|
31
|
+
*/
|
|
32
|
+
declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
|
|
33
|
+
commands: Hex;
|
|
34
|
+
inputs: Hex[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Build UniversalRouter execute args from a quote result.
|
|
38
|
+
*
|
|
39
|
+
* Takes the output of `findBestQuote` / `quoteBestRoute` and produces
|
|
40
|
+
* ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
|
|
41
|
+
*
|
|
42
|
+
* @param quote - Quote result containing the path
|
|
43
|
+
* @param currencyIn - Input token address
|
|
44
|
+
* @param currencyOut - Output token address
|
|
45
|
+
* @param amountIn - Exact input amount (same value passed to the quoter)
|
|
46
|
+
* @param minAmountOut - Minimum acceptable output (caller applies slippage)
|
|
47
|
+
*/
|
|
48
|
+
declare function buildSwapFromQuote(params: {
|
|
49
|
+
quote: QuoteResult;
|
|
50
|
+
currencyIn: Address;
|
|
51
|
+
currencyOut: Address;
|
|
52
|
+
amountIn: bigint;
|
|
53
|
+
minAmountOut: bigint;
|
|
54
|
+
}): {
|
|
55
|
+
commands: Hex;
|
|
56
|
+
inputs: Hex[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
interface SwapSimulationResult {
|
|
60
|
+
success: boolean;
|
|
61
|
+
gasEstimate: bigint;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
|
|
65
|
+
*
|
|
66
|
+
* Runs the full V4 swap flow — token transfer via Permit2, swap via
|
|
67
|
+
* PoolManager, output settlement — without submitting a transaction.
|
|
68
|
+
* If the simulation reverts, throws a `SimulationError` with the reason.
|
|
69
|
+
*
|
|
70
|
+
* @param client - viem PublicClient
|
|
71
|
+
* @param routerAddress - UniversalRouter contract address
|
|
72
|
+
* @param commands - Packed command bytes (from buildSwapFromQuote)
|
|
73
|
+
* @param inputs - Encoded inputs per command (from buildSwapFromQuote)
|
|
74
|
+
* @param deadline - Unix timestamp after which the tx expires
|
|
75
|
+
* @param from - Address that will execute the swap
|
|
76
|
+
*/
|
|
77
|
+
declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
|
|
78
|
+
|
|
79
|
+
export { SETTLE_ALL, SWAP_EXACT_IN, type SwapSimulationResult, TAKE_ALL, V4_SWAP, buildErc20ApprovalCalldata, buildPermit2ApprovalCalldata, buildSwapFromQuote, buildUniversalRouterExecuteArgs, buildV4SwapInput, checkAllowance, simulateSwap };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
import { Q as QuoteResult, e as PathKey } from '../types-CkRJzrZr.js';
|
|
3
|
+
|
|
4
|
+
declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
|
|
5
|
+
/**
|
|
6
|
+
* Encode an ERC-20 approve(spender, amount) call.
|
|
7
|
+
*/
|
|
8
|
+
declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
|
|
9
|
+
/**
|
|
10
|
+
* Encode a Permit2 approve(token, spender, amount, expiration) call.
|
|
11
|
+
*/
|
|
12
|
+
declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
|
|
13
|
+
|
|
14
|
+
/** UniversalRouter command byte for V4 swap */
|
|
15
|
+
declare const V4_SWAP: 16;
|
|
16
|
+
declare const SWAP_EXACT_IN: 7;
|
|
17
|
+
declare const SETTLE_ALL: 12;
|
|
18
|
+
declare const TAKE_ALL: 15;
|
|
19
|
+
/**
|
|
20
|
+
* Build the calldata inputs[0] (the V4_SWAP command payload) for
|
|
21
|
+
* UniversalRouter.execute.
|
|
22
|
+
*
|
|
23
|
+
* Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
|
|
24
|
+
*
|
|
25
|
+
* Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
|
|
26
|
+
* are individually ABI-encoded, then wrapped together with the action bytes.
|
|
27
|
+
*/
|
|
28
|
+
declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
|
|
29
|
+
/**
|
|
30
|
+
* Build the full commands + inputs args for UniversalRouter.execute.
|
|
31
|
+
*/
|
|
32
|
+
declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
|
|
33
|
+
commands: Hex;
|
|
34
|
+
inputs: Hex[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Build UniversalRouter execute args from a quote result.
|
|
38
|
+
*
|
|
39
|
+
* Takes the output of `findBestQuote` / `quoteBestRoute` and produces
|
|
40
|
+
* ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
|
|
41
|
+
*
|
|
42
|
+
* @param quote - Quote result containing the path
|
|
43
|
+
* @param currencyIn - Input token address
|
|
44
|
+
* @param currencyOut - Output token address
|
|
45
|
+
* @param amountIn - Exact input amount (same value passed to the quoter)
|
|
46
|
+
* @param minAmountOut - Minimum acceptable output (caller applies slippage)
|
|
47
|
+
*/
|
|
48
|
+
declare function buildSwapFromQuote(params: {
|
|
49
|
+
quote: QuoteResult;
|
|
50
|
+
currencyIn: Address;
|
|
51
|
+
currencyOut: Address;
|
|
52
|
+
amountIn: bigint;
|
|
53
|
+
minAmountOut: bigint;
|
|
54
|
+
}): {
|
|
55
|
+
commands: Hex;
|
|
56
|
+
inputs: Hex[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
interface SwapSimulationResult {
|
|
60
|
+
success: boolean;
|
|
61
|
+
gasEstimate: bigint;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
|
|
65
|
+
*
|
|
66
|
+
* Runs the full V4 swap flow — token transfer via Permit2, swap via
|
|
67
|
+
* PoolManager, output settlement — without submitting a transaction.
|
|
68
|
+
* If the simulation reverts, throws a `SimulationError` with the reason.
|
|
69
|
+
*
|
|
70
|
+
* @param client - viem PublicClient
|
|
71
|
+
* @param routerAddress - UniversalRouter contract address
|
|
72
|
+
* @param commands - Packed command bytes (from buildSwapFromQuote)
|
|
73
|
+
* @param inputs - Encoded inputs per command (from buildSwapFromQuote)
|
|
74
|
+
* @param deadline - Unix timestamp after which the tx expires
|
|
75
|
+
* @param from - Address that will execute the swap
|
|
76
|
+
*/
|
|
77
|
+
declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
|
|
78
|
+
|
|
79
|
+
export { SETTLE_ALL, SWAP_EXACT_IN, type SwapSimulationResult, TAKE_ALL, V4_SWAP, buildErc20ApprovalCalldata, buildPermit2ApprovalCalldata, buildSwapFromQuote, buildUniversalRouterExecuteArgs, buildV4SwapInput, checkAllowance, simulateSwap };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SETTLE_ALL,
|
|
3
|
+
SWAP_EXACT_IN,
|
|
4
|
+
TAKE_ALL,
|
|
5
|
+
V4_SWAP,
|
|
6
|
+
buildErc20ApprovalCalldata,
|
|
7
|
+
buildPermit2ApprovalCalldata,
|
|
8
|
+
buildSwapFromQuote,
|
|
9
|
+
buildUniversalRouterExecuteArgs,
|
|
10
|
+
buildV4SwapInput,
|
|
11
|
+
checkAllowance,
|
|
12
|
+
simulateSwap
|
|
13
|
+
} from "../chunk-37BBGXTS.js";
|
|
14
|
+
import "../chunk-2PIXFXA2.js";
|
|
15
|
+
import "../chunk-P56TUGTS.js";
|
|
16
|
+
export {
|
|
17
|
+
SETTLE_ALL,
|
|
18
|
+
SWAP_EXACT_IN,
|
|
19
|
+
TAKE_ALL,
|
|
20
|
+
V4_SWAP,
|
|
21
|
+
buildErc20ApprovalCalldata,
|
|
22
|
+
buildPermit2ApprovalCalldata,
|
|
23
|
+
buildSwapFromQuote,
|
|
24
|
+
buildUniversalRouterExecuteArgs,
|
|
25
|
+
buildV4SwapInput,
|
|
26
|
+
checkAllowance,
|
|
27
|
+
simulateSwap
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
2
|
+
|
|
3
|
+
/** MintRequest(address to,uint256 amount,uint256 nonce,uint256 deadline) */
|
|
4
|
+
interface MintRequest {
|
|
5
|
+
to: Address;
|
|
6
|
+
amount: bigint;
|
|
7
|
+
nonce: bigint;
|
|
8
|
+
deadline: bigint;
|
|
9
|
+
}
|
|
10
|
+
/** ReceiverConsent(address onBehalfOf,address originalReceiver,uint256 amount,uint256 nonce,uint256 deadline,bytes extData) */
|
|
11
|
+
interface ReceiverConsent {
|
|
12
|
+
onBehalfOf: Address;
|
|
13
|
+
originalReceiver: Address;
|
|
14
|
+
amount: bigint;
|
|
15
|
+
nonce: bigint;
|
|
16
|
+
deadline: bigint;
|
|
17
|
+
extData: Hex;
|
|
18
|
+
}
|
|
19
|
+
interface EIP712Signature {
|
|
20
|
+
v: number;
|
|
21
|
+
r: Hex;
|
|
22
|
+
s: Hex;
|
|
23
|
+
serialized: Hex;
|
|
24
|
+
}
|
|
25
|
+
interface PointTokenDomainConfig {
|
|
26
|
+
name: string;
|
|
27
|
+
verifyingContract: Address;
|
|
28
|
+
chainId: number;
|
|
29
|
+
}
|
|
30
|
+
interface SignatureVerification {
|
|
31
|
+
isValid: boolean;
|
|
32
|
+
recoveredAddress: Address;
|
|
33
|
+
}
|
|
34
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
35
|
+
interface MintParams {
|
|
36
|
+
pointToken: Address;
|
|
37
|
+
receiver: Address;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
deadline: bigint;
|
|
40
|
+
minterSig: Hex;
|
|
41
|
+
receiverSig: Hex;
|
|
42
|
+
extData: Hex;
|
|
43
|
+
}
|
|
44
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
45
|
+
interface PathKey {
|
|
46
|
+
intermediateCurrency: Address;
|
|
47
|
+
fee: number;
|
|
48
|
+
tickSpacing: number;
|
|
49
|
+
hooks: Address;
|
|
50
|
+
hookData: Hex;
|
|
51
|
+
}
|
|
52
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
53
|
+
interface SwapParams {
|
|
54
|
+
path: PathKey[];
|
|
55
|
+
deadline: bigint;
|
|
56
|
+
}
|
|
57
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
58
|
+
interface Issuer {
|
|
59
|
+
issuerAddress: Address;
|
|
60
|
+
signerAddress: Address;
|
|
61
|
+
name: string;
|
|
62
|
+
symbol: string;
|
|
63
|
+
declaredTotalSupply: bigint;
|
|
64
|
+
capBasisPoints: number;
|
|
65
|
+
active: boolean;
|
|
66
|
+
pointToken: Address;
|
|
67
|
+
mintingOracle: Address;
|
|
68
|
+
}
|
|
69
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
70
|
+
interface PoolKey {
|
|
71
|
+
currency0: Address;
|
|
72
|
+
currency1: Address;
|
|
73
|
+
fee: number;
|
|
74
|
+
tickSpacing: number;
|
|
75
|
+
hooks: Address;
|
|
76
|
+
}
|
|
77
|
+
interface ChainConfig {
|
|
78
|
+
name: string;
|
|
79
|
+
}
|
|
80
|
+
interface QuoteResult {
|
|
81
|
+
amountOut: bigint;
|
|
82
|
+
gasEstimate: bigint;
|
|
83
|
+
path: PathKey[];
|
|
84
|
+
}
|
|
85
|
+
interface BestQuote {
|
|
86
|
+
bestRoute: QuoteResult;
|
|
87
|
+
allRoutes: QuoteResult[];
|
|
88
|
+
}
|
|
89
|
+
interface PafiSDKConfig {
|
|
90
|
+
pointTokenAddress?: Address;
|
|
91
|
+
relayContractAddress?: Address;
|
|
92
|
+
signer?: WalletClient;
|
|
93
|
+
provider?: PublicClient;
|
|
94
|
+
rpcUrl?: string;
|
|
95
|
+
chainId?: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type { BestQuote as B, ChainConfig as C, EIP712Signature as E, Issuer as I, MintRequest as M, PoolKey as P, QuoteResult as Q, ReceiverConsent as R, SignatureVerification as S, PafiSDKConfig as a, PointTokenDomainConfig as b, MintParams as c, SwapParams as d, PathKey as e };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
2
|
+
|
|
3
|
+
/** MintRequest(address to,uint256 amount,uint256 nonce,uint256 deadline) */
|
|
4
|
+
interface MintRequest {
|
|
5
|
+
to: Address;
|
|
6
|
+
amount: bigint;
|
|
7
|
+
nonce: bigint;
|
|
8
|
+
deadline: bigint;
|
|
9
|
+
}
|
|
10
|
+
/** ReceiverConsent(address onBehalfOf,address originalReceiver,uint256 amount,uint256 nonce,uint256 deadline,bytes extData) */
|
|
11
|
+
interface ReceiverConsent {
|
|
12
|
+
onBehalfOf: Address;
|
|
13
|
+
originalReceiver: Address;
|
|
14
|
+
amount: bigint;
|
|
15
|
+
nonce: bigint;
|
|
16
|
+
deadline: bigint;
|
|
17
|
+
extData: Hex;
|
|
18
|
+
}
|
|
19
|
+
interface EIP712Signature {
|
|
20
|
+
v: number;
|
|
21
|
+
r: Hex;
|
|
22
|
+
s: Hex;
|
|
23
|
+
serialized: Hex;
|
|
24
|
+
}
|
|
25
|
+
interface PointTokenDomainConfig {
|
|
26
|
+
name: string;
|
|
27
|
+
verifyingContract: Address;
|
|
28
|
+
chainId: number;
|
|
29
|
+
}
|
|
30
|
+
interface SignatureVerification {
|
|
31
|
+
isValid: boolean;
|
|
32
|
+
recoveredAddress: Address;
|
|
33
|
+
}
|
|
34
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
35
|
+
interface MintParams {
|
|
36
|
+
pointToken: Address;
|
|
37
|
+
receiver: Address;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
deadline: bigint;
|
|
40
|
+
minterSig: Hex;
|
|
41
|
+
receiverSig: Hex;
|
|
42
|
+
extData: Hex;
|
|
43
|
+
}
|
|
44
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
45
|
+
interface PathKey {
|
|
46
|
+
intermediateCurrency: Address;
|
|
47
|
+
fee: number;
|
|
48
|
+
tickSpacing: number;
|
|
49
|
+
hooks: Address;
|
|
50
|
+
hookData: Hex;
|
|
51
|
+
}
|
|
52
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
53
|
+
interface SwapParams {
|
|
54
|
+
path: PathKey[];
|
|
55
|
+
deadline: bigint;
|
|
56
|
+
}
|
|
57
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
58
|
+
interface Issuer {
|
|
59
|
+
issuerAddress: Address;
|
|
60
|
+
signerAddress: Address;
|
|
61
|
+
name: string;
|
|
62
|
+
symbol: string;
|
|
63
|
+
declaredTotalSupply: bigint;
|
|
64
|
+
capBasisPoints: number;
|
|
65
|
+
active: boolean;
|
|
66
|
+
pointToken: Address;
|
|
67
|
+
mintingOracle: Address;
|
|
68
|
+
}
|
|
69
|
+
/** Auto-generated from Solidity struct — do not edit */
|
|
70
|
+
interface PoolKey {
|
|
71
|
+
currency0: Address;
|
|
72
|
+
currency1: Address;
|
|
73
|
+
fee: number;
|
|
74
|
+
tickSpacing: number;
|
|
75
|
+
hooks: Address;
|
|
76
|
+
}
|
|
77
|
+
interface ChainConfig {
|
|
78
|
+
name: string;
|
|
79
|
+
}
|
|
80
|
+
interface QuoteResult {
|
|
81
|
+
amountOut: bigint;
|
|
82
|
+
gasEstimate: bigint;
|
|
83
|
+
path: PathKey[];
|
|
84
|
+
}
|
|
85
|
+
interface BestQuote {
|
|
86
|
+
bestRoute: QuoteResult;
|
|
87
|
+
allRoutes: QuoteResult[];
|
|
88
|
+
}
|
|
89
|
+
interface PafiSDKConfig {
|
|
90
|
+
pointTokenAddress?: Address;
|
|
91
|
+
relayContractAddress?: Address;
|
|
92
|
+
signer?: WalletClient;
|
|
93
|
+
provider?: PublicClient;
|
|
94
|
+
rpcUrl?: string;
|
|
95
|
+
chainId?: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type { BestQuote as B, ChainConfig as C, EIP712Signature as E, Issuer as I, MintRequest as M, PoolKey as P, QuoteResult as Q, ReceiverConsent as R, SignatureVerification as S, PafiSDKConfig as a, PointTokenDomainConfig as b, MintParams as c, SwapParams as d, PathKey as e };
|
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pafi-dev/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "EIP-712 signing, contract interaction, and Relay calldata for the PAFI point token system",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./abi": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/abi/index.d.ts",
|
|
23
|
+
"default": "./dist/abi/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/abi/index.d.cts",
|
|
27
|
+
"default": "./dist/abi/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./eip712": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/eip712/index.d.ts",
|
|
33
|
+
"default": "./dist/eip712/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/eip712/index.d.cts",
|
|
37
|
+
"default": "./dist/eip712/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./relay": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/relay/index.d.ts",
|
|
43
|
+
"default": "./dist/relay/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/relay/index.d.cts",
|
|
47
|
+
"default": "./dist/relay/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./quoting": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/quoting/index.d.ts",
|
|
53
|
+
"default": "./dist/quoting/index.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/quoting/index.d.cts",
|
|
57
|
+
"default": "./dist/quoting/index.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./swap": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/swap/index.d.ts",
|
|
63
|
+
"default": "./dist/swap/index.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/swap/index.d.cts",
|
|
67
|
+
"default": "./dist/swap/index.cjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./contract": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/contract/index.d.ts",
|
|
73
|
+
"default": "./dist/contract/index.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/contract/index.d.cts",
|
|
77
|
+
"default": "./dist/contract/index.cjs"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"./auth": {
|
|
81
|
+
"import": {
|
|
82
|
+
"types": "./dist/auth/index.d.ts",
|
|
83
|
+
"default": "./dist/auth/index.js"
|
|
84
|
+
},
|
|
85
|
+
"require": {
|
|
86
|
+
"types": "./dist/auth/index.d.cts",
|
|
87
|
+
"default": "./dist/auth/index.cjs"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"files": [
|
|
92
|
+
"dist"
|
|
93
|
+
],
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"viem": "^2.0.0"
|
|
96
|
+
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"tsx": "^4.0.0",
|
|
99
|
+
"viem": "^2.21.0",
|
|
100
|
+
"typescript": "^5.5.0",
|
|
101
|
+
"tsup": "^8.0.0",
|
|
102
|
+
"vitest": "^2.0.0"
|
|
103
|
+
},
|
|
104
|
+
"license": "Apache-2.0",
|
|
105
|
+
"scripts": {
|
|
106
|
+
"generate": "tsx scripts/generate-abis.ts",
|
|
107
|
+
"build": "tsup",
|
|
108
|
+
"test": "vitest run",
|
|
109
|
+
"test:watch": "vitest",
|
|
110
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
111
|
+
"test:fork": "vitest run --config vitest.fork.config.ts",
|
|
112
|
+
"typecheck": "tsc --noEmit"
|
|
113
|
+
}
|
|
114
|
+
}
|