@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,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mintRequestTypes,
|
|
3
|
+
receiverConsentTypes
|
|
4
|
+
} from "./chunk-R4L66ZR5.js";
|
|
5
|
+
|
|
6
|
+
// src/eip712/domain.ts
|
|
7
|
+
function buildDomain(config) {
|
|
8
|
+
return {
|
|
9
|
+
name: config.name,
|
|
10
|
+
version: "1",
|
|
11
|
+
chainId: config.chainId,
|
|
12
|
+
verifyingContract: config.verifyingContract
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/eip712/mintRequest.ts
|
|
17
|
+
import { getAddress, parseSignature, recoverTypedDataAddress } from "viem";
|
|
18
|
+
function buildMintRequestTypedData(domain, message) {
|
|
19
|
+
return {
|
|
20
|
+
domain: buildDomain(domain),
|
|
21
|
+
types: mintRequestTypes,
|
|
22
|
+
primaryType: "MintRequest",
|
|
23
|
+
message
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function signMintRequest(walletClient, domain, message) {
|
|
27
|
+
const serialized = await walletClient.signTypedData({
|
|
28
|
+
account: walletClient.account,
|
|
29
|
+
domain: buildDomain(domain),
|
|
30
|
+
types: mintRequestTypes,
|
|
31
|
+
primaryType: "MintRequest",
|
|
32
|
+
message
|
|
33
|
+
});
|
|
34
|
+
const { v, r, s } = parseSignature(serialized);
|
|
35
|
+
return {
|
|
36
|
+
v: Number(v),
|
|
37
|
+
r,
|
|
38
|
+
s,
|
|
39
|
+
serialized
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function verifyMintRequest(domain, message, signature, expectedMinter) {
|
|
43
|
+
const recoveredAddress = await recoverTypedDataAddress({
|
|
44
|
+
domain: buildDomain(domain),
|
|
45
|
+
types: mintRequestTypes,
|
|
46
|
+
primaryType: "MintRequest",
|
|
47
|
+
message,
|
|
48
|
+
signature
|
|
49
|
+
});
|
|
50
|
+
const isValid = getAddress(recoveredAddress) === getAddress(expectedMinter);
|
|
51
|
+
return { isValid, recoveredAddress };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/eip712/receiverConsent.ts
|
|
55
|
+
import { getAddress as getAddress2, parseSignature as parseSignature2, recoverTypedDataAddress as recoverTypedDataAddress2 } from "viem";
|
|
56
|
+
function buildReceiverConsentTypedData(domain, message) {
|
|
57
|
+
return {
|
|
58
|
+
domain: buildDomain(domain),
|
|
59
|
+
types: receiverConsentTypes,
|
|
60
|
+
primaryType: "ReceiverConsent",
|
|
61
|
+
message
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async function signReceiverConsent(walletClient, domain, message) {
|
|
65
|
+
const serialized = await walletClient.signTypedData({
|
|
66
|
+
account: walletClient.account,
|
|
67
|
+
domain: buildDomain(domain),
|
|
68
|
+
types: receiverConsentTypes,
|
|
69
|
+
primaryType: "ReceiverConsent",
|
|
70
|
+
message
|
|
71
|
+
});
|
|
72
|
+
const { v, r, s } = parseSignature2(serialized);
|
|
73
|
+
return {
|
|
74
|
+
v: Number(v),
|
|
75
|
+
r,
|
|
76
|
+
s,
|
|
77
|
+
serialized
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function verifyReceiverConsent(domain, message, signature, expectedReceiver) {
|
|
81
|
+
const recoveredAddress = await recoverTypedDataAddress2({
|
|
82
|
+
domain: buildDomain(domain),
|
|
83
|
+
types: receiverConsentTypes,
|
|
84
|
+
primaryType: "ReceiverConsent",
|
|
85
|
+
message,
|
|
86
|
+
signature
|
|
87
|
+
});
|
|
88
|
+
const isValid = getAddress2(recoveredAddress) === getAddress2(expectedReceiver);
|
|
89
|
+
return { isValid, recoveredAddress };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
buildDomain,
|
|
94
|
+
buildMintRequestTypedData,
|
|
95
|
+
signMintRequest,
|
|
96
|
+
verifyMintRequest,
|
|
97
|
+
buildReceiverConsentTypedData,
|
|
98
|
+
signReceiverConsent,
|
|
99
|
+
verifyReceiverConsent
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=chunk-C4ZDYG4D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eip712/domain.ts","../src/eip712/mintRequest.ts","../src/eip712/receiverConsent.ts"],"sourcesContent":["import type { PointTokenDomainConfig } from \"../types\";\n\nexport function buildDomain(config: PointTokenDomainConfig) {\n return {\n name: config.name,\n version: \"1\" as const,\n chainId: config.chainId,\n verifyingContract: config.verifyingContract,\n };\n}\n","import { getAddress, parseSignature, recoverTypedDataAddress } from \"viem\";\nimport type { Address, Hex, WalletClient } from \"viem\";\nimport { mintRequestTypes } from \"../constants\";\nimport type { EIP712Signature, MintRequest, PointTokenDomainConfig, SignatureVerification } from \"../types\";\nimport { buildDomain } from \"./domain\";\n\n/**\n * Build the EIP-712 typed data object for a MintRequest.\n * Returns the standard `{ domain, types, primaryType, message }` structure\n * that any EIP-712 signer (viem, ethers, Privy, WalletConnect) can consume.\n */\nexport function buildMintRequestTypedData(\n domain: PointTokenDomainConfig,\n message: MintRequest,\n) {\n return {\n domain: buildDomain(domain),\n types: mintRequestTypes,\n primaryType: \"MintRequest\" as const,\n message,\n };\n}\n\nexport async function signMintRequest(\n walletClient: WalletClient,\n domain: PointTokenDomainConfig,\n message: MintRequest,\n): Promise<EIP712Signature> {\n const serialized = await walletClient.signTypedData({\n account: walletClient.account!,\n domain: buildDomain(domain),\n types: mintRequestTypes,\n primaryType: \"MintRequest\",\n message,\n });\n\n const { v, r, s } = parseSignature(serialized);\n\n return {\n v: Number(v),\n r,\n s,\n serialized,\n };\n}\n\nexport async function verifyMintRequest(\n domain: PointTokenDomainConfig,\n message: MintRequest,\n signature: Hex,\n expectedMinter: Address,\n): Promise<SignatureVerification> {\n const recoveredAddress = await recoverTypedDataAddress({\n domain: buildDomain(domain),\n types: mintRequestTypes,\n primaryType: \"MintRequest\",\n message,\n signature,\n });\n\n const isValid = getAddress(recoveredAddress) === getAddress(expectedMinter);\n\n return { isValid, recoveredAddress };\n}\n","import { getAddress, parseSignature, recoverTypedDataAddress } from \"viem\";\nimport type { Address, Hex, WalletClient } from \"viem\";\nimport { receiverConsentTypes } from \"../constants\";\nimport type { EIP712Signature, PointTokenDomainConfig, ReceiverConsent, SignatureVerification } from \"../types\";\nimport { buildDomain } from \"./domain\";\n\n/**\n * Build the EIP-712 typed data object for a ReceiverConsent.\n * Returns the standard `{ domain, types, primaryType, message }` structure\n * that any EIP-712 signer (viem, ethers, Privy, WalletConnect) can consume.\n */\nexport function buildReceiverConsentTypedData(\n domain: PointTokenDomainConfig,\n message: ReceiverConsent,\n) {\n return {\n domain: buildDomain(domain),\n types: receiverConsentTypes,\n primaryType: \"ReceiverConsent\" as const,\n message,\n };\n}\n\nexport async function signReceiverConsent(\n walletClient: WalletClient,\n domain: PointTokenDomainConfig,\n message: ReceiverConsent,\n): Promise<EIP712Signature> {\n const serialized = await walletClient.signTypedData({\n account: walletClient.account!,\n domain: buildDomain(domain),\n types: receiverConsentTypes,\n primaryType: \"ReceiverConsent\",\n message,\n });\n\n const { v, r, s } = parseSignature(serialized);\n\n return {\n v: Number(v),\n r,\n s,\n serialized,\n };\n}\n\nexport async function verifyReceiverConsent(\n domain: PointTokenDomainConfig,\n message: ReceiverConsent,\n signature: Hex,\n expectedReceiver: Address,\n): Promise<SignatureVerification> {\n const recoveredAddress = await recoverTypedDataAddress({\n domain: buildDomain(domain),\n types: receiverConsentTypes,\n primaryType: \"ReceiverConsent\",\n message,\n signature,\n });\n\n const isValid = getAddress(recoveredAddress) === getAddress(expectedReceiver);\n\n return { isValid, recoveredAddress };\n}\n"],"mappings":";;;;;;AAEO,SAAS,YAAY,QAAgC;AAC1D,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,SAAS;AAAA,IACT,SAAS,OAAO;AAAA,IAChB,mBAAmB,OAAO;AAAA,EAC5B;AACF;;;ACTA,SAAS,YAAY,gBAAgB,+BAA+B;AAW7D,SAAS,0BACd,QACA,SACA;AACA,SAAO;AAAA,IACL,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF;AACF;AAEA,eAAsB,gBACpB,cACA,QACA,SAC0B;AAC1B,QAAM,aAAa,MAAM,aAAa,cAAc;AAAA,IAClD,SAAS,aAAa;AAAA,IACtB,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF,CAAC;AAED,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,eAAe,UAAU;AAE7C,SAAO;AAAA,IACL,GAAG,OAAO,CAAC;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,kBACpB,QACA,SACA,WACA,gBACgC;AAChC,QAAM,mBAAmB,MAAM,wBAAwB;AAAA,IACrD,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,UAAU,WAAW,gBAAgB,MAAM,WAAW,cAAc;AAE1E,SAAO,EAAE,SAAS,iBAAiB;AACrC;;;AC/DA,SAAS,cAAAA,aAAY,kBAAAC,iBAAgB,2BAAAC,gCAA+B;AAW7D,SAAS,8BACd,QACA,SACA;AACA,SAAO;AAAA,IACL,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF;AACF;AAEA,eAAsB,oBACpB,cACA,QACA,SAC0B;AAC1B,QAAM,aAAa,MAAM,aAAa,cAAc;AAAA,IAClD,SAAS,aAAa;AAAA,IACtB,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF,CAAC;AAED,QAAM,EAAE,GAAG,GAAG,EAAE,IAAIC,gBAAe,UAAU;AAE7C,SAAO;AAAA,IACL,GAAG,OAAO,CAAC;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,sBACpB,QACA,SACA,WACA,kBACgC;AAChC,QAAM,mBAAmB,MAAMC,yBAAwB;AAAA,IACrD,QAAQ,YAAY,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,UAAUC,YAAW,gBAAgB,MAAMA,YAAW,gBAAgB;AAE5E,SAAO,EAAE,SAAS,iBAAiB;AACrC;","names":["getAddress","parseSignature","recoverTypedDataAddress","parseSignature","recoverTypedDataAddress","getAddress"]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkCL3QSI4Ocjs = require('./chunk-CL3QSI4O.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkCWP4PFOPcjs = require('./chunk-CWP4PFOP.cjs');
|
|
9
|
+
|
|
10
|
+
// src/quoting/routes.ts
|
|
11
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
12
|
+
function combineRoutes(chainId, pointTokenAddress) {
|
|
13
|
+
const commonPools = _nullishCoalesce(_chunkCWP4PFOPcjs.COMMON_POOLS[chainId], () => ( []));
|
|
14
|
+
const pointPools = _nullishCoalesce(_optionalChain([_chunkCWP4PFOPcjs.POINT_TOKEN_POOLS, 'access', _ => _[chainId], 'optionalAccess', _2 => _2[pointTokenAddress]]), () => ( []));
|
|
15
|
+
return [...pointPools, ...commonPools];
|
|
16
|
+
}
|
|
17
|
+
function buildAllPaths(pools, tokenIn, tokenOut, maxHops = 3) {
|
|
18
|
+
const results = [];
|
|
19
|
+
function dfs(currentToken, currentPath, usedPoolIndices) {
|
|
20
|
+
if (currentPath.length > maxHops) return;
|
|
21
|
+
if (currentPath.length > 0 && currentToken.toLowerCase() === tokenOut.toLowerCase()) {
|
|
22
|
+
results.push([...currentPath]);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < pools.length; i++) {
|
|
26
|
+
if (usedPoolIndices.has(i)) continue;
|
|
27
|
+
const pool = pools[i];
|
|
28
|
+
const c0 = pool.currency0.toLowerCase();
|
|
29
|
+
const c1 = pool.currency1.toLowerCase();
|
|
30
|
+
const curr = currentToken.toLowerCase();
|
|
31
|
+
let nextToken = null;
|
|
32
|
+
if (curr === c0) {
|
|
33
|
+
nextToken = pool.currency1;
|
|
34
|
+
} else if (curr === c1) {
|
|
35
|
+
nextToken = pool.currency0;
|
|
36
|
+
}
|
|
37
|
+
if (!nextToken) continue;
|
|
38
|
+
const hop = {
|
|
39
|
+
intermediateCurrency: nextToken,
|
|
40
|
+
fee: pool.fee,
|
|
41
|
+
tickSpacing: pool.tickSpacing,
|
|
42
|
+
hooks: _nullishCoalesce(pool.hooks, () => ( ZERO_ADDRESS)),
|
|
43
|
+
hookData: "0x"
|
|
44
|
+
};
|
|
45
|
+
usedPoolIndices.add(i);
|
|
46
|
+
currentPath.push(hop);
|
|
47
|
+
dfs(nextToken, currentPath, usedPoolIndices);
|
|
48
|
+
currentPath.pop();
|
|
49
|
+
usedPoolIndices.delete(i);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
dfs(tokenIn, [], /* @__PURE__ */ new Set());
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/quoting/quote.ts
|
|
57
|
+
async function quoteExactInput(client, quoterAddress, exactCurrency, path, exactAmount) {
|
|
58
|
+
const [amountOut, gasEstimate] = await client.readContract({
|
|
59
|
+
address: quoterAddress,
|
|
60
|
+
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
61
|
+
functionName: "quoteExactInput",
|
|
62
|
+
args: [{ exactCurrency, path, exactAmount: BigInt(exactAmount) }]
|
|
63
|
+
});
|
|
64
|
+
return { amountOut, gasEstimate, path };
|
|
65
|
+
}
|
|
66
|
+
async function quoteExactInputSingle(client, quoterAddress, poolKey, zeroForOne, exactAmount, hookData) {
|
|
67
|
+
const [amountOut, gasEstimate] = await client.readContract({
|
|
68
|
+
address: quoterAddress,
|
|
69
|
+
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
70
|
+
functionName: "quoteExactInputSingle",
|
|
71
|
+
args: [
|
|
72
|
+
{
|
|
73
|
+
poolKey,
|
|
74
|
+
zeroForOne,
|
|
75
|
+
exactAmount: BigInt(exactAmount),
|
|
76
|
+
hookData
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
return { amountOut, gasEstimate };
|
|
81
|
+
}
|
|
82
|
+
async function quoteBestRoute(client, quoterAddress, exactCurrency, routes, exactAmount) {
|
|
83
|
+
const results = await client.multicall({
|
|
84
|
+
contracts: routes.map((path) => ({
|
|
85
|
+
address: quoterAddress,
|
|
86
|
+
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
87
|
+
functionName: "quoteExactInput",
|
|
88
|
+
args: [
|
|
89
|
+
{
|
|
90
|
+
exactCurrency,
|
|
91
|
+
path,
|
|
92
|
+
exactAmount: BigInt(exactAmount)
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
})),
|
|
96
|
+
allowFailure: true
|
|
97
|
+
});
|
|
98
|
+
const allRoutes = [];
|
|
99
|
+
for (let i = 0; i < results.length; i++) {
|
|
100
|
+
const r = results[i];
|
|
101
|
+
if (r.status === "success") {
|
|
102
|
+
const [amountOut, gasEstimate] = r.result;
|
|
103
|
+
allRoutes.push({ amountOut, gasEstimate, path: routes[i] });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (allRoutes.length === 0) {
|
|
107
|
+
throw new Error("No valid routes found");
|
|
108
|
+
}
|
|
109
|
+
const bestRoute = allRoutes.reduce(
|
|
110
|
+
(best, current) => current.amountOut > best.amountOut ? current : best
|
|
111
|
+
);
|
|
112
|
+
return { bestRoute, allRoutes };
|
|
113
|
+
}
|
|
114
|
+
async function findBestQuote(client, chainId, tokenIn, tokenOut, exactAmount, pools = [], quoterAddress, maxHops = 3) {
|
|
115
|
+
const quoter = _nullishCoalesce(quoterAddress, () => ( _chunkCWP4PFOPcjs.V4_QUOTER_ADDRESSES[chainId]));
|
|
116
|
+
if (!quoter) {
|
|
117
|
+
throw new Error(`No V4 Quoter address configured for chain ${chainId}`);
|
|
118
|
+
}
|
|
119
|
+
const commonPools = _nullishCoalesce(_chunkCWP4PFOPcjs.COMMON_POOLS[chainId], () => ( []));
|
|
120
|
+
const allPools = [...pools, ...commonPools];
|
|
121
|
+
const paths = buildAllPaths(allPools, tokenIn, tokenOut, maxHops);
|
|
122
|
+
if (paths.length === 0) {
|
|
123
|
+
throw new Error(`No paths found from ${tokenIn} to ${tokenOut}`);
|
|
124
|
+
}
|
|
125
|
+
return quoteBestRoute(client, quoter, tokenIn, paths, exactAmount);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
exports.combineRoutes = combineRoutes; exports.buildAllPaths = buildAllPaths; exports.quoteExactInput = quoteExactInput; exports.quoteExactInputSingle = quoteExactInputSingle; exports.quoteBestRoute = quoteBestRoute; exports.findBestQuote = findBestQuote;
|
|
136
|
+
//# sourceMappingURL=chunk-CAE2BVKI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CAE2BVKI.cjs","../src/quoting/routes.ts","../src/quoting/quote.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,IAAM,aAAA,EAAe,4CAAA;AAMd,SAAS,aAAA,CACd,OAAA,EACA,iBAAA,EACW;AACX,EAAA,MAAM,YAAA,mBAAc,8BAAA,CAAa,OAAO,CAAA,UAAK,CAAC,GAAA;AAC9C,EAAA,MAAM,WAAA,mCAAa,mCAAA,mBAAkB,OAAO,CAAA,4BAAA,CAAI,iBAAiB,GAAA,UAAK,CAAC,GAAA;AACvE,EAAA,OAAO,CAAC,GAAG,UAAA,EAAY,GAAG,WAAW,CAAA;AACvC;AAcO,SAAS,aAAA,CACd,KAAA,EACA,OAAA,EACA,QAAA,EACA,QAAA,EAAU,CAAA,EACG;AACb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AAC,CAAA;AAAA,IAC7D;AAAA,EACF;AAEA,EAAA,GAAA,CAAI,SAAA,CAAU,OAAA,IAAW,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAI,KAAA,CAAM,uBAAuB,CAAA;AAAA,EACzC;AAEA,EAAA,MAAM,UAAA,EAAY,SAAA,CAAU,MAAA;AAAA,IAAO,CAAC,IAAA,EAAM,OAAA,EAAA,GACxC,OAAA,CAAQ,UAAA,EAAY,IAAA,CAAK,UAAA,EAAY,QAAA,EAAU;AAAA,EACjD,CAAA;AAEA,EAAA,OAAO,EAAE,SAAA,EAAW,UAAU,CAAA;AAChC;AAkBA,MAAA,SAAsB,aAAA,CACpB,MAAA,EACA,OAAA,EACA,OAAA,EACA,QAAA,EACA,WAAA,EACA,MAAA,EAAmB,CAAC,CAAA,EACpB,aAAA,EACA,QAAA,EAAU,CAAA,EACU;AACpB,EAAA,MAAM,OAAA,mBAAS,aAAA,UAAiB,qCAAA,CAAoB,OAAO,GAAA;AAC3D,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,0CAAA,EAA6C,OAAO,CAAA,CAAA;AACtE,EAAA;AAE8C,EAAA;AACJ,EAAA;AACsB,EAAA;AAExC,EAAA;AACyC,IAAA;AACjE,EAAA;AAEiE,EAAA;AACnE;AFjByE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CAE2BVKI.cjs","sourcesContent":[null,"import type { Address } from \"viem\";\nimport type { PathKey, PoolKey } from \"../types\";\nimport { COMMON_POOLS, POINT_TOKEN_POOLS } from \"../constants\";\n\nconst ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\" as Address;\n\n/**\n * Combine point-token-specific pools and common pools for a given chain.\n * Point token pools are listed first so callers can prioritise them.\n */\nexport function combineRoutes(\n chainId: number,\n pointTokenAddress: Address,\n): PoolKey[] {\n const commonPools = COMMON_POOLS[chainId] ?? [];\n const pointPools = POINT_TOKEN_POOLS[chainId]?.[pointTokenAddress] ?? [];\n return [...pointPools, ...commonPools];\n}\n\n/**\n * Build all possible swap paths from `tokenIn` to `tokenOut` using the given\n * pools. Returns an array of PathKey[] routes (each up to `maxHops` hops).\n *\n * Supports both direct single-hop routes and multi-hop routes through\n * intermediate tokens. Each pool is used at most once per path.\n *\n * @param pools - Available pools to route through\n * @param tokenIn - Input token address\n * @param tokenOut - Desired output token address\n * @param maxHops - Maximum number of hops (default 3)\n */\nexport function buildAllPaths(\n pools: PoolKey[],\n tokenIn: Address,\n tokenOut: Address,\n maxHops = 3,\n): PathKey[][] {\n const results: PathKey[][] = [];\n\n function dfs(\n currentToken: Address,\n currentPath: PathKey[],\n usedPoolIndices: Set<number>,\n ) {\n if (currentPath.length > maxHops) return;\n\n // Check if we've reached the destination\n if (\n currentPath.length > 0 &&\n currentToken.toLowerCase() === tokenOut.toLowerCase()\n ) {\n results.push([...currentPath]);\n return;\n }\n\n for (let i = 0; i < pools.length; i++) {\n if (usedPoolIndices.has(i)) continue;\n\n const pool = pools[i]!;\n const c0 = pool.currency0.toLowerCase();\n const c1 = pool.currency1.toLowerCase();\n const curr = currentToken.toLowerCase();\n\n let nextToken: Address | null = null;\n if (curr === c0) {\n nextToken = pool.currency1 as Address;\n } else if (curr === c1) {\n nextToken = pool.currency0 as Address;\n }\n\n if (!nextToken) continue;\n\n const hop: PathKey = {\n intermediateCurrency: nextToken,\n fee: pool.fee,\n tickSpacing: pool.tickSpacing,\n hooks: pool.hooks ?? ZERO_ADDRESS,\n hookData: \"0x\",\n };\n\n usedPoolIndices.add(i);\n currentPath.push(hop);\n dfs(nextToken, currentPath, usedPoolIndices);\n currentPath.pop();\n usedPoolIndices.delete(i);\n }\n }\n\n dfs(tokenIn, [], new Set());\n return results;\n}\n","import type { Address, PublicClient } from \"viem\";\nimport type { BestQuote, PathKey, PoolKey, QuoteResult } from \"../types\";\nimport { v4QuoterAbi } from \"../abi/v4Quoter\";\nimport { buildAllPaths } from \"./routes\";\nimport { COMMON_POOLS, V4_QUOTER_ADDRESSES } from \"../constants\";\n\n/**\n * Quote exact-input for a multi-hop path.\n */\nexport async function quoteExactInput(\n client: PublicClient,\n quoterAddress: Address,\n exactCurrency: Address,\n path: PathKey[],\n exactAmount: bigint,\n): Promise<QuoteResult> {\n const [amountOut, gasEstimate] = await client.readContract({\n address: quoterAddress,\n abi: v4QuoterAbi,\n functionName: \"quoteExactInput\",\n args: [{ exactCurrency, path, exactAmount: BigInt(exactAmount) as unknown as number }],\n }) as [bigint, bigint];\n\n return { amountOut, gasEstimate, path };\n}\n\n/**\n * Quote exact-input for a single-hop swap, given an explicit PoolKey and direction.\n */\nexport async function quoteExactInputSingle(\n client: PublicClient,\n quoterAddress: Address,\n poolKey: PoolKey,\n zeroForOne: boolean,\n exactAmount: bigint,\n hookData: `0x${string}`,\n): Promise<{ amountOut: bigint; gasEstimate: bigint }> {\n const [amountOut, gasEstimate] = await client.readContract({\n address: quoterAddress,\n abi: v4QuoterAbi,\n functionName: \"quoteExactInputSingle\",\n args: [\n {\n poolKey,\n zeroForOne,\n exactAmount: BigInt(exactAmount) as unknown as number,\n hookData,\n },\n ],\n }) as [bigint, bigint];\n\n return { amountOut, gasEstimate };\n}\n\n/**\n * Try multiple PathKey[] routes and return the best quote plus all results.\n * Routes that fail (e.g. pool does not exist) are silently skipped.\n *\n * Uses viem multicall to batch all quotes into a single RPC call for speed.\n */\nexport async function quoteBestRoute(\n client: PublicClient,\n quoterAddress: Address,\n exactCurrency: Address,\n routes: PathKey[][],\n exactAmount: bigint,\n): Promise<BestQuote> {\n const results = await client.multicall({\n contracts: routes.map((path) => ({\n address: quoterAddress,\n abi: v4QuoterAbi,\n functionName: \"quoteExactInput\" as const,\n args: [\n {\n exactCurrency,\n path,\n exactAmount: BigInt(exactAmount) as unknown as number,\n },\n ],\n })),\n allowFailure: true,\n });\n\n const allRoutes: QuoteResult[] = [];\n for (let i = 0; i < results.length; i++) {\n const r = results[i]!;\n if (r.status === \"success\") {\n const [amountOut, gasEstimate] = r.result as unknown as [bigint, bigint];\n allRoutes.push({ amountOut, gasEstimate, path: routes[i]! });\n }\n }\n\n if (allRoutes.length === 0) {\n throw new Error(\"No valid routes found\");\n }\n\n const bestRoute = allRoutes.reduce((best, current) =>\n current.amountOut > best.amountOut ? current : best,\n );\n\n return { bestRoute, allRoutes };\n}\n\n/**\n * Find and quote the best swap route from `tokenIn` to `tokenOut`.\n *\n * Combines the caller's `pools` with `COMMON_POOLS[chainId]`, builds all\n * possible paths (up to `maxHops`), then quotes them all via a single\n * multicall and returns the best result.\n *\n * @param client - viem PublicClient\n * @param chainId - Chain ID (used to look up COMMON_POOLS and V4_QUOTER_ADDRESSES)\n * @param tokenIn - Input token address\n * @param tokenOut - Desired output token address\n * @param exactAmount - Exact input amount\n * @param pools - Additional pools to consider (e.g. point-token-specific)\n * @param quoterAddress - Override the default V4 Quoter address for this chain\n * @param maxHops - Maximum number of hops per path (default 3)\n */\nexport async function findBestQuote(\n client: PublicClient,\n chainId: number,\n tokenIn: Address,\n tokenOut: Address,\n exactAmount: bigint,\n pools: PoolKey[] = [],\n quoterAddress?: Address,\n maxHops = 3,\n): Promise<BestQuote> {\n const quoter = quoterAddress ?? V4_QUOTER_ADDRESSES[chainId];\n if (!quoter) {\n throw new Error(`No V4 Quoter address configured for chain ${chainId}`);\n }\n\n const commonPools = COMMON_POOLS[chainId] ?? [];\n const allPools = [...pools, ...commonPools];\n const paths = buildAllPaths(allPools, tokenIn, tokenOut, maxHops);\n\n if (paths.length === 0) {\n throw new Error(`No paths found from ${tokenIn} to ${tokenOut}`);\n }\n\n return quoteBestRoute(client, quoter, tokenIn, paths, exactAmount);\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/abi/v4Quoter.ts
|
|
2
|
+
var poolKeyComponents = [
|
|
3
|
+
{ name: "currency0", type: "address" },
|
|
4
|
+
{ name: "currency1", type: "address" },
|
|
5
|
+
{ name: "fee", type: "uint24" },
|
|
6
|
+
{ name: "tickSpacing", type: "int24" },
|
|
7
|
+
{ name: "hooks", type: "address" }
|
|
8
|
+
];
|
|
9
|
+
var pathKeyComponents = [
|
|
10
|
+
{ name: "intermediateCurrency", type: "address" },
|
|
11
|
+
{ name: "fee", type: "uint24" },
|
|
12
|
+
{ name: "tickSpacing", type: "int24" },
|
|
13
|
+
{ name: "hooks", type: "address" },
|
|
14
|
+
{ name: "hookData", type: "bytes" }
|
|
15
|
+
];
|
|
16
|
+
var v4QuoterAbi = [
|
|
17
|
+
// quoteExactInputSingle — single-hop quote
|
|
18
|
+
{
|
|
19
|
+
type: "function",
|
|
20
|
+
name: "quoteExactInputSingle",
|
|
21
|
+
stateMutability: "nonpayable",
|
|
22
|
+
inputs: [
|
|
23
|
+
{
|
|
24
|
+
name: "params",
|
|
25
|
+
type: "tuple",
|
|
26
|
+
components: [
|
|
27
|
+
{ name: "poolKey", type: "tuple", components: poolKeyComponents },
|
|
28
|
+
{ name: "zeroForOne", type: "bool" },
|
|
29
|
+
{ name: "exactAmount", type: "uint128" },
|
|
30
|
+
{ name: "hookData", type: "bytes" }
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
outputs: [
|
|
35
|
+
{ name: "amountOut", type: "uint256" },
|
|
36
|
+
{ name: "gasEstimate", type: "uint256" }
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
// quoteExactInput — multi-hop quote
|
|
40
|
+
{
|
|
41
|
+
type: "function",
|
|
42
|
+
name: "quoteExactInput",
|
|
43
|
+
stateMutability: "nonpayable",
|
|
44
|
+
inputs: [
|
|
45
|
+
{
|
|
46
|
+
name: "params",
|
|
47
|
+
type: "tuple",
|
|
48
|
+
components: [
|
|
49
|
+
{ name: "exactCurrency", type: "address" },
|
|
50
|
+
{ name: "path", type: "tuple[]", components: pathKeyComponents },
|
|
51
|
+
{ name: "exactAmount", type: "uint128" }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
outputs: [
|
|
56
|
+
{ name: "amountOut", type: "uint256" },
|
|
57
|
+
{ name: "gasEstimate", type: "uint256" }
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
exports.v4QuoterAbi = v4QuoterAbi;
|
|
65
|
+
//# sourceMappingURL=chunk-CL3QSI4O.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CL3QSI4O.cjs","../src/abi/v4Quoter.ts"],"names":[],"mappings":"AAAA;ACEA,IAAM,kBAAA,EAAoB;AAAA,EACxB,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,UAAU,CAAA;AAAA,EACrC,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,UAAU,CAAA;AAAA,EACrC,EAAE,IAAA,EAAM,KAAA,EAAO,IAAA,EAAM,SAAS,CAAA;AAAA,EAC9B,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,QAAQ,CAAA;AAAA,EACrC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,UAAU;AACnC,CAAA;AAEA,IAAM,kBAAA,EAAoB;AAAA,EACxB,EAAE,IAAA,EAAM,sBAAA,EAAwB,IAAA,EAAM,UAAU,CAAA;AAAA,EAChD,EAAE,IAAA,EAAM,KAAA,EAAO,IAAA,EAAM,SAAS,CAAA;AAAA,EAC9B,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,QAAQ,CAAA;AAAA,EACrC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,UAAU,CAAA;AAAA,EACjC,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,QAAQ;AACpC,CAAA;AAEO,IA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,IACA,OAAA,EAAS;AAAA,MACP,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,UAAU,CAAA;AAAA,MACrC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,UAAU;AAAA,IACzC;AAAA,EACF;AACF,CAAA;ADFA;AACA;AACE;AACF,kCAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CL3QSI4O.cjs","sourcesContent":[null,"// IV4Quoter — Uniswap V4 Quoter interface\n\nconst poolKeyComponents = [\n { name: \"currency0\", type: \"address\" },\n { name: \"currency1\", type: \"address\" },\n { name: \"fee\", type: \"uint24\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n] as const;\n\nconst pathKeyComponents = [\n { name: \"intermediateCurrency\", type: \"address\" },\n { name: \"fee\", type: \"uint24\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n { name: \"hookData\", type: \"bytes\" },\n] as const;\n\nexport const v4QuoterAbi = [\n // quoteExactInputSingle — single-hop quote\n {\n type: \"function\",\n name: \"quoteExactInputSingle\",\n stateMutability: \"nonpayable\",\n inputs: [\n {\n name: \"params\",\n type: \"tuple\",\n components: [\n { name: \"poolKey\", type: \"tuple\", components: poolKeyComponents },\n { name: \"zeroForOne\", type: \"bool\" },\n { name: \"exactAmount\", type: \"uint128\" },\n { name: \"hookData\", type: \"bytes\" },\n ],\n },\n ],\n outputs: [\n { name: \"amountOut\", type: \"uint256\" },\n { name: \"gasEstimate\", type: \"uint256\" },\n ],\n },\n // quoteExactInput — multi-hop quote\n {\n type: \"function\",\n name: \"quoteExactInput\",\n stateMutability: \"nonpayable\",\n inputs: [\n {\n name: \"params\",\n type: \"tuple\",\n components: [\n { name: \"exactCurrency\", type: \"address\" },\n { name: \"path\", type: \"tuple[]\", components: pathKeyComponents },\n { name: \"exactAmount\", type: \"uint128\" },\n ],\n },\n ],\n outputs: [\n { name: \"amountOut\", type: \"uint256\" },\n { name: \"gasEstimate\", type: \"uint256\" },\n ],\n },\n] as const;\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/constants.ts
|
|
2
|
+
var mintRequestTypes = {
|
|
3
|
+
MintRequest: [
|
|
4
|
+
{ name: "to", type: "address" },
|
|
5
|
+
{ name: "amount", type: "uint256" },
|
|
6
|
+
{ name: "nonce", type: "uint256" },
|
|
7
|
+
{ name: "deadline", type: "uint256" }
|
|
8
|
+
]
|
|
9
|
+
};
|
|
10
|
+
var receiverConsentTypes = {
|
|
11
|
+
ReceiverConsent: [
|
|
12
|
+
{ name: "onBehalfOf", type: "address" },
|
|
13
|
+
{ name: "originalReceiver", type: "address" },
|
|
14
|
+
{ name: "amount", type: "uint256" },
|
|
15
|
+
{ name: "nonce", type: "uint256" },
|
|
16
|
+
{ name: "deadline", type: "uint256" },
|
|
17
|
+
{ name: "extData", type: "bytes" }
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
var SUPPORTED_CHAINS = {
|
|
21
|
+
8453: { name: "Base" }
|
|
22
|
+
};
|
|
23
|
+
var V4_QUOTER_ADDRESSES = {
|
|
24
|
+
8453: "0x0d5e0f971ed27fbff6c2837bf31316121532048d"
|
|
25
|
+
};
|
|
26
|
+
var UNIVERSAL_ROUTER_ADDRESSES = {
|
|
27
|
+
8453: "0x6ff5693b99212da76ad316178a184ab56d299b43"
|
|
28
|
+
};
|
|
29
|
+
var COMMON_TOKENS = {
|
|
30
|
+
// Base
|
|
31
|
+
8453: {
|
|
32
|
+
WETH: "0x4200000000000000000000000000000000000006",
|
|
33
|
+
USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
34
|
+
USDT: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var COMMON_POOLS = {
|
|
38
|
+
// Base — existing Uniswap V4 pools
|
|
39
|
+
8453: [
|
|
40
|
+
// WETH/USDC 0.3%
|
|
41
|
+
{
|
|
42
|
+
currency0: "0x4200000000000000000000000000000000000006",
|
|
43
|
+
currency1: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
44
|
+
fee: 3e3,
|
|
45
|
+
tickSpacing: 60,
|
|
46
|
+
hooks: "0x0000000000000000000000000000000000000000"
|
|
47
|
+
},
|
|
48
|
+
// WETH/USDC 0.05%
|
|
49
|
+
{
|
|
50
|
+
currency0: "0x4200000000000000000000000000000000000006",
|
|
51
|
+
currency1: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
52
|
+
fee: 500,
|
|
53
|
+
tickSpacing: 10,
|
|
54
|
+
hooks: "0x0000000000000000000000000000000000000000"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
var POINT_TOKEN_POOLS = {
|
|
59
|
+
// chainId → pointTokenAddress → PoolKey[]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.mintRequestTypes = mintRequestTypes; exports.receiverConsentTypes = receiverConsentTypes; exports.SUPPORTED_CHAINS = SUPPORTED_CHAINS; exports.V4_QUOTER_ADDRESSES = V4_QUOTER_ADDRESSES; exports.UNIVERSAL_ROUTER_ADDRESSES = UNIVERSAL_ROUTER_ADDRESSES; exports.COMMON_TOKENS = COMMON_TOKENS; exports.COMMON_POOLS = COMMON_POOLS; exports.POINT_TOKEN_POOLS = POINT_TOKEN_POOLS;
|
|
72
|
+
//# sourceMappingURL=chunk-CWP4PFOP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CWP4PFOP.cjs","../src/constants.ts"],"names":[],"mappings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A,EAAM;AAAA;AAAA,IAEJ;AAAA,MACE,SAAA,EAAW,4CAAA;AAAA,MACX,SAAA,EAAW,4CAAA;AAAA,MACX,GAAA,EAAK,GAAA;AAAA,MACL,WAAA,EAAa,EAAA;AAAA,MACb,KAAA,EAAO;AAAA,IACT,CAAA;AAAA;AAAA,IAEA;AAAA,MACE,SAAA,EAAW,4CAAA;AAAA,MACX,SAAA,EAAW,4CAAA;AAAA,MACX,GAAA,EAAK,GAAA;AAAA,MACL,WAAA,EAAa,EAAA;AAAA,MACb,KAAA,EAAO;AAAA,IACT;AAAA,EACF;AACF,CAAA;AAEO,IAAM,kBAAA,EAAgE;AAAA;AAE7E,CAAA;ADhBA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6XAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-CWP4PFOP.cjs","sourcesContent":[null,"import type { Address } from \"viem\";\nimport type { ChainConfig, PoolKey } from \"./types\";\n\n// -------------------------------------------------------------------------\n// EIP-712 type definitions for viem\n// -------------------------------------------------------------------------\n\nexport const mintRequestTypes = {\n MintRequest: [\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n} as const;\n\nexport const receiverConsentTypes = {\n ReceiverConsent: [\n { name: \"onBehalfOf\", type: \"address\" },\n { name: \"originalReceiver\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"extData\", type: \"bytes\" },\n ],\n} as const;\n\n// -------------------------------------------------------------------------\n// Chain-indexed constants — add entries here as new chains are supported\n// -------------------------------------------------------------------------\n\nexport const SUPPORTED_CHAINS: Record<number, ChainConfig> = {\n 8453: { name: \"Base\" },\n};\n\nexport const V4_QUOTER_ADDRESSES: Record<number, Address> = {\n 8453: \"0x0d5e0f971ed27fbff6c2837bf31316121532048d\",\n};\n\nexport const UNIVERSAL_ROUTER_ADDRESSES: Record<number, Address> = {\n 8453: \"0x6ff5693b99212da76ad316178a184ab56d299b43\",\n};\n\nexport const COMMON_TOKENS: Record<number, Record<string, Address>> = {\n // Base\n 8453: {\n WETH: \"0x4200000000000000000000000000000000000006\",\n USDC: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n USDT: \"0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2\",\n },\n};\n\nexport const COMMON_POOLS: Record<number, PoolKey[]> = {\n // Base — existing Uniswap V4 pools\n 8453: [\n // WETH/USDC 0.3%\n {\n currency0: \"0x4200000000000000000000000000000000000006\",\n currency1: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n fee: 3000,\n tickSpacing: 60,\n hooks: \"0x0000000000000000000000000000000000000000\",\n },\n // WETH/USDC 0.05%\n {\n currency0: \"0x4200000000000000000000000000000000000006\",\n currency1: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n fee: 500,\n tickSpacing: 10,\n hooks: \"0x0000000000000000000000000000000000000000\",\n },\n ],\n};\n\nexport const POINT_TOKEN_POOLS: Record<number, Record<Address, PoolKey[]>> = {\n // chainId → pointTokenAddress → PoolKey[]\n};\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
relayAbi
|
|
3
|
+
} from "./chunk-4RYBJLF3.js";
|
|
4
|
+
import {
|
|
5
|
+
SimulationError
|
|
6
|
+
} from "./chunk-P56TUGTS.js";
|
|
7
|
+
|
|
8
|
+
// src/relay/calldata.ts
|
|
9
|
+
import {
|
|
10
|
+
decodeFunctionData,
|
|
11
|
+
encodeFunctionData,
|
|
12
|
+
encodeAbiParameters,
|
|
13
|
+
decodeAbiParameters
|
|
14
|
+
} from "viem";
|
|
15
|
+
function encodeExtData(minAmountOut, feeInUsdt) {
|
|
16
|
+
return encodeAbiParameters(
|
|
17
|
+
[{ type: "uint256" }, { type: "uint256" }],
|
|
18
|
+
[minAmountOut, feeInUsdt]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function decodeExtData(extData) {
|
|
22
|
+
const [minAmountOut, feeInUsdt] = decodeAbiParameters(
|
|
23
|
+
[{ type: "uint256" }, { type: "uint256" }],
|
|
24
|
+
extData
|
|
25
|
+
);
|
|
26
|
+
return { minAmountOut, feeInUsdt };
|
|
27
|
+
}
|
|
28
|
+
function buildRelaySwapParams(params) {
|
|
29
|
+
return {
|
|
30
|
+
swapParams: {
|
|
31
|
+
path: params.quote.path,
|
|
32
|
+
deadline: params.deadline
|
|
33
|
+
},
|
|
34
|
+
extData: encodeExtData(params.minAmountOut, params.feeInUsdt)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function encodeMintAndSwap(mint, swap) {
|
|
38
|
+
return encodeFunctionData({
|
|
39
|
+
abi: relayAbi,
|
|
40
|
+
functionName: "mintAndSwap",
|
|
41
|
+
args: [mint, swap]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function decodeMintAndSwap(calldata) {
|
|
45
|
+
const { args } = decodeFunctionData({
|
|
46
|
+
abi: relayAbi,
|
|
47
|
+
data: calldata
|
|
48
|
+
});
|
|
49
|
+
const [rawMint, rawSwap] = args;
|
|
50
|
+
const mint = {
|
|
51
|
+
pointToken: rawMint.pointToken,
|
|
52
|
+
receiver: rawMint.receiver,
|
|
53
|
+
amount: rawMint.amount,
|
|
54
|
+
deadline: rawMint.deadline,
|
|
55
|
+
minterSig: rawMint.minterSig,
|
|
56
|
+
receiverSig: rawMint.receiverSig,
|
|
57
|
+
extData: rawMint.extData
|
|
58
|
+
};
|
|
59
|
+
const swap = {
|
|
60
|
+
path: rawSwap.path.map(
|
|
61
|
+
(hop) => ({
|
|
62
|
+
intermediateCurrency: hop.intermediateCurrency,
|
|
63
|
+
fee: hop.fee,
|
|
64
|
+
tickSpacing: hop.tickSpacing,
|
|
65
|
+
hooks: hop.hooks,
|
|
66
|
+
hookData: hop.hookData
|
|
67
|
+
})
|
|
68
|
+
),
|
|
69
|
+
deadline: rawSwap.deadline
|
|
70
|
+
};
|
|
71
|
+
return { mint, swap };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/relay/simulate.ts
|
|
75
|
+
async function simulateMintAndSwap(client, relayAddress, mint, swap, from) {
|
|
76
|
+
try {
|
|
77
|
+
const gasEstimate = await client.estimateContractGas({
|
|
78
|
+
address: relayAddress,
|
|
79
|
+
abi: relayAbi,
|
|
80
|
+
functionName: "mintAndSwap",
|
|
81
|
+
args: [mint, swap],
|
|
82
|
+
account: from
|
|
83
|
+
});
|
|
84
|
+
return { success: true, gasEstimate };
|
|
85
|
+
} catch (error) {
|
|
86
|
+
const message = error instanceof Error ? error.message : "Unknown simulation error";
|
|
87
|
+
throw new SimulationError("mintAndSwap", message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
encodeExtData,
|
|
93
|
+
decodeExtData,
|
|
94
|
+
buildRelaySwapParams,
|
|
95
|
+
encodeMintAndSwap,
|
|
96
|
+
decodeMintAndSwap,
|
|
97
|
+
simulateMintAndSwap
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=chunk-DSCUHT3F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/relay/calldata.ts","../src/relay/simulate.ts"],"sourcesContent":["import {\n decodeFunctionData,\n encodeFunctionData,\n encodeAbiParameters,\n decodeAbiParameters,\n} from \"viem\";\nimport type { Hex } from \"viem\";\nimport { relayAbi } from \"../abi/relay\";\nimport type { MintParams, PathKey, SwapParams } from \"../types\";\n\n/**\n * Encode extData for ReceiverConsent and MintParams.\n * extData = abi.encode(uint256 minAmountOut, uint256 feeInUsdt)\n */\nexport function encodeExtData(minAmountOut: bigint, feeInUsdt: bigint): Hex {\n return encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"uint256\" }],\n [minAmountOut, feeInUsdt],\n );\n}\n\n/**\n * Decode extData back to { minAmountOut, feeInUsdt }.\n */\nexport function decodeExtData(extData: Hex): {\n minAmountOut: bigint;\n feeInUsdt: bigint;\n} {\n const [minAmountOut, feeInUsdt] = decodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"uint256\" }],\n extData,\n );\n return { minAmountOut, feeInUsdt };\n}\n\n/**\n * Build SwapParams and extData from a quote result for Relay.mintAndSwap.\n *\n * @param quote - Quote result containing the path\n * @param minAmountOut - Minimum acceptable USDT output (caller applies slippage)\n * @param feeInUsdt - Fixed USDT fee for the relayer\n * @param deadline - Swap deadline (unix timestamp)\n */\nexport function buildRelaySwapParams(params: {\n quote: { path: PathKey[] };\n minAmountOut: bigint;\n feeInUsdt: bigint;\n deadline: bigint;\n}): { swapParams: SwapParams; extData: Hex } {\n return {\n swapParams: {\n path: params.quote.path,\n deadline: params.deadline,\n },\n extData: encodeExtData(params.minAmountOut, params.feeInUsdt),\n };\n}\n\nexport function encodeMintAndSwap(mint: MintParams, swap: SwapParams): Hex {\n return encodeFunctionData({\n abi: relayAbi,\n functionName: \"mintAndSwap\",\n args: [mint, swap],\n });\n}\n\nexport function decodeMintAndSwap(calldata: Hex): {\n mint: MintParams;\n swap: SwapParams;\n} {\n const { args } = decodeFunctionData({\n abi: relayAbi,\n data: calldata,\n });\n\n const [rawMint, rawSwap] = args as [\n {\n pointToken: `0x${string}`;\n receiver: `0x${string}`;\n amount: bigint;\n deadline: bigint;\n minterSig: Hex;\n receiverSig: Hex;\n extData: Hex;\n },\n {\n path: ReadonlyArray<{\n intermediateCurrency: `0x${string}`;\n fee: number;\n tickSpacing: number;\n hooks: `0x${string}`;\n hookData: Hex;\n }>;\n deadline: bigint;\n },\n ];\n\n const mint: MintParams = {\n pointToken: rawMint.pointToken,\n receiver: rawMint.receiver,\n amount: rawMint.amount,\n deadline: rawMint.deadline,\n minterSig: rawMint.minterSig,\n receiverSig: rawMint.receiverSig,\n extData: rawMint.extData,\n };\n\n const swap: SwapParams = {\n path: rawSwap.path.map(\n (hop): PathKey => ({\n intermediateCurrency: hop.intermediateCurrency,\n fee: hop.fee,\n tickSpacing: hop.tickSpacing,\n hooks: hop.hooks,\n hookData: hop.hookData,\n }),\n ),\n deadline: rawSwap.deadline,\n };\n\n return { mint, swap };\n}\n","import type { Address, PublicClient } from \"viem\";\nimport { relayAbi } from \"../abi/relay\";\nimport type { MintParams, SwapParams } from \"../types\";\nimport { SimulationError } from \"../errors\";\n\nexport interface SimulationResult {\n success: boolean;\n gasEstimate: bigint;\n}\n\n/**\n * Simulate a Relay.mintAndSwap call via eth_call (no gas spent).\n *\n * Runs the full flow — signature verification, minting, swap via PoolManager,\n * fee split — without submitting a transaction. If the simulation reverts,\n * throws a `SimulationError` with the revert reason.\n *\n * Call this AFTER both signatures are collected but BEFORE submitting the tx.\n *\n * @param client - viem PublicClient\n * @param relayAddress - Relay contract address\n * @param mint - MintParams (with real minterSig + receiverSig)\n * @param swap - SwapParams (path + deadline)\n * @param from - Address that will call mintAndSwap (the relayer)\n */\nexport async function simulateMintAndSwap(\n client: PublicClient,\n relayAddress: Address,\n mint: MintParams,\n swap: SwapParams,\n from: Address,\n): Promise<SimulationResult> {\n try {\n const gasEstimate = await client.estimateContractGas({\n address: relayAddress,\n abi: relayAbi,\n functionName: \"mintAndSwap\",\n args: [mint, swap],\n account: from,\n });\n\n return { success: true, gasEstimate };\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : \"Unknown simulation error\";\n throw new SimulationError(\"mintAndSwap\", message);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASA,SAAS,cAAc,cAAsB,WAAwB;AAC1E,SAAO;AAAA,IACL,CAAC,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,UAAU,CAAC;AAAA,IACzC,CAAC,cAAc,SAAS;AAAA,EAC1B;AACF;AAKO,SAAS,cAAc,SAG5B;AACA,QAAM,C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