@pafi-dev/core 0.3.0-beta.9 → 0.5.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 +165 -1084
- package/dist/auth/index.cjs +16 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +93 -2
- package/dist/auth/index.d.ts +93 -2
- package/dist/auth/index.js +17 -3
- package/dist/{chunk-KJKDLD7N.cjs → chunk-2PY5RNVS.cjs} +11 -11
- package/dist/{chunk-KJKDLD7N.cjs.map → chunk-2PY5RNVS.cjs.map} +1 -1
- package/dist/{chunk-DMW67WBU.cjs → chunk-52SZJDFT.cjs} +6 -2
- package/dist/chunk-52SZJDFT.cjs.map +1 -0
- package/dist/{chunk-Z2V525IS.cjs → chunk-ARZSGP5Y.cjs} +6 -6
- package/dist/{chunk-Z2V525IS.cjs.map → chunk-ARZSGP5Y.cjs.map} +1 -1
- package/dist/{chunk-GWLEEXM4.cjs → chunk-FNJZUNK3.cjs} +90 -2
- package/dist/chunk-FNJZUNK3.cjs.map +1 -0
- package/dist/{chunk-I2P3TIP7.js → chunk-N5M3BLOV.js} +2 -2
- package/dist/{chunk-73CQTNLB.js → chunk-S5CCEO4O.js} +6 -2
- package/dist/{chunk-73CQTNLB.js.map → chunk-S5CCEO4O.js.map} +1 -1
- package/dist/{chunk-W23EJNYG.js → chunk-T6Y32SNK.js} +12 -2
- package/dist/chunk-T6Y32SNK.js.map +1 -0
- package/dist/{chunk-O4SMTUOY.js → chunk-W6VULMCO.js} +90 -2
- package/dist/chunk-W6VULMCO.js.map +1 -0
- package/dist/{chunk-DUY7Z2AI.js → chunk-WTWG6QXP.js} +2 -2
- package/dist/{chunk-EDR5SFJN.cjs → chunk-YU7MFR6Y.cjs} +12 -2
- package/dist/chunk-YU7MFR6Y.cjs.map +1 -0
- package/dist/eip712/index.cjs +3 -3
- package/dist/eip712/index.js +2 -2
- package/dist/{index-B7pGBych.d.cts → index-BEx-Q1bW.d.cts} +23 -40
- package/dist/{index-B06IJlHe.d.ts → index-r4xCdQO7.d.ts} +23 -40
- package/dist/index.cjs +178 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +211 -26
- package/dist/index.d.ts +211 -26
- package/dist/index.js +176 -35
- package/dist/index.js.map +1 -1
- package/dist/quoting/index.cjs +3 -3
- package/dist/quoting/index.js +2 -2
- package/dist/swap/index.cjs +3 -2
- package/dist/swap/index.cjs.map +1 -1
- package/dist/swap/index.d.cts +1 -1
- package/dist/swap/index.d.ts +1 -1
- package/dist/swap/index.js +2 -1
- package/package.json +1 -1
- package/dist/chunk-DMW67WBU.cjs.map +0 -1
- package/dist/chunk-EDR5SFJN.cjs.map +0 -1
- package/dist/chunk-GWLEEXM4.cjs.map +0 -1
- package/dist/chunk-O4SMTUOY.js.map +0 -1
- package/dist/chunk-W23EJNYG.js.map +0 -1
- /package/dist/{chunk-I2P3TIP7.js.map → chunk-N5M3BLOV.js.map} +0 -0
- /package/dist/{chunk-DUY7Z2AI.js.map → chunk-WTWG6QXP.js.map} +0 -0
package/dist/auth/index.cjs
CHANGED
|
@@ -2,10 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var _chunkGWLEEXM4cjs = require('../chunk-GWLEEXM4.cjs');
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkFNJZUNK3cjs = require('../chunk-FNJZUNK3.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.SPONSOR_AUTH_DOMAIN_NAME = _chunkFNJZUNK3cjs.SPONSOR_AUTH_DOMAIN_NAME; exports.SPONSOR_AUTH_TYPES = _chunkFNJZUNK3cjs.SPONSOR_AUTH_TYPES; exports.buildSponsorAuthDomain = _chunkFNJZUNK3cjs.buildSponsorAuthDomain; exports.buildSponsorAuthTypedData = _chunkFNJZUNK3cjs.buildSponsorAuthTypedData; exports.computeCallDataHash = _chunkFNJZUNK3cjs.computeCallDataHash; exports.createLoginMessage = _chunkFNJZUNK3cjs.createLoginMessage; exports.parseLoginMessage = _chunkFNJZUNK3cjs.parseLoginMessage; exports.signSponsorAuth = _chunkFNJZUNK3cjs.signSponsorAuth; exports.verifyLoginMessage = _chunkFNJZUNK3cjs.verifyLoginMessage; exports.verifySponsorAuth = _chunkFNJZUNK3cjs.verifySponsorAuth;
|
|
11
25
|
//# sourceMappingURL=index.cjs.map
|
package/dist/auth/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/auth/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACF,
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/auth/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,urBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/auth/index.cjs"}
|
package/dist/auth/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Hex } from 'viem';
|
|
1
|
+
import { Address, Hex, WalletClient } from 'viem';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parameters for building an EIP-4361 (Sign-In with Ethereum) login message.
|
|
@@ -57,4 +57,95 @@ declare function parseLoginMessage(message: string): LoginMessageParams;
|
|
|
57
57
|
*/
|
|
58
58
|
declare function verifyLoginMessage(message: string, signature: Hex): Promise<VerifyLoginResult>;
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
declare const SPONSOR_AUTH_DOMAIN_NAME = "PafiSponsorAuth";
|
|
61
|
+
declare const SPONSOR_AUTH_TYPES: {
|
|
62
|
+
readonly SponsorAuth: readonly [{
|
|
63
|
+
readonly name: "chainId";
|
|
64
|
+
readonly type: "uint256";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "sender";
|
|
67
|
+
readonly type: "address";
|
|
68
|
+
}, {
|
|
69
|
+
readonly name: "callDataHash";
|
|
70
|
+
readonly type: "bytes32";
|
|
71
|
+
}, {
|
|
72
|
+
readonly name: "nonce";
|
|
73
|
+
readonly type: "uint256";
|
|
74
|
+
}, {
|
|
75
|
+
readonly name: "expiresAt";
|
|
76
|
+
readonly type: "uint256";
|
|
77
|
+
}, {
|
|
78
|
+
readonly name: "scenario";
|
|
79
|
+
readonly type: "string";
|
|
80
|
+
}, {
|
|
81
|
+
readonly name: "issuerId";
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
}];
|
|
84
|
+
};
|
|
85
|
+
interface SponsorAuthPayload {
|
|
86
|
+
chainId: number;
|
|
87
|
+
sender: Address;
|
|
88
|
+
callDataHash: Hex;
|
|
89
|
+
nonce: bigint;
|
|
90
|
+
expiresAt: number;
|
|
91
|
+
scenario: string;
|
|
92
|
+
issuerId: string;
|
|
93
|
+
}
|
|
94
|
+
interface SponsorAuthVerifyResult {
|
|
95
|
+
ok: boolean;
|
|
96
|
+
recoveredAddress?: Address;
|
|
97
|
+
reason?: "EXPIRED" | "INVALID_SIGNER" | "INVALID_SIGNATURE_FORMAT";
|
|
98
|
+
}
|
|
99
|
+
declare function buildSponsorAuthDomain(chainId: number): {
|
|
100
|
+
name: string;
|
|
101
|
+
version: string;
|
|
102
|
+
chainId: number;
|
|
103
|
+
verifyingContract: Address;
|
|
104
|
+
};
|
|
105
|
+
declare function buildSponsorAuthTypedData(payload: SponsorAuthPayload): {
|
|
106
|
+
domain: {
|
|
107
|
+
name: string;
|
|
108
|
+
version: string;
|
|
109
|
+
chainId: number;
|
|
110
|
+
verifyingContract: Address;
|
|
111
|
+
};
|
|
112
|
+
types: {
|
|
113
|
+
readonly SponsorAuth: readonly [{
|
|
114
|
+
readonly name: "chainId";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "sender";
|
|
118
|
+
readonly type: "address";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "callDataHash";
|
|
121
|
+
readonly type: "bytes32";
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "nonce";
|
|
124
|
+
readonly type: "uint256";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "expiresAt";
|
|
127
|
+
readonly type: "uint256";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "scenario";
|
|
130
|
+
readonly type: "string";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "issuerId";
|
|
133
|
+
readonly type: "string";
|
|
134
|
+
}];
|
|
135
|
+
};
|
|
136
|
+
primaryType: "SponsorAuth";
|
|
137
|
+
message: {
|
|
138
|
+
chainId: bigint;
|
|
139
|
+
sender: `0x${string}`;
|
|
140
|
+
callDataHash: `0x${string}`;
|
|
141
|
+
nonce: bigint;
|
|
142
|
+
expiresAt: bigint;
|
|
143
|
+
scenario: string;
|
|
144
|
+
issuerId: string;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
declare function computeCallDataHash(callData: Hex): Hex;
|
|
148
|
+
declare function signSponsorAuth(wallet: WalletClient, payload: SponsorAuthPayload): Promise<Hex>;
|
|
149
|
+
declare function verifySponsorAuth(payload: SponsorAuthPayload, signature: Hex, expectedSigner: Address): Promise<SponsorAuthVerifyResult>;
|
|
150
|
+
|
|
151
|
+
export { type LoginMessageParams, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, type SponsorAuthPayload, type SponsorAuthVerifyResult, type VerifyLoginResult, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth };
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Hex } from 'viem';
|
|
1
|
+
import { Address, Hex, WalletClient } from 'viem';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parameters for building an EIP-4361 (Sign-In with Ethereum) login message.
|
|
@@ -57,4 +57,95 @@ declare function parseLoginMessage(message: string): LoginMessageParams;
|
|
|
57
57
|
*/
|
|
58
58
|
declare function verifyLoginMessage(message: string, signature: Hex): Promise<VerifyLoginResult>;
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
declare const SPONSOR_AUTH_DOMAIN_NAME = "PafiSponsorAuth";
|
|
61
|
+
declare const SPONSOR_AUTH_TYPES: {
|
|
62
|
+
readonly SponsorAuth: readonly [{
|
|
63
|
+
readonly name: "chainId";
|
|
64
|
+
readonly type: "uint256";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "sender";
|
|
67
|
+
readonly type: "address";
|
|
68
|
+
}, {
|
|
69
|
+
readonly name: "callDataHash";
|
|
70
|
+
readonly type: "bytes32";
|
|
71
|
+
}, {
|
|
72
|
+
readonly name: "nonce";
|
|
73
|
+
readonly type: "uint256";
|
|
74
|
+
}, {
|
|
75
|
+
readonly name: "expiresAt";
|
|
76
|
+
readonly type: "uint256";
|
|
77
|
+
}, {
|
|
78
|
+
readonly name: "scenario";
|
|
79
|
+
readonly type: "string";
|
|
80
|
+
}, {
|
|
81
|
+
readonly name: "issuerId";
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
}];
|
|
84
|
+
};
|
|
85
|
+
interface SponsorAuthPayload {
|
|
86
|
+
chainId: number;
|
|
87
|
+
sender: Address;
|
|
88
|
+
callDataHash: Hex;
|
|
89
|
+
nonce: bigint;
|
|
90
|
+
expiresAt: number;
|
|
91
|
+
scenario: string;
|
|
92
|
+
issuerId: string;
|
|
93
|
+
}
|
|
94
|
+
interface SponsorAuthVerifyResult {
|
|
95
|
+
ok: boolean;
|
|
96
|
+
recoveredAddress?: Address;
|
|
97
|
+
reason?: "EXPIRED" | "INVALID_SIGNER" | "INVALID_SIGNATURE_FORMAT";
|
|
98
|
+
}
|
|
99
|
+
declare function buildSponsorAuthDomain(chainId: number): {
|
|
100
|
+
name: string;
|
|
101
|
+
version: string;
|
|
102
|
+
chainId: number;
|
|
103
|
+
verifyingContract: Address;
|
|
104
|
+
};
|
|
105
|
+
declare function buildSponsorAuthTypedData(payload: SponsorAuthPayload): {
|
|
106
|
+
domain: {
|
|
107
|
+
name: string;
|
|
108
|
+
version: string;
|
|
109
|
+
chainId: number;
|
|
110
|
+
verifyingContract: Address;
|
|
111
|
+
};
|
|
112
|
+
types: {
|
|
113
|
+
readonly SponsorAuth: readonly [{
|
|
114
|
+
readonly name: "chainId";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "sender";
|
|
118
|
+
readonly type: "address";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "callDataHash";
|
|
121
|
+
readonly type: "bytes32";
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "nonce";
|
|
124
|
+
readonly type: "uint256";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "expiresAt";
|
|
127
|
+
readonly type: "uint256";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "scenario";
|
|
130
|
+
readonly type: "string";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "issuerId";
|
|
133
|
+
readonly type: "string";
|
|
134
|
+
}];
|
|
135
|
+
};
|
|
136
|
+
primaryType: "SponsorAuth";
|
|
137
|
+
message: {
|
|
138
|
+
chainId: bigint;
|
|
139
|
+
sender: `0x${string}`;
|
|
140
|
+
callDataHash: `0x${string}`;
|
|
141
|
+
nonce: bigint;
|
|
142
|
+
expiresAt: bigint;
|
|
143
|
+
scenario: string;
|
|
144
|
+
issuerId: string;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
declare function computeCallDataHash(callData: Hex): Hex;
|
|
148
|
+
declare function signSponsorAuth(wallet: WalletClient, payload: SponsorAuthPayload): Promise<Hex>;
|
|
149
|
+
declare function verifySponsorAuth(payload: SponsorAuthPayload, signature: Hex, expectedSigner: Address): Promise<SponsorAuthVerifyResult>;
|
|
150
|
+
|
|
151
|
+
export { type LoginMessageParams, SPONSOR_AUTH_DOMAIN_NAME, SPONSOR_AUTH_TYPES, type SponsorAuthPayload, type SponsorAuthVerifyResult, type VerifyLoginResult, buildSponsorAuthDomain, buildSponsorAuthTypedData, computeCallDataHash, createLoginMessage, parseLoginMessage, signSponsorAuth, verifyLoginMessage, verifySponsorAuth };
|
package/dist/auth/index.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SPONSOR_AUTH_DOMAIN_NAME,
|
|
3
|
+
SPONSOR_AUTH_TYPES,
|
|
4
|
+
buildSponsorAuthDomain,
|
|
5
|
+
buildSponsorAuthTypedData,
|
|
6
|
+
computeCallDataHash,
|
|
2
7
|
createLoginMessage,
|
|
3
8
|
parseLoginMessage,
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
signSponsorAuth,
|
|
10
|
+
verifyLoginMessage,
|
|
11
|
+
verifySponsorAuth
|
|
12
|
+
} from "../chunk-W6VULMCO.js";
|
|
6
13
|
export {
|
|
14
|
+
SPONSOR_AUTH_DOMAIN_NAME,
|
|
15
|
+
SPONSOR_AUTH_TYPES,
|
|
16
|
+
buildSponsorAuthDomain,
|
|
17
|
+
buildSponsorAuthTypedData,
|
|
18
|
+
computeCallDataHash,
|
|
7
19
|
createLoginMessage,
|
|
8
20
|
parseLoginMessage,
|
|
9
|
-
|
|
21
|
+
signSponsorAuth,
|
|
22
|
+
verifyLoginMessage,
|
|
23
|
+
verifySponsorAuth
|
|
10
24
|
};
|
|
11
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk52SZJDFTcjs = require('./chunk-52SZJDFT.cjs');
|
|
6
6
|
|
|
7
7
|
// src/eip712/domain.ts
|
|
8
8
|
function buildDomain(config) {
|
|
@@ -19,7 +19,7 @@ var _viem = require('viem');
|
|
|
19
19
|
function buildMintRequestTypedData(domain, message) {
|
|
20
20
|
return {
|
|
21
21
|
domain: buildDomain(domain),
|
|
22
|
-
types:
|
|
22
|
+
types: _chunk52SZJDFTcjs.mintRequestTypes,
|
|
23
23
|
primaryType: "MintRequest",
|
|
24
24
|
message
|
|
25
25
|
};
|
|
@@ -28,7 +28,7 @@ async function signMintRequest(walletClient, domain, message) {
|
|
|
28
28
|
const serialized = await walletClient.signTypedData({
|
|
29
29
|
account: walletClient.account,
|
|
30
30
|
domain: buildDomain(domain),
|
|
31
|
-
types:
|
|
31
|
+
types: _chunk52SZJDFTcjs.mintRequestTypes,
|
|
32
32
|
primaryType: "MintRequest",
|
|
33
33
|
message
|
|
34
34
|
});
|
|
@@ -43,7 +43,7 @@ async function signMintRequest(walletClient, domain, message) {
|
|
|
43
43
|
async function verifyMintRequest(domain, message, signature, expectedMinter) {
|
|
44
44
|
const recoveredAddress = await _viem.recoverTypedDataAddress.call(void 0, {
|
|
45
45
|
domain: buildDomain(domain),
|
|
46
|
-
types:
|
|
46
|
+
types: _chunk52SZJDFTcjs.mintRequestTypes,
|
|
47
47
|
primaryType: "MintRequest",
|
|
48
48
|
message,
|
|
49
49
|
signature
|
|
@@ -57,7 +57,7 @@ async function verifyMintRequest(domain, message, signature, expectedMinter) {
|
|
|
57
57
|
function buildBurnRequestTypedData(domain, message) {
|
|
58
58
|
return {
|
|
59
59
|
domain: buildDomain(domain),
|
|
60
|
-
types:
|
|
60
|
+
types: _chunk52SZJDFTcjs.burnRequestTypes,
|
|
61
61
|
primaryType: "BurnRequest",
|
|
62
62
|
message
|
|
63
63
|
};
|
|
@@ -66,7 +66,7 @@ async function signBurnRequest(walletClient, domain, message) {
|
|
|
66
66
|
const serialized = await walletClient.signTypedData({
|
|
67
67
|
account: walletClient.account,
|
|
68
68
|
domain: buildDomain(domain),
|
|
69
|
-
types:
|
|
69
|
+
types: _chunk52SZJDFTcjs.burnRequestTypes,
|
|
70
70
|
primaryType: "BurnRequest",
|
|
71
71
|
message
|
|
72
72
|
});
|
|
@@ -81,7 +81,7 @@ async function signBurnRequest(walletClient, domain, message) {
|
|
|
81
81
|
async function verifyBurnRequest(domain, message, signature, expectedBurner) {
|
|
82
82
|
const recoveredAddress = await _viem.recoverTypedDataAddress.call(void 0, {
|
|
83
83
|
domain: buildDomain(domain),
|
|
84
|
-
types:
|
|
84
|
+
types: _chunk52SZJDFTcjs.burnRequestTypes,
|
|
85
85
|
primaryType: "BurnRequest",
|
|
86
86
|
message,
|
|
87
87
|
signature
|
|
@@ -95,7 +95,7 @@ async function verifyBurnRequest(domain, message, signature, expectedBurner) {
|
|
|
95
95
|
function buildReceiverConsentTypedData(domain, message) {
|
|
96
96
|
return {
|
|
97
97
|
domain: buildDomain(domain),
|
|
98
|
-
types:
|
|
98
|
+
types: _chunk52SZJDFTcjs.receiverConsentTypes,
|
|
99
99
|
primaryType: "ReceiverConsent",
|
|
100
100
|
message
|
|
101
101
|
};
|
|
@@ -104,7 +104,7 @@ async function signReceiverConsent(walletClient, domain, message) {
|
|
|
104
104
|
const serialized = await walletClient.signTypedData({
|
|
105
105
|
account: walletClient.account,
|
|
106
106
|
domain: buildDomain(domain),
|
|
107
|
-
types:
|
|
107
|
+
types: _chunk52SZJDFTcjs.receiverConsentTypes,
|
|
108
108
|
primaryType: "ReceiverConsent",
|
|
109
109
|
message
|
|
110
110
|
});
|
|
@@ -119,7 +119,7 @@ async function signReceiverConsent(walletClient, domain, message) {
|
|
|
119
119
|
async function verifyReceiverConsent(domain, message, signature, expectedReceiver) {
|
|
120
120
|
const recoveredAddress = await _viem.recoverTypedDataAddress.call(void 0, {
|
|
121
121
|
domain: buildDomain(domain),
|
|
122
|
-
types:
|
|
122
|
+
types: _chunk52SZJDFTcjs.receiverConsentTypes,
|
|
123
123
|
primaryType: "ReceiverConsent",
|
|
124
124
|
message,
|
|
125
125
|
signature
|
|
@@ -140,4 +140,4 @@ async function verifyReceiverConsent(domain, message, signature, expectedReceive
|
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
exports.buildDomain = buildDomain; exports.buildMintRequestTypedData = buildMintRequestTypedData; exports.signMintRequest = signMintRequest; exports.verifyMintRequest = verifyMintRequest; exports.buildBurnRequestTypedData = buildBurnRequestTypedData; exports.signBurnRequest = signBurnRequest; exports.verifyBurnRequest = verifyBurnRequest; exports.buildReceiverConsentTypedData = buildReceiverConsentTypedData; exports.signReceiverConsent = signReceiverConsent; exports.verifyReceiverConsent = verifyReceiverConsent;
|
|
143
|
-
//# sourceMappingURL=chunk-
|
|
143
|
+
//# sourceMappingURL=chunk-2PY5RNVS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-KJKDLD7N.cjs","../src/eip712/domain.ts","../src/eip712/mintRequest.ts","../src/eip712/burnRequest.ts","../src/eip712/receiverConsent.ts"],"names":["parseSignature","recoverTypedDataAddress","getAddress"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACJO,SAAS,WAAA,CAAY,MAAA,EAAgC;AAC1D,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,MAAA,CAAO,IAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,OAAA,EAAS,MAAA,CAAO,OAAA;AAAA,IAChB,iBAAA,EAAmB,MAAA,CAAO;AAAA,EAC5B,CAAA;AACF;ADMA;AACA;AEhBA,4BAAoE;AAW7D,SAAS,yBAAA,CACd,MAAA,EACA,OAAA,EACA;AACA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ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,EACF,CAAA;AACF;AAEA,MAAA,SAAsB,mBAAA,CACpB,YAAA,EACA,MAAA,EACA,OAAA,EAC0B;AAC1B,EAAA,MAAM,WAAA,EAAa,MAAM,YAAA,CAAa,aAAA,CAAc;AAAA,IAClD,OAAA,EAAS,YAAA,CAAa,OAAA;AAAA,IACtB,MAAA,EAAQ,WAAA,CAAY,MAAM,CAAA;AAAA,IAC1B,KAAA,EAAO,sCAAA;AAAA,IACP,WAAA,EAAa,iBAAA;AAAA,IACb;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,EAAE,CAAA,EAAG,CAAA,EAAG,EAAE,EAAA,EAAIF,kCAAAA,UAAyB,CAAA;AAE7C,EAAA,OAAO;AAAA,IACL,CAAA,EAAG,MAAA,CAAO,CAAC,CAAA;AAAA,IACX,CAAA;AAAA,IACA,CAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;AAEA,MAAA,SAAsB,qBAAA,CACpB,MAAA,EACA,OAAA,EACA,SAAA,EACA,gBAAA,EACgC;AAChC,EAAA,MAAM,iBAAA,EAAmB,MAAMC,2CAAAA;AAAwB,IACrD,MAAA,EAAQ,WAAA,CAAY,MAAM,CAAA;AAAA,IAC1B,KAAA,EAAO,sCAAA;AAAA,IACP,WAAA,EAAa,iBAAA;AAAA,IACb,OAAA;AAAA,IACA;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,QAAA,EAAUC,8BAAAA,gBAA2B,EAAA,IAAMA,8BAAAA,gBAA2B,CAAA;AAE5E,EAAA,OAAO,EAAE,OAAA,EAAS,iBAAiB,CAAA;AACrC;AJkEA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,qgBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-KJKDLD7N.cjs","sourcesContent":[null,"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 { burnRequestTypes } from \"../constants\";\nimport type {\n BurnRequest,\n EIP712Signature,\n PointTokenDomainConfig,\n SignatureVerification,\n} from \"../types\";\nimport { buildDomain } from \"./domain\";\n\n/**\n * EIP-712 helpers for `BurnRequest` — consumed by the sig-gated burn\n * path on `PointToken`:\n *\n * burn(address from, uint256 amount, uint256 deadline, bytes burnerSig)\n *\n * Solidity type hash:\n * BurnRequest(address from,uint256 amount,uint256 nonce,uint256 deadline)\n *\n * Issuer backend signs with its burner signer (HSM/KMS). On-chain\n * `msg.sender` must equal `from`, and the recovered signer must be in\n * `burners[]`. Nonce comes from `burnRequestNonces[from]` and is\n * auto-incremented on success.\n */\nexport function buildBurnRequestTypedData(\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n) {\n return {\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\" as const,\n message,\n };\n}\n\nexport async function signBurnRequest(\n walletClient: WalletClient,\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n): Promise<EIP712Signature> {\n const serialized = await walletClient.signTypedData({\n account: walletClient.account!,\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\",\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 verifyBurnRequest(\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n signature: Hex,\n expectedBurner: Address,\n): Promise<SignatureVerification> {\n const recoveredAddress = await recoverTypedDataAddress({\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\",\n message,\n signature,\n });\n\n const isValid = getAddress(recoveredAddress) === getAddress(expectedBurner);\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"]}
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-2PY5RNVS.cjs","../src/eip712/domain.ts","../src/eip712/mintRequest.ts","../src/eip712/burnRequest.ts","../src/eip712/receiverConsent.ts"],"names":["parseSignature","recoverTypedDataAddress","getAddress"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACJO,SAAS,WAAA,CAAY,MAAA,EAAgC;AAC1D,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,MAAA,CAAO,IAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,OAAA,EAAS,MAAA,CAAO,OAAA;AAAA,IAChB,iBAAA,EAAmB,MAAA,CAAO;AAAA,EAC5B,CAAA;AACF;ADMA;AACA;AEhBA,4BAAoE;AAW7D,SAAS,yBAAA,CACd,MAAA,EACA,OAAA,EACA;AACA,EAAA,OAAO;AAAA,IACL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A,IACb;AAAA,EACF,CAAA;AACF;AAEA,MAAA,SAAsB,mBAAA,CACpB,YAAA,EACA,MAAA,EACA,OAAA,EAC0B;AAC1B,EAAA,MAAM,WAAA,EAAa,MAAM,YAAA,CAAa,aAAA,CAAc;AAAA,IAClD,OAAA,EAAS,YAAA,CAAa,OAAA;AAAA,IACtB,MAAA,EAAQ,WAAA,CAAY,MAAM,CAAA;AAAA,IAC1B,KAAA,EAAO,sCAAA;AAAA,IACP,WAAA,EAAa,iBAAA;AAAA,IACb;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,EAAE,CAAA,EAAG,CAAA,EAAG,EAAE,EAAA,EAAIF,kCAAAA,UAAyB,CAAA;AAE7C,EAAA,OAAO;AAAA,IACL,CAAA,EAAG,MAAA,CAAO,CAAC,CAAA;AAAA,IACX,CAAA;AAAA,IACA,CAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;AAEA,MAAA,SAAsB,qBAAA,CACpB,MAAA,EACA,OAAA,EACA,SAAA,EACA,gBAAA,EACgC;AAChC,EAAA,MAAM,iBAAA,EAAmB,MAAMC,2CAAAA;AAAwB,IACrD,MAAA,EAAQ,WAAA,CAAY,MAAM,CAAA;AAAA,IAC1B,KAAA,EAAO,sCAAA;AAAA,IACP,WAAA,EAAa,iBAAA;AAAA,IACb,OAAA;AAAA,IACA;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,QAAA,EAAUC,8BAAAA,gBAA2B,EAAA,IAAMA,8BAAAA,gBAA2B,CAAA;AAE5E,EAAA,OAAO,EAAE,OAAA,EAAS,iBAAiB,CAAA;AACrC;AJkEA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,qgBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-2PY5RNVS.cjs","sourcesContent":[null,"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 { burnRequestTypes } from \"../constants\";\nimport type {\n BurnRequest,\n EIP712Signature,\n PointTokenDomainConfig,\n SignatureVerification,\n} from \"../types\";\nimport { buildDomain } from \"./domain\";\n\n/**\n * EIP-712 helpers for `BurnRequest` — consumed by the sig-gated burn\n * path on `PointToken`:\n *\n * burn(address from, uint256 amount, uint256 deadline, bytes burnerSig)\n *\n * Solidity type hash:\n * BurnRequest(address from,uint256 amount,uint256 nonce,uint256 deadline)\n *\n * Issuer backend signs with its burner signer (HSM/KMS). On-chain\n * `msg.sender` must equal `from`, and the recovered signer must be in\n * `burners[]`. Nonce comes from `burnRequestNonces[from]` and is\n * auto-incremented on success.\n */\nexport function buildBurnRequestTypedData(\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n) {\n return {\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\" as const,\n message,\n };\n}\n\nexport async function signBurnRequest(\n walletClient: WalletClient,\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n): Promise<EIP712Signature> {\n const serialized = await walletClient.signTypedData({\n account: walletClient.account!,\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\",\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 verifyBurnRequest(\n domain: PointTokenDomainConfig,\n message: BurnRequest,\n signature: Hex,\n expectedBurner: Address,\n): Promise<SignatureVerification> {\n const recoveredAddress = await recoverTypedDataAddress({\n domain: buildDomain(domain),\n types: burnRequestTypes,\n primaryType: \"BurnRequest\",\n message,\n signature,\n });\n\n const isValid = getAddress(recoveredAddress) === getAddress(expectedBurner);\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"]}
|
|
@@ -66,6 +66,8 @@ var COMMON_POOLS = {
|
|
|
66
66
|
var POINT_TOKEN_POOLS = {
|
|
67
67
|
// chainId → pointTokenAddress → PoolKey[]
|
|
68
68
|
};
|
|
69
|
+
var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
70
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
69
71
|
|
|
70
72
|
|
|
71
73
|
|
|
@@ -77,5 +79,7 @@ var POINT_TOKEN_POOLS = {
|
|
|
77
79
|
|
|
78
80
|
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
exports.mintRequestTypes = mintRequestTypes; exports.burnRequestTypes = burnRequestTypes; 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; exports.ENTRY_POINT_V07 = ENTRY_POINT_V07; exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
|
|
85
|
+
//# sourceMappingURL=chunk-52SZJDFT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-52SZJDFT.cjs","../src/constants.ts"],"names":[],"mappings":"AAAA;ACOO,IAAM,iBAAA,EAAmB;AAAA,EAC9B,WAAA,EAAa;AAAA,IACX,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,UAAU,CAAA;AAAA,IAC9B,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,UAAU,CAAA;AAAA,IAClC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,UAAU,CAAA;AAAA,IACjC,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,UAAU;AAAA,EACtC;AACF,CAAA;AAEO,IAAM,iBAAA,EAAmB;AAAA,EAC9B,WAAA,EAAa;AAAA,IACX,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,UAAU,CAAA;AAAA,IAChC,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,UAAU,CAAA;AAAA,IAClC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,UAAU,CAAA;AAAA,IACjC,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,UAAU;AAAA,EACtC;AACF,CAAA;AAEO,IAAM,qBAAA,EAAuB;AAAA,EAClC,eAAA,EAAiB;AAAA,IACf,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,UAAU,CA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;AAGjC,IAAM,gBAAA,EAA2B,4CAAA;ADzBxC;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,ggBAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-52SZJDFT.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 burnRequestTypes = {\n BurnRequest: [\n { name: \"from\", 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\n// -------------------------------------------------------------------------\n// Protocol constants — chain-agnostic (same address on every EVM chain)\n// -------------------------------------------------------------------------\n\n/** ERC-4337 v0.7 EntryPoint — deployed deterministically across all EVM chains. */\nexport const ENTRY_POINT_V07: Address = \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\";\n\n/** Permit2 — Uniswap's universal approval contract, same address on all EVM chains. */\nexport const PERMIT2_ADDRESS: Address = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\";\n"]}
|
|
@@ -5,13 +5,13 @@ var _chunkCL3QSI4Ocjs = require('./chunk-CL3QSI4O.cjs');
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunk52SZJDFTcjs = require('./chunk-52SZJDFT.cjs');
|
|
9
9
|
|
|
10
10
|
// src/quoting/routes.ts
|
|
11
11
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
12
12
|
function combineRoutes(chainId, pointTokenAddress) {
|
|
13
|
-
const commonPools = _nullishCoalesce(
|
|
14
|
-
const pointPools = _nullishCoalesce(_optionalChain([
|
|
13
|
+
const commonPools = _nullishCoalesce(_chunk52SZJDFTcjs.COMMON_POOLS[chainId], () => ( []));
|
|
14
|
+
const pointPools = _nullishCoalesce(_optionalChain([_chunk52SZJDFTcjs.POINT_TOKEN_POOLS, 'access', _ => _[chainId], 'optionalAccess', _2 => _2[pointTokenAddress]]), () => ( []));
|
|
15
15
|
return [...pointPools, ...commonPools];
|
|
16
16
|
}
|
|
17
17
|
function buildAllPaths(pools, tokenIn, tokenOut, maxHops = 3) {
|
|
@@ -112,11 +112,11 @@ async function quoteBestRoute(client, quoterAddress, exactCurrency, routes, exac
|
|
|
112
112
|
return { bestRoute, allRoutes };
|
|
113
113
|
}
|
|
114
114
|
async function findBestQuote(client, chainId, tokenIn, tokenOut, exactAmount, pools = [], quoterAddress, maxHops = 3) {
|
|
115
|
-
const quoter = _nullishCoalesce(quoterAddress, () => (
|
|
115
|
+
const quoter = _nullishCoalesce(quoterAddress, () => ( _chunk52SZJDFTcjs.V4_QUOTER_ADDRESSES[chainId]));
|
|
116
116
|
if (!quoter) {
|
|
117
117
|
throw new Error(`No V4 Quoter address configured for chain ${chainId}`);
|
|
118
118
|
}
|
|
119
|
-
const commonPools = _nullishCoalesce(
|
|
119
|
+
const commonPools = _nullishCoalesce(_chunk52SZJDFTcjs.COMMON_POOLS[chainId], () => ( []));
|
|
120
120
|
const allPools = [...pools, ...commonPools];
|
|
121
121
|
const paths = buildAllPaths(allPools, tokenIn, tokenOut, maxHops);
|
|
122
122
|
if (paths.length === 0) {
|
|
@@ -133,4 +133,4 @@ async function findBestQuote(client, chainId, tokenIn, tokenOut, exactAmount, po
|
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
exports.combineRoutes = combineRoutes; exports.buildAllPaths = buildAllPaths; exports.quoteExactInput = quoteExactInput; exports.quoteExactInputSingle = quoteExactInputSingle; exports.quoteBestRoute = quoteBestRoute; exports.findBestQuote = findBestQuote;
|
|
136
|
-
//# sourceMappingURL=chunk-
|
|
136
|
+
//# sourceMappingURL=chunk-ARZSGP5Y.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-Z2V525IS.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,EAAA,MAAM,QAAA,EAAuB,CAAC,CAAA;AAE9B,EAAA,SAAS,GAAA,CACP,YAAA,EACA,WAAA,EACA,eAAA,EACA;AACA,IAAA,GAAA,CAAI,WAAA,CAAY,OAAA,EAAS,OAAA,EAAS,MAAA;AAGlC,IAAA,GAAA,CACE,WAAA,CAAY,OAAA,EAAS,EAAA,GACrB,YAAA,CAAa,WAAA,CAAY,EAAA,IAAM,QAAA,CAAS,WAAA,CAAY,CAAA,EACpD;AACA,MAAA,OAAA,CAAQ,IAAA,CAAK,CAAC,GAAG,WAAW,CAAC,CAAA;AAC7B,MAAA,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,KAAA,CAAM,MAAA,EAAQ,CAAA,EAAA,EAAK;AACrC,MAAA,GAAA,CAAI,eAAA,CAAgB,GAAA,CAAI,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AAM,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-Z2V525IS.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"]}
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-ARZSGP5Y.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,EAAA,MAAM,QAAA,EAAuB,CAAC,CAAA;AAE9B,EAAA,SAAS,GAAA,CACP,YAAA,EACA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AAW,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-ARZSGP5Y.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"]}
|
|
@@ -155,9 +155,97 @@ function optionalDate(fields, key) {
|
|
|
155
155
|
return new Date(raw);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
// src/auth/sponsorAuth.ts
|
|
159
|
+
|
|
160
|
+
var SPONSOR_AUTH_DOMAIN_NAME = "PafiSponsorAuth";
|
|
161
|
+
var SPONSOR_AUTH_TYPES = {
|
|
162
|
+
SponsorAuth: [
|
|
163
|
+
{ name: "chainId", type: "uint256" },
|
|
164
|
+
{ name: "sender", type: "address" },
|
|
165
|
+
{ name: "callDataHash", type: "bytes32" },
|
|
166
|
+
{ name: "nonce", type: "uint256" },
|
|
167
|
+
{ name: "expiresAt", type: "uint256" },
|
|
168
|
+
{ name: "scenario", type: "string" },
|
|
169
|
+
{ name: "issuerId", type: "string" }
|
|
170
|
+
]
|
|
171
|
+
};
|
|
172
|
+
function buildSponsorAuthDomain(chainId) {
|
|
173
|
+
return {
|
|
174
|
+
name: SPONSOR_AUTH_DOMAIN_NAME,
|
|
175
|
+
version: "1",
|
|
176
|
+
chainId,
|
|
177
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function buildMessage(payload) {
|
|
181
|
+
return {
|
|
182
|
+
chainId: BigInt(payload.chainId),
|
|
183
|
+
sender: payload.sender,
|
|
184
|
+
callDataHash: payload.callDataHash,
|
|
185
|
+
nonce: payload.nonce,
|
|
186
|
+
expiresAt: BigInt(payload.expiresAt),
|
|
187
|
+
scenario: payload.scenario,
|
|
188
|
+
issuerId: payload.issuerId
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function buildSponsorAuthTypedData(payload) {
|
|
192
|
+
return {
|
|
193
|
+
domain: buildSponsorAuthDomain(payload.chainId),
|
|
194
|
+
types: SPONSOR_AUTH_TYPES,
|
|
195
|
+
primaryType: "SponsorAuth",
|
|
196
|
+
message: buildMessage(payload)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function computeCallDataHash(callData) {
|
|
200
|
+
return _viem.keccak256.call(void 0, callData);
|
|
201
|
+
}
|
|
202
|
+
async function signSponsorAuth(wallet, payload) {
|
|
203
|
+
const { domain, types, primaryType, message } = buildSponsorAuthTypedData(payload);
|
|
204
|
+
return wallet.signTypedData({
|
|
205
|
+
account: wallet.account,
|
|
206
|
+
domain,
|
|
207
|
+
types,
|
|
208
|
+
primaryType,
|
|
209
|
+
message
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async function verifySponsorAuth(payload, signature, expectedSigner) {
|
|
213
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
214
|
+
if (payload.expiresAt < nowSec) {
|
|
215
|
+
return { ok: false, reason: "EXPIRED" };
|
|
216
|
+
}
|
|
217
|
+
if (signature.length < 132) {
|
|
218
|
+
return { ok: false, reason: "INVALID_SIGNATURE_FORMAT" };
|
|
219
|
+
}
|
|
220
|
+
let recovered;
|
|
221
|
+
try {
|
|
222
|
+
const { domain, types, primaryType, message } = buildSponsorAuthTypedData(payload);
|
|
223
|
+
recovered = await _viem.recoverTypedDataAddress.call(void 0, {
|
|
224
|
+
domain,
|
|
225
|
+
types,
|
|
226
|
+
primaryType,
|
|
227
|
+
message,
|
|
228
|
+
signature
|
|
229
|
+
});
|
|
230
|
+
} catch (e) {
|
|
231
|
+
return { ok: false, reason: "INVALID_SIGNATURE_FORMAT" };
|
|
232
|
+
}
|
|
233
|
+
if (recovered.toLowerCase() !== expectedSigner.toLowerCase()) {
|
|
234
|
+
return { ok: false, reason: "INVALID_SIGNER", recoveredAddress: recovered };
|
|
235
|
+
}
|
|
236
|
+
return { ok: true, recoveredAddress: recovered };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
158
246
|
|
|
159
247
|
|
|
160
248
|
|
|
161
249
|
|
|
162
|
-
exports.createLoginMessage = createLoginMessage; exports.parseLoginMessage = parseLoginMessage; exports.verifyLoginMessage = verifyLoginMessage;
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
250
|
+
exports.createLoginMessage = createLoginMessage; exports.parseLoginMessage = parseLoginMessage; exports.verifyLoginMessage = verifyLoginMessage; exports.SPONSOR_AUTH_DOMAIN_NAME = SPONSOR_AUTH_DOMAIN_NAME; exports.SPONSOR_AUTH_TYPES = SPONSOR_AUTH_TYPES; exports.buildSponsorAuthDomain = buildSponsorAuthDomain; exports.buildSponsorAuthTypedData = buildSponsorAuthTypedData; exports.computeCallDataHash = computeCallDataHash; exports.signSponsorAuth = signSponsorAuth; exports.verifySponsorAuth = verifySponsorAuth;
|
|
251
|
+
//# sourceMappingURL=chunk-FNJZUNK3.cjs.map
|