@bananapus/nana-sdk-core 1.9.4 → 1.10.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/dist/cjs/v6/directPay.d.ts +69 -0
- package/dist/cjs/v6/directPay.d.ts.map +1 -0
- package/dist/cjs/v6/directPay.js +391 -0
- package/dist/cjs/v6/directPay.js.map +1 -0
- package/dist/cjs/v6/index.d.ts +2 -0
- package/dist/cjs/v6/index.d.ts.map +1 -1
- package/dist/cjs/v6/index.js +2 -0
- package/dist/cjs/v6/index.js.map +1 -1
- package/dist/cjs/v6/loans.d.ts +25 -0
- package/dist/cjs/v6/loans.d.ts.map +1 -1
- package/dist/cjs/v6/loans.js +42 -1
- package/dist/cjs/v6/loans.js.map +1 -1
- package/dist/cjs/v6/permit2.d.ts +169 -0
- package/dist/cjs/v6/permit2.d.ts.map +1 -0
- package/dist/cjs/v6/permit2.js +145 -0
- package/dist/cjs/v6/permit2.js.map +1 -0
- package/dist/esm/v6/directPay.d.ts +69 -0
- package/dist/esm/v6/directPay.d.ts.map +1 -0
- package/dist/esm/v6/directPay.js +385 -0
- package/dist/esm/v6/directPay.js.map +1 -0
- package/dist/esm/v6/index.d.ts +2 -0
- package/dist/esm/v6/index.d.ts.map +1 -1
- package/dist/esm/v6/index.js +2 -0
- package/dist/esm/v6/index.js.map +1 -1
- package/dist/esm/v6/loans.d.ts +25 -0
- package/dist/esm/v6/loans.d.ts.map +1 -1
- package/dist/esm/v6/loans.js +39 -0
- package/dist/esm/v6/loans.js.map +1 -1
- package/dist/esm/v6/permit2.d.ts +169 -0
- package/dist/esm/v6/permit2.d.ts.map +1 -0
- package/dist/esm/v6/permit2.js +136 -0
- package/dist/esm/v6/permit2.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient } from "viem";
|
|
2
|
+
import type { JBChainId } from "../types.js";
|
|
3
|
+
/** Canonical Permit2 deployment shared by supported EVM chains. */
|
|
4
|
+
export declare const PERMIT2_ADDRESS: `0x${string}`;
|
|
5
|
+
/** Permit2 methods used to inspect or establish Universal Router allowances. */
|
|
6
|
+
export declare const permit2Abi: readonly [{
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly name: "allowance";
|
|
9
|
+
readonly stateMutability: "view";
|
|
10
|
+
readonly inputs: readonly [{
|
|
11
|
+
readonly name: "owner";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "token";
|
|
15
|
+
readonly type: "address";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "spender";
|
|
18
|
+
readonly type: "address";
|
|
19
|
+
}];
|
|
20
|
+
readonly outputs: readonly [{
|
|
21
|
+
readonly name: "amount";
|
|
22
|
+
readonly type: "uint160";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "expiration";
|
|
25
|
+
readonly type: "uint48";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "nonce";
|
|
28
|
+
readonly type: "uint48";
|
|
29
|
+
}];
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "function";
|
|
32
|
+
readonly name: "approve";
|
|
33
|
+
readonly stateMutability: "nonpayable";
|
|
34
|
+
readonly inputs: readonly [{
|
|
35
|
+
readonly name: "token";
|
|
36
|
+
readonly type: "address";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "spender";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "amount";
|
|
42
|
+
readonly type: "uint160";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "expiration";
|
|
45
|
+
readonly type: "uint48";
|
|
46
|
+
}];
|
|
47
|
+
readonly outputs: readonly [];
|
|
48
|
+
}];
|
|
49
|
+
/** EIP-712 types for Permit2's one-token, one-spender authorization. */
|
|
50
|
+
export declare const PERMIT2_TYPES: {
|
|
51
|
+
readonly PermitDetails: readonly [{
|
|
52
|
+
readonly name: "token";
|
|
53
|
+
readonly type: "address";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "amount";
|
|
56
|
+
readonly type: "uint160";
|
|
57
|
+
}, {
|
|
58
|
+
readonly name: "expiration";
|
|
59
|
+
readonly type: "uint48";
|
|
60
|
+
}, {
|
|
61
|
+
readonly name: "nonce";
|
|
62
|
+
readonly type: "uint48";
|
|
63
|
+
}];
|
|
64
|
+
readonly PermitSingle: readonly [{
|
|
65
|
+
readonly name: "details";
|
|
66
|
+
readonly type: "PermitDetails";
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "spender";
|
|
69
|
+
readonly type: "address";
|
|
70
|
+
}, {
|
|
71
|
+
readonly name: "sigDeadline";
|
|
72
|
+
readonly type: "uint256";
|
|
73
|
+
}];
|
|
74
|
+
};
|
|
75
|
+
export interface Permit2SignatureAuthorization {
|
|
76
|
+
chainId: JBChainId;
|
|
77
|
+
token: Address;
|
|
78
|
+
spender: Address;
|
|
79
|
+
amount: bigint;
|
|
80
|
+
expiration: number;
|
|
81
|
+
nonce: number;
|
|
82
|
+
sigDeadline: bigint;
|
|
83
|
+
}
|
|
84
|
+
export interface Permit2Allowance {
|
|
85
|
+
amount: bigint;
|
|
86
|
+
expiration: number;
|
|
87
|
+
nonce: number;
|
|
88
|
+
}
|
|
89
|
+
/** Build the exact typed-data payload a wallet signs for PermitSingle. */
|
|
90
|
+
export declare function permit2TypedData(authorization: Permit2SignatureAuthorization): {
|
|
91
|
+
domain: {
|
|
92
|
+
name: "Permit2";
|
|
93
|
+
chainId: 1 | 11155111 | 10 | 11155420 | 8453 | 84532 | 42161 | 421614;
|
|
94
|
+
verifyingContract: `0x${string}`;
|
|
95
|
+
};
|
|
96
|
+
types: {
|
|
97
|
+
readonly PermitDetails: readonly [{
|
|
98
|
+
readonly name: "token";
|
|
99
|
+
readonly type: "address";
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "amount";
|
|
102
|
+
readonly type: "uint160";
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: "expiration";
|
|
105
|
+
readonly type: "uint48";
|
|
106
|
+
}, {
|
|
107
|
+
readonly name: "nonce";
|
|
108
|
+
readonly type: "uint48";
|
|
109
|
+
}];
|
|
110
|
+
readonly PermitSingle: readonly [{
|
|
111
|
+
readonly name: "details";
|
|
112
|
+
readonly type: "PermitDetails";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "spender";
|
|
115
|
+
readonly type: "address";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "sigDeadline";
|
|
118
|
+
readonly type: "uint256";
|
|
119
|
+
}];
|
|
120
|
+
};
|
|
121
|
+
primaryType: "PermitSingle";
|
|
122
|
+
message: {
|
|
123
|
+
details: {
|
|
124
|
+
token: `0x${string}`;
|
|
125
|
+
amount: bigint;
|
|
126
|
+
expiration: number;
|
|
127
|
+
nonce: number;
|
|
128
|
+
};
|
|
129
|
+
spender: `0x${string}`;
|
|
130
|
+
sigDeadline: bigint;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/** Read an owner's Permit2 allowance, defaulting the spender to Universal Router. */
|
|
134
|
+
export declare function readPermit2Allowance(client: PublicClient, { chainId, owner, token, spender, }: {
|
|
135
|
+
chainId: JBChainId;
|
|
136
|
+
owner: Address;
|
|
137
|
+
token: Address;
|
|
138
|
+
spender?: Address;
|
|
139
|
+
}): Promise<Permit2Allowance>;
|
|
140
|
+
/** Whether an allowance is too small or expires inside the safety buffer. */
|
|
141
|
+
export declare function permit2AllowanceNeedsRefresh({ allowance, amount, now, expirationBufferSeconds, }: {
|
|
142
|
+
allowance: Pick<Permit2Allowance, "amount" | "expiration">;
|
|
143
|
+
amount: bigint;
|
|
144
|
+
now?: number;
|
|
145
|
+
expirationBufferSeconds?: number;
|
|
146
|
+
}): boolean;
|
|
147
|
+
/** Read whether an ERC-20 needs a fresh Permit2 authorization for Universal Router. */
|
|
148
|
+
export declare function needsPermit2Approval({ client, chainId, owner, token, amount, now, expirationBufferSeconds, }: {
|
|
149
|
+
client: PublicClient;
|
|
150
|
+
chainId: JBChainId;
|
|
151
|
+
owner: Address;
|
|
152
|
+
token: Address;
|
|
153
|
+
amount: bigint;
|
|
154
|
+
now?: number;
|
|
155
|
+
expirationBufferSeconds?: number;
|
|
156
|
+
}): Promise<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* Prefer a gasless Permit2 signature for EOAs. Contract wallets generally need
|
|
159
|
+
* the on-chain Permit2 approval path unless their integration handles ERC-1271.
|
|
160
|
+
*/
|
|
161
|
+
export declare function shouldUsePermit2Signature({ needsApproval, walletLookupSettled, walletBytecode, isSafe, }: {
|
|
162
|
+
needsApproval: boolean;
|
|
163
|
+
walletLookupSettled: boolean;
|
|
164
|
+
walletBytecode?: Hex;
|
|
165
|
+
isSafe: boolean;
|
|
166
|
+
}): boolean;
|
|
167
|
+
/** Fall back only for wallets that cannot sign typed data, never on rejection. */
|
|
168
|
+
export declare function permit2SignatureNeedsOnchainFallback(error: unknown): boolean;
|
|
169
|
+
//# sourceMappingURL=permit2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../src/v6/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,mEAAmE;AACnE,eAAO,MAAM,eAAe,eAA0B,CAAC;AAEvD,gFAAgF;AAChF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4Bb,CAAC;AAEX,wEAAwE;AACxE,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAYhB,CAAC;AAEX,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MA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CAAC,EAAE,MAAM,CAAC;IACb,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,OAAO,CAAC,CAanB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,MAAM,GACP,EAAE;IACD,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CAGV;AAED,kFAAkF;AAClF,wBAAgB,oCAAoC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAgB5E"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMIT2_TYPES = exports.permit2Abi = exports.PERMIT2_ADDRESS = void 0;
|
|
4
|
+
exports.permit2TypedData = permit2TypedData;
|
|
5
|
+
exports.readPermit2Allowance = readPermit2Allowance;
|
|
6
|
+
exports.permit2AllowanceNeedsRefresh = permit2AllowanceNeedsRefresh;
|
|
7
|
+
exports.needsPermit2Approval = needsPermit2Approval;
|
|
8
|
+
exports.shouldUsePermit2Signature = shouldUsePermit2Signature;
|
|
9
|
+
exports.permit2SignatureNeedsOnchainFallback = permit2SignatureNeedsOnchainFallback;
|
|
10
|
+
const constants_js_1 = require("../constants.js");
|
|
11
|
+
const uniswapV4_js_1 = require("./uniswapV4.js");
|
|
12
|
+
/** Canonical Permit2 deployment shared by supported EVM chains. */
|
|
13
|
+
exports.PERMIT2_ADDRESS = uniswapV4_js_1.UNISWAP_PERMIT2_ADDRESS;
|
|
14
|
+
/** Permit2 methods used to inspect or establish Universal Router allowances. */
|
|
15
|
+
exports.permit2Abi = [
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
name: "allowance",
|
|
19
|
+
stateMutability: "view",
|
|
20
|
+
inputs: [
|
|
21
|
+
{ name: "owner", type: "address" },
|
|
22
|
+
{ name: "token", type: "address" },
|
|
23
|
+
{ name: "spender", type: "address" },
|
|
24
|
+
],
|
|
25
|
+
outputs: [
|
|
26
|
+
{ name: "amount", type: "uint160" },
|
|
27
|
+
{ name: "expiration", type: "uint48" },
|
|
28
|
+
{ name: "nonce", type: "uint48" },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "function",
|
|
33
|
+
name: "approve",
|
|
34
|
+
stateMutability: "nonpayable",
|
|
35
|
+
inputs: [
|
|
36
|
+
{ name: "token", type: "address" },
|
|
37
|
+
{ name: "spender", type: "address" },
|
|
38
|
+
{ name: "amount", type: "uint160" },
|
|
39
|
+
{ name: "expiration", type: "uint48" },
|
|
40
|
+
],
|
|
41
|
+
outputs: [],
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
/** EIP-712 types for Permit2's one-token, one-spender authorization. */
|
|
45
|
+
exports.PERMIT2_TYPES = {
|
|
46
|
+
PermitDetails: [
|
|
47
|
+
{ name: "token", type: "address" },
|
|
48
|
+
{ name: "amount", type: "uint160" },
|
|
49
|
+
{ name: "expiration", type: "uint48" },
|
|
50
|
+
{ name: "nonce", type: "uint48" },
|
|
51
|
+
],
|
|
52
|
+
PermitSingle: [
|
|
53
|
+
{ name: "details", type: "PermitDetails" },
|
|
54
|
+
{ name: "spender", type: "address" },
|
|
55
|
+
{ name: "sigDeadline", type: "uint256" },
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
/** Build the exact typed-data payload a wallet signs for PermitSingle. */
|
|
59
|
+
function permit2TypedData(authorization) {
|
|
60
|
+
return {
|
|
61
|
+
domain: {
|
|
62
|
+
name: "Permit2",
|
|
63
|
+
chainId: authorization.chainId,
|
|
64
|
+
verifyingContract: exports.PERMIT2_ADDRESS,
|
|
65
|
+
},
|
|
66
|
+
types: exports.PERMIT2_TYPES,
|
|
67
|
+
primaryType: "PermitSingle",
|
|
68
|
+
message: {
|
|
69
|
+
details: {
|
|
70
|
+
token: authorization.token,
|
|
71
|
+
amount: authorization.amount,
|
|
72
|
+
expiration: authorization.expiration,
|
|
73
|
+
nonce: authorization.nonce,
|
|
74
|
+
},
|
|
75
|
+
spender: authorization.spender,
|
|
76
|
+
sigDeadline: authorization.sigDeadline,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Read an owner's Permit2 allowance, defaulting the spender to Universal Router. */
|
|
81
|
+
async function readPermit2Allowance(client, { chainId, owner, token, spender, }) {
|
|
82
|
+
const resolvedSpender = spender ?? (0, uniswapV4_js_1.uniswapV4Deployment)(chainId)?.universalRouter;
|
|
83
|
+
if (!resolvedSpender) {
|
|
84
|
+
throw new Error(`No supported Uniswap Universal Router on chain ${chainId}.`);
|
|
85
|
+
}
|
|
86
|
+
const [amount, expiration, nonce] = await client.readContract({
|
|
87
|
+
address: exports.PERMIT2_ADDRESS,
|
|
88
|
+
abi: exports.permit2Abi,
|
|
89
|
+
functionName: "allowance",
|
|
90
|
+
args: [owner, token, resolvedSpender],
|
|
91
|
+
});
|
|
92
|
+
return { amount, expiration, nonce };
|
|
93
|
+
}
|
|
94
|
+
/** Whether an allowance is too small or expires inside the safety buffer. */
|
|
95
|
+
function permit2AllowanceNeedsRefresh({ allowance, amount, now = Math.floor(Date.now() / 1000), expirationBufferSeconds = 1_800, }) {
|
|
96
|
+
if (expirationBufferSeconds < 0) {
|
|
97
|
+
throw new Error("expirationBufferSeconds cannot be negative.");
|
|
98
|
+
}
|
|
99
|
+
return (allowance.amount < amount ||
|
|
100
|
+
allowance.expiration <= now + expirationBufferSeconds);
|
|
101
|
+
}
|
|
102
|
+
/** Read whether an ERC-20 needs a fresh Permit2 authorization for Universal Router. */
|
|
103
|
+
async function needsPermit2Approval({ client, chainId, owner, token, amount, now, expirationBufferSeconds, }) {
|
|
104
|
+
if (token.toLowerCase() === constants_js_1.NATIVE_TOKEN.toLowerCase())
|
|
105
|
+
return false;
|
|
106
|
+
const allowance = await readPermit2Allowance(client, {
|
|
107
|
+
chainId,
|
|
108
|
+
owner,
|
|
109
|
+
token,
|
|
110
|
+
});
|
|
111
|
+
return permit2AllowanceNeedsRefresh({
|
|
112
|
+
allowance,
|
|
113
|
+
amount,
|
|
114
|
+
now,
|
|
115
|
+
expirationBufferSeconds,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Prefer a gasless Permit2 signature for EOAs. Contract wallets generally need
|
|
120
|
+
* the on-chain Permit2 approval path unless their integration handles ERC-1271.
|
|
121
|
+
*/
|
|
122
|
+
function shouldUsePermit2Signature({ needsApproval, walletLookupSettled, walletBytecode, isSafe, }) {
|
|
123
|
+
const isContract = !!walletBytecode && walletBytecode !== "0x";
|
|
124
|
+
return needsApproval && walletLookupSettled && !isContract && !isSafe;
|
|
125
|
+
}
|
|
126
|
+
/** Fall back only for wallets that cannot sign typed data, never on rejection. */
|
|
127
|
+
function permit2SignatureNeedsOnchainFallback(error) {
|
|
128
|
+
const messages = [];
|
|
129
|
+
let current = error;
|
|
130
|
+
for (let depth = 0; current && depth < 5; depth += 1) {
|
|
131
|
+
if (typeof current !== "object")
|
|
132
|
+
break;
|
|
133
|
+
const value = current;
|
|
134
|
+
for (const key of ["code", "shortMessage", "message", "details"]) {
|
|
135
|
+
if (value[key] !== undefined)
|
|
136
|
+
messages.push(String(value[key]));
|
|
137
|
+
}
|
|
138
|
+
current = value.cause;
|
|
139
|
+
}
|
|
140
|
+
const text = messages.join(" ").toLowerCase();
|
|
141
|
+
if (/user rejected|rejected the request|denied|4001/.test(text))
|
|
142
|
+
return false;
|
|
143
|
+
return /(^|\s)-32602(\s|$)|(^|\s)-32601(\s|$)|(^|\s)4200(\s|$)|invalid parameters|method .*not supported|unsupported method|typed data.*not supported/.test(text);
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=permit2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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xC,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,MAAM,GAMP;IACC,MAAM,UAAU,GAAG,CAAC,CAAC,cAAc,IAAI,cAAc,KAAK,IAAI,CAAC;IAC/D,OAAO,aAAa,IAAI,mBAAmB,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC;AACxE,CAAC;AAED,kFAAkF;AAClF,SAAgB,oCAAoC,CAAC,KAAc;IACjE,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,OAAO,GAAY,KAAK,CAAC;IAC7B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,OAAO,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,MAAM;QACvC,MAAM,KAAK,GAAG,OAAkC,CAAC;QACjD,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YACjE,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;IACxB,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,gDAAgD,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,OAAO,+IAA+I,CAAC,IAAI,CACzJ,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient } from "viem";
|
|
2
|
+
import type { JBChainId } from "../types.js";
|
|
3
|
+
import { type PayPreview, type PaySettlement } from "./pay.js";
|
|
4
|
+
import type { Permit2SignatureAuthorization } from "./permit2.js";
|
|
5
|
+
import { type UniswapV4PoolKey } from "./uniswapV4.js";
|
|
6
|
+
export interface NativeSwapConfig {
|
|
7
|
+
wrappedNative: Address;
|
|
8
|
+
bridgeToken: Address;
|
|
9
|
+
v3Quoter: Address;
|
|
10
|
+
}
|
|
11
|
+
/** Canonical WETH/USDC V3 bridge used by direct-pay swaps on all v6 mainnets. */
|
|
12
|
+
export declare const NATIVE_SWAP_BY_CHAIN: Readonly<Partial<Record<JBChainId, NativeSwapConfig>>>;
|
|
13
|
+
export type DirectPayInputRoute = {
|
|
14
|
+
kind: "single-v4";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "native-v3-v4";
|
|
17
|
+
wrappedNative: Address;
|
|
18
|
+
bridgeToken: Address;
|
|
19
|
+
bridgeTokenSymbol: "USDC";
|
|
20
|
+
bridgeTokenDecimals: 6;
|
|
21
|
+
v3Fee: number;
|
|
22
|
+
quotedBridgeAmount: bigint;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "erc20-v3-native-v4";
|
|
25
|
+
inputToken: Address;
|
|
26
|
+
wrappedNative: Address;
|
|
27
|
+
bridgeTokenSymbol: "ETH";
|
|
28
|
+
bridgeTokenDecimals: 18;
|
|
29
|
+
v3Fee: number;
|
|
30
|
+
quotedBridgeAmount: bigint;
|
|
31
|
+
};
|
|
32
|
+
export interface DirectPaySwapQuote {
|
|
33
|
+
kind: "direct-swap";
|
|
34
|
+
poolKey: UniswapV4PoolKey;
|
|
35
|
+
zeroForOne: boolean;
|
|
36
|
+
quotedTokenCount: bigint;
|
|
37
|
+
/** Protected minimum and the beneficiary's direct-swap token count. */
|
|
38
|
+
minimumTokenCount: bigint;
|
|
39
|
+
beneficiaryTokenCount: bigint;
|
|
40
|
+
reservedTokenCount: 0n;
|
|
41
|
+
inputRoute: DirectPayInputRoute;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Quote the best direct pool purchase, including the atomic ETH/USDC V3 bridge
|
|
45
|
+
* when the user's payment currency differs from the hooked V4 pool currency.
|
|
46
|
+
* Returns null unless its slippage-protected minimum beats terminal payment.
|
|
47
|
+
*/
|
|
48
|
+
export declare function quoteDirectPaySwap({ client, chainId, poolKey, pairIsCurrency0, paymentToken, amount, payPreview, paySettlement, slippageBps, }: {
|
|
49
|
+
client: PublicClient;
|
|
50
|
+
chainId: JBChainId;
|
|
51
|
+
poolKey: UniswapV4PoolKey;
|
|
52
|
+
pairIsCurrency0: boolean;
|
|
53
|
+
paymentToken: Address;
|
|
54
|
+
amount: bigint;
|
|
55
|
+
payPreview: PayPreview;
|
|
56
|
+
paySettlement?: PaySettlement;
|
|
57
|
+
slippageBps?: bigint;
|
|
58
|
+
}): Promise<DirectPaySwapQuote | null>;
|
|
59
|
+
/** Build the atomic Universal Router transaction for a direct-pay quote. */
|
|
60
|
+
export declare function buildDirectPaySwapTx({ chainId, quote, amount, recipient, deadline, }: {
|
|
61
|
+
chainId: JBChainId;
|
|
62
|
+
quote: DirectPaySwapQuote;
|
|
63
|
+
amount: bigint;
|
|
64
|
+
recipient: Address;
|
|
65
|
+
deadline: bigint;
|
|
66
|
+
}): import("./uniswapV4.js").UniswapV4SwapTxRequest;
|
|
67
|
+
/** Prepend Universal Router's PERMIT2_PERMIT command to a reviewed swap. */
|
|
68
|
+
export declare function addPermit2SignatureToDirectPaySwap(request: ReturnType<typeof buildDirectPaySwapTx>, authorization: Permit2SignatureAuthorization, signature: Hex): ReturnType<typeof buildDirectPaySwapTx>;
|
|
69
|
+
//# sourceMappingURL=directPay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directPay.d.ts","sourceRoot":"","sources":["../../../src/v6/directPay.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAEL,KAAK,UAAU,EACf,KAAK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