@kehtus/proportion-sdk 0.5.0 → 1.2.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/abi/challengeAccount.d.ts +1855 -0
- package/dist/abi/challengeAccount.d.ts.map +1 -0
- package/dist/abi/challengeAccount.js +2365 -0
- package/dist/abi/challengeAccount.js.map +1 -0
- package/dist/abi/challengeFactory.d.ts +1351 -0
- package/dist/abi/challengeFactory.d.ts.map +1 -0
- package/dist/abi/challengeFactory.js +1727 -0
- package/dist/abi/challengeFactory.js.map +1 -0
- package/dist/abi/challengeVault.d.ts +1392 -0
- package/dist/abi/challengeVault.d.ts.map +1 -0
- package/dist/abi/challengeVault.js +1793 -0
- package/dist/abi/challengeVault.js.map +1 -0
- package/dist/abi/factory.d.ts +4 -0
- package/dist/abi/factory.d.ts.map +1 -1
- package/dist/abi/factory.js +5 -0
- package/dist/abi/factory.js.map +1 -1
- package/dist/abi/fundedAccount.d.ts +49 -10
- package/dist/abi/fundedAccount.d.ts.map +1 -1
- package/dist/abi/fundedAccount.js +62 -13
- package/dist/abi/fundedAccount.js.map +1 -1
- package/dist/abi/mainVault.d.ts +409 -20
- package/dist/abi/mainVault.d.ts.map +1 -1
- package/dist/abi/mainVault.js +523 -20
- package/dist/abi/mainVault.js.map +1 -1
- package/dist/abi/priceOracle.d.ts +497 -0
- package/dist/abi/priceOracle.d.ts.map +1 -0
- package/dist/abi/priceOracle.js +644 -0
- package/dist/abi/priceOracle.js.map +1 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +6 -0
- package/dist/account.js.map +1 -1
- package/dist/challenge/account.d.ts +95 -0
- package/dist/challenge/account.d.ts.map +1 -0
- package/dist/challenge/account.js +375 -0
- package/dist/challenge/account.js.map +1 -0
- package/dist/challenge/api.d.ts +49 -0
- package/dist/challenge/api.d.ts.map +1 -0
- package/dist/challenge/api.js +173 -0
- package/dist/challenge/api.js.map +1 -0
- package/dist/challenge/factory.d.ts +165 -0
- package/dist/challenge/factory.d.ts.map +1 -0
- package/dist/challenge/factory.js +392 -0
- package/dist/challenge/factory.js.map +1 -0
- package/dist/challenge/intents.d.ts +137 -0
- package/dist/challenge/intents.d.ts.map +1 -0
- package/dist/challenge/intents.js +218 -0
- package/dist/challenge/intents.js.map +1 -0
- package/dist/challenge/oracle.d.ts +50 -0
- package/dist/challenge/oracle.d.ts.map +1 -0
- package/dist/challenge/oracle.js +117 -0
- package/dist/challenge/oracle.js.map +1 -0
- package/dist/challenge/types.d.ts +652 -0
- package/dist/challenge/types.d.ts.map +1 -0
- package/dist/challenge/types.js +64 -0
- package/dist/challenge/types.js.map +1 -0
- package/dist/challenge/vault.d.ts +87 -0
- package/dist/challenge/vault.d.ts.map +1 -0
- package/dist/challenge/vault.js +299 -0
- package/dist/challenge/vault.js.map +1 -0
- package/dist/constants.d.ts +7 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +21 -3
- package/dist/constants.js.map +1 -1
- package/dist/factory.d.ts +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +12 -0
- package/dist/factory.js.map +1 -1
- package/dist/forwarder.d.ts +58 -0
- package/dist/forwarder.d.ts.map +1 -0
- package/dist/forwarder.js +145 -0
- package/dist/forwarder.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +52 -0
- package/dist/indexer.d.ts.map +1 -1
- package/dist/indexer.js +219 -4
- package/dist/indexer.js.map +1 -1
- package/dist/sdk.d.ts +23 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +122 -35
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +35 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +86 -7
- package/dist/utils.js.map +1 -1
- package/dist/vault.d.ts +44 -4
- package/dist/vault.d.ts.map +1 -1
- package/dist/vault.js +143 -9
- package/dist/vault.js.map +1 -1
- package/package.json +42 -42
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { encodeFunctionData, hashTypedData, recoverTypedDataAddress, zeroAddress, } from "viem";
|
|
2
|
+
import { challengeFactoryAbi } from "../abi/challengeFactory.js";
|
|
3
|
+
import { assertAllSuccess } from "../utils.js";
|
|
4
|
+
// EIP-712 types mirroring ChallengePricingLib.CHALLENGE_QUOTE_TYPEHASH.
|
|
5
|
+
export const CHALLENGE_QUOTE_TYPES = {
|
|
6
|
+
ChallengeQuote: [
|
|
7
|
+
{ name: "accountOwner", type: "address" },
|
|
8
|
+
{ name: "payer", type: "address" },
|
|
9
|
+
{ name: "builder", type: "address" },
|
|
10
|
+
{ name: "referrer", type: "address" },
|
|
11
|
+
{ name: "allocation", type: "uint96" },
|
|
12
|
+
{ name: "drawdownBps", type: "uint16" },
|
|
13
|
+
{ name: "dailyDrawdownEnabled", type: "bool" },
|
|
14
|
+
{ name: "tradingDaysEnabled", type: "bool" },
|
|
15
|
+
{ name: "challengeType", type: "uint8" },
|
|
16
|
+
{ name: "finalTargetProfitBps", type: "uint16" },
|
|
17
|
+
{ name: "priceMultiplierBps", type: "uint16" },
|
|
18
|
+
{ name: "quotedChallengeFee", type: "uint256" },
|
|
19
|
+
{ name: "minBuilderVaultAmount", type: "uint256" },
|
|
20
|
+
{ name: "deadline", type: "uint64" },
|
|
21
|
+
{ name: "nonce", type: "uint256" },
|
|
22
|
+
{ name: "quoteConfigNonce", type: "uint256" },
|
|
23
|
+
{ name: "builderQuoteEpoch", type: "uint256" },
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
// IBuilderRegistryViews.delegateBuilder — the only registry read verifyQuote needs.
|
|
27
|
+
const delegateBuilderAbi = [
|
|
28
|
+
{
|
|
29
|
+
type: "function",
|
|
30
|
+
name: "delegateBuilder",
|
|
31
|
+
stateMutability: "view",
|
|
32
|
+
inputs: [{ name: "delegate", type: "address" }],
|
|
33
|
+
outputs: [{ name: "builder", type: "address" }],
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* ChallengeFactory module — signed-quote purchases plus builder quote administration.
|
|
38
|
+
*
|
|
39
|
+
* Quotes are priced and signed by the builder's quote-signer service; the SDK's job is to
|
|
40
|
+
* verify them (verifyQuote / previewQuote) and spend them (buyChallenge). Owner pricing/risk
|
|
41
|
+
* config setters are multisig territory and intentionally not covered.
|
|
42
|
+
*/
|
|
43
|
+
export class ChallengeFactoryModule {
|
|
44
|
+
publicClient;
|
|
45
|
+
walletClient;
|
|
46
|
+
chain;
|
|
47
|
+
addressResolver;
|
|
48
|
+
/** builderRegistry is immutable on the factory — cached after the first delegate check. */
|
|
49
|
+
builderRegistryCache;
|
|
50
|
+
resolvedAddress;
|
|
51
|
+
addressPromise;
|
|
52
|
+
constructor(publicClient, walletClient, chain, addressResolver) {
|
|
53
|
+
this.publicClient = publicClient;
|
|
54
|
+
this.walletClient = walletClient;
|
|
55
|
+
this.chain = chain;
|
|
56
|
+
this.addressResolver = addressResolver;
|
|
57
|
+
if (typeof addressResolver === "string")
|
|
58
|
+
this.resolvedAddress = addressResolver;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolved ChallengeFactory address, lazily fetched when constructed with a resolver
|
|
62
|
+
* function (e.g. from the indexer's ProtocolConfig). The in-flight promise is cached so
|
|
63
|
+
* concurrent callers share one lookup; a failed resolution clears the cache for retry.
|
|
64
|
+
* Once resolved, the address is memoized so the synchronous `address`/`quoteDigest`
|
|
65
|
+
* accessors below work without an extra round trip.
|
|
66
|
+
*/
|
|
67
|
+
async getAddress() {
|
|
68
|
+
if (this.resolvedAddress)
|
|
69
|
+
return this.resolvedAddress;
|
|
70
|
+
if (!this.addressPromise) {
|
|
71
|
+
const resolver = this.addressResolver;
|
|
72
|
+
this.addressPromise = resolver()
|
|
73
|
+
.then((addr) => {
|
|
74
|
+
this.resolvedAddress = addr;
|
|
75
|
+
return addr;
|
|
76
|
+
})
|
|
77
|
+
.catch((err) => {
|
|
78
|
+
this.addressPromise = undefined;
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return this.addressPromise;
|
|
83
|
+
}
|
|
84
|
+
/** Throws if constructed with a resolver and no async method has resolved it yet — see getAddress(). */
|
|
85
|
+
get address() {
|
|
86
|
+
if (!this.resolvedAddress) {
|
|
87
|
+
throw new Error("ChallengeFactory address not yet resolved. Await getAddress() (or any async method on this " +
|
|
88
|
+
"module) first, or construct the SDK with config.addresses.CHALLENGE_FACTORY set.");
|
|
89
|
+
}
|
|
90
|
+
return this.resolvedAddress;
|
|
91
|
+
}
|
|
92
|
+
requireWallet() {
|
|
93
|
+
if (!this.walletClient)
|
|
94
|
+
throw new Error("WalletClient required for write operations");
|
|
95
|
+
const walletChainId = this.walletClient.chain?.id;
|
|
96
|
+
if (walletChainId !== undefined && walletChainId !== this.chain.id) {
|
|
97
|
+
throw new Error(`WalletClient chain mismatch: expected ${this.chain.id}, got ${walletChainId}`);
|
|
98
|
+
}
|
|
99
|
+
return this.walletClient;
|
|
100
|
+
}
|
|
101
|
+
async write(params) {
|
|
102
|
+
const wallet = this.requireWallet();
|
|
103
|
+
const account = wallet.account;
|
|
104
|
+
if (!account)
|
|
105
|
+
throw new Error("WalletClient has no account");
|
|
106
|
+
return wallet.writeContract({ ...params, chain: this.chain, account });
|
|
107
|
+
}
|
|
108
|
+
// ── READS ───────────────────────────────────────────
|
|
109
|
+
/** Factory wiring + quote freshness anchors (quoteConfigNonce invalidates all quotes on config change). */
|
|
110
|
+
async getConfig() {
|
|
111
|
+
const contract = { address: await this.getAddress(), abi: challengeFactoryAbi };
|
|
112
|
+
const results = await this.publicClient.multicall({
|
|
113
|
+
contracts: [
|
|
114
|
+
{ ...contract, functionName: "vault" },
|
|
115
|
+
{ ...contract, functionName: "oracle" },
|
|
116
|
+
{ ...contract, functionName: "implementation" },
|
|
117
|
+
{ ...contract, functionName: "builderRegistry" },
|
|
118
|
+
{ ...contract, functionName: "owner" },
|
|
119
|
+
{ ...contract, functionName: "pendingOwner" },
|
|
120
|
+
{ ...contract, functionName: "quoteConfigNonce" },
|
|
121
|
+
{ ...contract, functionName: "maxOpenPositions" },
|
|
122
|
+
{ ...contract, functionName: "minHoldBlocks" },
|
|
123
|
+
{ ...contract, functionName: "allAccountsLength" },
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
const r = assertAllSuccess(results);
|
|
127
|
+
return {
|
|
128
|
+
vault: r[0],
|
|
129
|
+
oracle: r[1],
|
|
130
|
+
implementation: r[2],
|
|
131
|
+
builderRegistry: r[3],
|
|
132
|
+
owner: r[4],
|
|
133
|
+
pendingOwner: r[5],
|
|
134
|
+
quoteConfigNonce: r[6],
|
|
135
|
+
maxOpenPositions: r[7],
|
|
136
|
+
minHoldBlocks: r[8],
|
|
137
|
+
accountsCount: r[9],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async getPricingConfig() {
|
|
141
|
+
const c = await this.publicClient.readContract({
|
|
142
|
+
address: await this.getAddress(),
|
|
143
|
+
abi: challengeFactoryAbi,
|
|
144
|
+
functionName: "pricingConfig",
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
challengeFeeBps: c.challengeFeeBps,
|
|
148
|
+
protocolFeeBps: c.protocolFeeBps,
|
|
149
|
+
referralFeeBps: c.referralFeeBps,
|
|
150
|
+
referenceDrawdownBps: c.referenceDrawdownBps,
|
|
151
|
+
challengeFeeMultiplierBps: c.challengeFeeMultiplierBps,
|
|
152
|
+
noDailyDrawdownSurchargeBps: c.noDailyDrawdownSurchargeBps,
|
|
153
|
+
noTradingDaysSurchargeBps: c.noTradingDaysSurchargeBps,
|
|
154
|
+
minBuilderPriceMultiplierBps: c.minBuilderPriceMultiplierBps,
|
|
155
|
+
maxBuilderPriceMultiplierBps: c.maxBuilderPriceMultiplierBps,
|
|
156
|
+
twoStepDiscountBps: c.twoStepDiscountBps,
|
|
157
|
+
maxLeverageBps: c.maxLeverageBps,
|
|
158
|
+
minAllocation: c.minAllocation,
|
|
159
|
+
maxAllocation: c.maxAllocation,
|
|
160
|
+
minDrawdownBps: c.minDrawdownBps,
|
|
161
|
+
maxDrawdownBps: c.maxDrawdownBps,
|
|
162
|
+
oneStepProfitableDaysRequired: c.oneStepProfitableDaysRequired,
|
|
163
|
+
twoStepProfitableDaysRequired: c.twoStepProfitableDaysRequired,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Immutable terms a challenge account was minted with. */
|
|
167
|
+
async getChallengeTerms(account) {
|
|
168
|
+
const t = await this.publicClient.readContract({
|
|
169
|
+
address: await this.getAddress(),
|
|
170
|
+
abi: challengeFactoryAbi,
|
|
171
|
+
functionName: "challengeTerms",
|
|
172
|
+
args: [account],
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
challengeType: t.challengeType,
|
|
176
|
+
trader: t.trader,
|
|
177
|
+
builder: t.builder,
|
|
178
|
+
totalSteps: t.totalSteps,
|
|
179
|
+
allocation6: t.allocation6,
|
|
180
|
+
drawdownBps: t.drawdownBps,
|
|
181
|
+
dailyDrawdownEnabled: t.dailyDrawdownEnabled,
|
|
182
|
+
tradingDaysEnabled: t.tradingDaysEnabled,
|
|
183
|
+
profitableDaysRequired: t.profitableDaysRequired,
|
|
184
|
+
stepTargetProfitBps: t.stepTargetProfitBps,
|
|
185
|
+
finalTargetProfitBps: t.finalTargetProfitBps,
|
|
186
|
+
challengeFee: t.challengeFee,
|
|
187
|
+
builderAmount: t.builderAmount,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* On-chain fee re-derivation for a quote. This is the authoritative pricing check —
|
|
192
|
+
* do NOT re-implement ChallengePricingLib math off-chain, it drifts on config changes.
|
|
193
|
+
*/
|
|
194
|
+
async previewQuote(quote) {
|
|
195
|
+
const fees = await this.publicClient.readContract({
|
|
196
|
+
address: await this.getAddress(),
|
|
197
|
+
abi: challengeFactoryAbi,
|
|
198
|
+
functionName: "previewQuotedChallenge",
|
|
199
|
+
args: [quote],
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
challengeFee: fees.challengeFee,
|
|
203
|
+
builderAmount: fees.builderAmount,
|
|
204
|
+
protocolFee: fees.protocolFee,
|
|
205
|
+
referralFee: fees.referralFee,
|
|
206
|
+
maxNotional: fees.maxNotional,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Local EIP-712 digest of a quote (no RPC; matches challengeQuoteDigest on-chain). Requires the address to already be resolved — see getAddress(). */
|
|
210
|
+
quoteDigest(quote) {
|
|
211
|
+
return this.digestFor(this.address, quote);
|
|
212
|
+
}
|
|
213
|
+
digestFor(factoryAddress, quote) {
|
|
214
|
+
return hashTypedData({
|
|
215
|
+
domain: {
|
|
216
|
+
name: "ProportionChallengeFactory",
|
|
217
|
+
version: "1",
|
|
218
|
+
chainId: this.chain.id,
|
|
219
|
+
verifyingContract: factoryAddress,
|
|
220
|
+
},
|
|
221
|
+
types: CHALLENGE_QUOTE_TYPES,
|
|
222
|
+
primaryType: "ChallengeQuote",
|
|
223
|
+
message: quote,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Verify a builder quote signature before paying for it. Recovers the ECDSA signer locally,
|
|
228
|
+
* accepts the builder EOA directly, and falls back to a MainVault.delegateBuilder registry
|
|
229
|
+
* check over RPC. ERC-1271 contract signatures cannot be recovered off-chain — those return
|
|
230
|
+
* valid=false and must be validated by on-chain simulation instead.
|
|
231
|
+
*/
|
|
232
|
+
async verifyQuote(quote, signature) {
|
|
233
|
+
const factoryAddress = await this.getAddress();
|
|
234
|
+
const digest = this.digestFor(factoryAddress, quote);
|
|
235
|
+
let signer = null;
|
|
236
|
+
try {
|
|
237
|
+
signer = await recoverTypedDataAddress({
|
|
238
|
+
domain: {
|
|
239
|
+
name: "ProportionChallengeFactory",
|
|
240
|
+
version: "1",
|
|
241
|
+
chainId: this.chain.id,
|
|
242
|
+
verifyingContract: factoryAddress,
|
|
243
|
+
},
|
|
244
|
+
types: CHALLENGE_QUOTE_TYPES,
|
|
245
|
+
primaryType: "ChallengeQuote",
|
|
246
|
+
message: quote,
|
|
247
|
+
signature,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return { digest, signer: null, isBuilderSigned: false, isDelegateSigned: false, valid: false };
|
|
252
|
+
}
|
|
253
|
+
const isBuilderSigned = signer.toLowerCase() === quote.builder.toLowerCase();
|
|
254
|
+
let isDelegateSigned = false;
|
|
255
|
+
if (!isBuilderSigned) {
|
|
256
|
+
try {
|
|
257
|
+
this.builderRegistryCache ??= await this.publicClient.readContract({
|
|
258
|
+
address: factoryAddress,
|
|
259
|
+
abi: challengeFactoryAbi,
|
|
260
|
+
functionName: "builderRegistry",
|
|
261
|
+
});
|
|
262
|
+
const delegatedTo = await this.publicClient.readContract({
|
|
263
|
+
address: this.builderRegistryCache,
|
|
264
|
+
abi: delegateBuilderAbi,
|
|
265
|
+
functionName: "delegateBuilder",
|
|
266
|
+
args: [signer],
|
|
267
|
+
});
|
|
268
|
+
isDelegateSigned = delegatedTo !== zeroAddress && delegatedTo.toLowerCase() === quote.builder.toLowerCase();
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
isDelegateSigned = false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return { digest, signer, isBuilderSigned, isDelegateSigned, valid: isBuilderSigned || isDelegateSigned };
|
|
275
|
+
}
|
|
276
|
+
/** Deterministic clone address for the trader's next challenge with this builder. */
|
|
277
|
+
async predictChallengeAccount(trader, builder) {
|
|
278
|
+
return this.publicClient.readContract({
|
|
279
|
+
address: await this.getAddress(),
|
|
280
|
+
abi: challengeFactoryAbi,
|
|
281
|
+
functionName: "predictChallengeAccount",
|
|
282
|
+
args: [trader, builder],
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async getAccountAt(index) {
|
|
286
|
+
return this.publicClient.readContract({
|
|
287
|
+
address: await this.getAddress(),
|
|
288
|
+
abi: challengeFactoryAbi,
|
|
289
|
+
functionName: "allAccounts",
|
|
290
|
+
args: [index],
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/** Current per-builder epoch; bumping it (incrementBuilderQuoteEpoch) voids all prior quotes. */
|
|
294
|
+
async getBuilderQuoteEpoch(builder) {
|
|
295
|
+
return this.publicClient.readContract({
|
|
296
|
+
address: await this.getAddress(),
|
|
297
|
+
abi: challengeFactoryAbi,
|
|
298
|
+
functionName: "builderQuoteEpoch",
|
|
299
|
+
args: [builder],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async isQuoteNonceUsed(builder, nonce) {
|
|
303
|
+
return this.publicClient.readContract({
|
|
304
|
+
address: await this.getAddress(),
|
|
305
|
+
abi: challengeFactoryAbi,
|
|
306
|
+
functionName: "usedQuoteNonces",
|
|
307
|
+
args: [builder, nonce],
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
// ── BUYER WRITES ────────────────────────────────────
|
|
311
|
+
/**
|
|
312
|
+
* Direct-gas purchase of a builder-signed quote. Requires prior USDC allowance from the
|
|
313
|
+
* payer to the ChallengeVault. `maxChallengeFee` defaults to the quoted fee (no slippage).
|
|
314
|
+
* For gasless UX submit through the challenge-service /purchase route instead.
|
|
315
|
+
*/
|
|
316
|
+
async buyChallenge(quote, builderSignature, maxChallengeFee) {
|
|
317
|
+
return this.write({
|
|
318
|
+
address: await this.getAddress(),
|
|
319
|
+
abi: challengeFactoryAbi,
|
|
320
|
+
functionName: "buyChallenge",
|
|
321
|
+
args: [quote, maxChallengeFee ?? quote.quotedChallengeFee, builderSignature],
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Calldata for buyChallengeWithPermit — the ONLY call shape the challenge-service
|
|
326
|
+
* gasless POST /purchase route accepts (it strictly decodes this selector and requires
|
|
327
|
+
* permitValue >= quotedChallengeFee). Wrap it in a ForwardRequest via
|
|
328
|
+
* ForwarderModule.signRequest({ to: factory, data }) and submit with
|
|
329
|
+
* ChallengeApiClient.purchase.
|
|
330
|
+
*/
|
|
331
|
+
static encodeBuyChallengeWithPermit(p) {
|
|
332
|
+
return encodeFunctionData({
|
|
333
|
+
abi: challengeFactoryAbi,
|
|
334
|
+
functionName: "buyChallengeWithPermit",
|
|
335
|
+
args: [
|
|
336
|
+
p.quote,
|
|
337
|
+
p.maxChallengeFee ?? p.quote.quotedChallengeFee,
|
|
338
|
+
p.builderSignature,
|
|
339
|
+
p.permitValue,
|
|
340
|
+
p.permitDeadline,
|
|
341
|
+
p.v,
|
|
342
|
+
p.r,
|
|
343
|
+
p.s,
|
|
344
|
+
],
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** Purchase with an ERC-2612 permit (first-time users with no vault allowance). */
|
|
348
|
+
async buyChallengeWithPermit(p) {
|
|
349
|
+
return this.write({
|
|
350
|
+
address: await this.getAddress(),
|
|
351
|
+
abi: challengeFactoryAbi,
|
|
352
|
+
functionName: "buyChallengeWithPermit",
|
|
353
|
+
args: [
|
|
354
|
+
p.quote,
|
|
355
|
+
p.maxChallengeFee ?? p.quote.quotedChallengeFee,
|
|
356
|
+
p.builderSignature,
|
|
357
|
+
p.permitValue,
|
|
358
|
+
p.permitDeadline,
|
|
359
|
+
p.v,
|
|
360
|
+
p.r,
|
|
361
|
+
p.s,
|
|
362
|
+
],
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// ── BUILDER QUOTE ADMIN (emergency quote revocation) ──
|
|
366
|
+
/** Void one outstanding quote nonce (builder or its delegate). */
|
|
367
|
+
async cancelQuoteNonce(nonce) {
|
|
368
|
+
return this.write({
|
|
369
|
+
address: await this.getAddress(),
|
|
370
|
+
abi: challengeFactoryAbi,
|
|
371
|
+
functionName: "cancelQuoteNonce",
|
|
372
|
+
args: [nonce],
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
async cancelQuoteNonces(nonces) {
|
|
376
|
+
return this.write({
|
|
377
|
+
address: await this.getAddress(),
|
|
378
|
+
abi: challengeFactoryAbi,
|
|
379
|
+
functionName: "cancelQuoteNonces",
|
|
380
|
+
args: [nonces],
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/** Void ALL outstanding quotes of the calling builder at once. */
|
|
384
|
+
async incrementBuilderQuoteEpoch() {
|
|
385
|
+
return this.write({
|
|
386
|
+
address: await this.getAddress(),
|
|
387
|
+
abi: challengeFactoryAbi,
|
|
388
|
+
functionName: "incrementBuilderQuoteEpoch",
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/challenge/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,uBAAuB,EACvB,WAAW,GASZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc,EAAE;QACd,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE;QACzC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;QAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;QACpC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE;QACtC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvC,EAAE,IA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,KAAK,CAAC;YAChB,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;YAChC,GAAG,EAAE,mBAAmB;YACxB,YAAY,EAAE,kBAAkB;YAChC,IAAI,EAAE,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,MAAgB;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;YAChC,GAAG,EAAE,mBAAmB;YACxB,YAAY,EAAE,mBAAmB;YACjC,IAAI,EAAE,CAAC,MAAM,CAAC;SACf,CAAC,CAAC;IACL,CAAC;IAED,kEAAkE;IAClE,KAAK,CAAC,0BAA0B;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;YAChC,GAAG,EAAE,mBAAmB;YACxB,YAAY,EAAE,4BAA4B;SAC3C,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hex, type PublicClient, type TypedDataDomain, type WalletClient } from "viem";
|
|
2
|
+
import type { CloseIntent, OpenIntent, SignedCloseIntent, SignedOpenIntent } from "./types.js";
|
|
3
|
+
export declare const OPEN_INTENT_TYPES: {
|
|
4
|
+
readonly OpenIntent: readonly [{
|
|
5
|
+
readonly name: "owner";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "account";
|
|
9
|
+
readonly type: "address";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "market";
|
|
12
|
+
readonly type: "uint32";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "isLong";
|
|
15
|
+
readonly type: "bool";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "margin";
|
|
18
|
+
readonly type: "uint96";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "notional";
|
|
21
|
+
readonly type: "uint96";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "maxPrice";
|
|
24
|
+
readonly type: "uint64";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "minPrice";
|
|
27
|
+
readonly type: "uint64";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "nonce";
|
|
30
|
+
readonly type: "uint256";
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "deadline";
|
|
33
|
+
readonly type: "uint64";
|
|
34
|
+
}];
|
|
35
|
+
};
|
|
36
|
+
export declare const CLOSE_INTENT_TYPES: {
|
|
37
|
+
readonly CloseIntent: readonly [{
|
|
38
|
+
readonly name: "owner";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "account";
|
|
42
|
+
readonly type: "address";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "positionId";
|
|
45
|
+
readonly type: "uint64";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "maxPrice";
|
|
48
|
+
readonly type: "uint64";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "minPrice";
|
|
51
|
+
readonly type: "uint64";
|
|
52
|
+
}, {
|
|
53
|
+
readonly name: "nonce";
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
}, {
|
|
56
|
+
readonly name: "deadline";
|
|
57
|
+
readonly type: "uint64";
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
/** SessionKeyLib permission bits (bitmask for registerSessionKey / SessionKey.permissions). */
|
|
61
|
+
export declare const SESSION_PERMISSION_OPEN: bigint;
|
|
62
|
+
export declare const SESSION_PERMISSION_CLOSE: bigint;
|
|
63
|
+
/**
|
|
64
|
+
* EIP-712 domain of a ChallengeAccount clone. The domain is bound to the clone address,
|
|
65
|
+
* so intents can never replay across accounts or chains.
|
|
66
|
+
*/
|
|
67
|
+
export declare function challengeAccountDomain(account: Address, chainId: number): TypedDataDomain;
|
|
68
|
+
/** Local EIP-712 digest of an open intent (matches ChallengeAccount's on-chain digest). */
|
|
69
|
+
export declare function hashOpenIntent(intent: OpenIntent, chainId: number): Hex;
|
|
70
|
+
/** Local EIP-712 digest of a close intent (matches ChallengeAccount's on-chain digest). */
|
|
71
|
+
export declare function hashCloseIntent(intent: CloseIntent, chainId: number): Hex;
|
|
72
|
+
/**
|
|
73
|
+
* Symmetric slippage bounds around an oracle price for intent maxPrice/minPrice.
|
|
74
|
+
* The contract checks the fill against both bounds, so setting both is safe for
|
|
75
|
+
* either side. Prices are raw HyperCore uint64 units.
|
|
76
|
+
*/
|
|
77
|
+
export declare function priceBounds(price: bigint, slippageBps: number): {
|
|
78
|
+
maxPrice: bigint;
|
|
79
|
+
minPrice: bigint;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Session-key market whitelist: bit `market` set = allowed. Markets must be < 256.
|
|
83
|
+
*
|
|
84
|
+
* CAUTION: on-chain a mask of 0 means ALL markets allowed (SessionKeyLib treats 0 as
|
|
85
|
+
* "no restriction"), which is the opposite of an empty whitelist — so an empty input
|
|
86
|
+
* throws instead of silently producing the most permissive value. To deliberately allow
|
|
87
|
+
* all markets, pass 0n to registerSessionKey directly.
|
|
88
|
+
*/
|
|
89
|
+
export declare function marketsToMask(markets: readonly number[]): bigint;
|
|
90
|
+
export declare function maskToMarkets(mask: bigint): number[];
|
|
91
|
+
/**
|
|
92
|
+
* Builds and signs ChallengeAccount trade intents (EIP-712). This is the canonical gasless
|
|
93
|
+
* trading path: the owner or a registered session key signs the intent locally and the
|
|
94
|
+
* challenge-service relayer submits it via openPositionBySig/closePositionBySig
|
|
95
|
+
* (see ChallengeApiClient.submitOpenIntent / submitCloseIntent).
|
|
96
|
+
*/
|
|
97
|
+
export declare class ChallengeIntentsModule {
|
|
98
|
+
private publicClient;
|
|
99
|
+
private walletClient;
|
|
100
|
+
private chain;
|
|
101
|
+
constructor(publicClient: PublicClient, walletClient: WalletClient | undefined, chain: Chain);
|
|
102
|
+
private requireWallet;
|
|
103
|
+
/** Next intent nonce of an account (monotonic; consumed by every bySig call). */
|
|
104
|
+
getNonce(account: Address): Promise<bigint>;
|
|
105
|
+
/**
|
|
106
|
+
* Sign an open intent. `owner` must be the account owner; it defaults to the signer,
|
|
107
|
+
* which is only correct when the owner (not a session key) signs. Session keys must
|
|
108
|
+
* pass the owner explicitly. `nonce` is fetched from the account when omitted.
|
|
109
|
+
*/
|
|
110
|
+
signOpenIntent(p: {
|
|
111
|
+
account: Address;
|
|
112
|
+
market: number;
|
|
113
|
+
isLong: boolean;
|
|
114
|
+
margin: bigint;
|
|
115
|
+
notional: bigint;
|
|
116
|
+
maxPrice: bigint;
|
|
117
|
+
minPrice: bigint;
|
|
118
|
+
owner?: Address;
|
|
119
|
+
nonce?: bigint;
|
|
120
|
+
deadlineSeconds?: number;
|
|
121
|
+
}): Promise<SignedOpenIntent>;
|
|
122
|
+
/** Sign a close intent. Same owner/nonce semantics as signOpenIntent. */
|
|
123
|
+
signCloseIntent(p: {
|
|
124
|
+
account: Address;
|
|
125
|
+
positionId: bigint;
|
|
126
|
+
maxPrice: bigint;
|
|
127
|
+
minPrice: bigint;
|
|
128
|
+
owner?: Address;
|
|
129
|
+
nonce?: bigint;
|
|
130
|
+
deadlineSeconds?: number;
|
|
131
|
+
}): Promise<SignedCloseIntent>;
|
|
132
|
+
/** Recover the signer of a signed open intent (owner or session key). */
|
|
133
|
+
recoverOpenIntentSigner(signed: SignedOpenIntent): Promise<Address>;
|
|
134
|
+
/** Recover the signer of a signed close intent (owner or session key). */
|
|
135
|
+
recoverCloseIntentSigner(signed: SignedCloseIntent): Promise<Address>;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=intents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents.d.ts","sourceRoot":"","sources":["../../src/challenge/intents.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,eAAe,EAC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