@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,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin typed client for the challenge-service public HTTP API. Optional — activated by
|
|
3
|
+
* `challengeApiUrl` in SDKConfig. It only maps SDK types onto the service wire formats;
|
|
4
|
+
* pricing, admission, and submission policy live server-side.
|
|
5
|
+
*
|
|
6
|
+
* Endpoints: POST /quote (quote-signer), POST /intents/open, POST /intents/close (relayer),
|
|
7
|
+
* POST /purchase (gasless buyChallenge via a signed ForwardRequest).
|
|
8
|
+
*/
|
|
9
|
+
export class ChallengeApiClient {
|
|
10
|
+
fetchFn;
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(baseUrl, fetchFn) {
|
|
13
|
+
this.fetchFn = fetchFn;
|
|
14
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
15
|
+
}
|
|
16
|
+
async postRaw(path, body) {
|
|
17
|
+
const fetchFn = this.fetchFn ?? globalThis.fetch;
|
|
18
|
+
if (!fetchFn)
|
|
19
|
+
throw new Error("fetch is not available; pass fetchFn in SDKConfig");
|
|
20
|
+
const res = await fetchFn(`${this.baseUrl}${path}`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
body: JSON.stringify(body),
|
|
24
|
+
});
|
|
25
|
+
const json = (await res.json().catch(() => ({})));
|
|
26
|
+
return { ok: res.ok, status: res.status, json };
|
|
27
|
+
}
|
|
28
|
+
static wireError(path, status, json) {
|
|
29
|
+
const error = typeof json.error === "string" ? json.error : `HTTP ${status}`;
|
|
30
|
+
const detail = typeof json.detail === "string" ? `: ${json.detail}` : "";
|
|
31
|
+
return new Error(`challenge-service ${path} failed (${status}) ${error}${detail}`);
|
|
32
|
+
}
|
|
33
|
+
async post(path, body) {
|
|
34
|
+
const { ok, status, json } = await this.postRaw(path, body);
|
|
35
|
+
if (!ok)
|
|
36
|
+
throw ChallengeApiClient.wireError(path, status, json);
|
|
37
|
+
return json;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Submit endpoints reply with meaningful terminal bodies on non-2xx codes too:
|
|
41
|
+
* 409 {"status":"cached"} (dedup replay of an already-submitted intent),
|
|
42
|
+
* 422 {"status":"reverted", tx_hash, phase, ...} (mined but reverted),
|
|
43
|
+
* 503 {"status":"queued"} (broadcast deferred to recovery). Any body carrying a
|
|
44
|
+
* `status` field is a submit outcome, not a transport error — only error-keyed
|
|
45
|
+
* bodies (e.g. 400 validation, 503 dedup_released) throw.
|
|
46
|
+
*/
|
|
47
|
+
async postSubmit(path, body) {
|
|
48
|
+
const { ok, status, json } = await this.postRaw(path, body);
|
|
49
|
+
if (typeof json.status === "string")
|
|
50
|
+
return ChallengeApiClient.parseSubmitResponse(json);
|
|
51
|
+
if (!ok)
|
|
52
|
+
throw ChallengeApiClient.wireError(path, status, json);
|
|
53
|
+
return ChallengeApiClient.parseSubmitResponse(json);
|
|
54
|
+
}
|
|
55
|
+
// u64 wire fields are JSON numbers; guard the bigint → number conversion.
|
|
56
|
+
static toJsonNumber(value, field) {
|
|
57
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < 0n) {
|
|
58
|
+
throw new Error(`${field} does not fit a JSON number: ${value}`);
|
|
59
|
+
}
|
|
60
|
+
return Number(value);
|
|
61
|
+
}
|
|
62
|
+
static parseSubmitResponse(raw) {
|
|
63
|
+
return {
|
|
64
|
+
status: raw.status,
|
|
65
|
+
txId: typeof raw.tx_id === "string" ? raw.tx_id : undefined,
|
|
66
|
+
txHash: typeof raw.tx_hash === "string" ? raw.tx_hash : undefined,
|
|
67
|
+
phase: typeof raw.phase === "number" ? raw.phase : undefined,
|
|
68
|
+
challengeFailed: typeof raw.challenge_failed === "boolean" ? raw.challenge_failed : undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Request a builder-signed quote from the quote-signer. Verify the returned signature
|
|
73
|
+
* and fee (ChallengeFactoryModule.verifyQuote / previewQuote) before paying.
|
|
74
|
+
*/
|
|
75
|
+
async requestQuote(req) {
|
|
76
|
+
const raw = await this.post("/quote", {
|
|
77
|
+
account_owner: req.accountOwner,
|
|
78
|
+
...(req.payer ? { payer: req.payer } : {}),
|
|
79
|
+
allocation: req.allocation.toString(),
|
|
80
|
+
drawdown_bps: req.drawdownBps,
|
|
81
|
+
daily_drawdown_enabled: req.dailyDrawdownEnabled,
|
|
82
|
+
trading_days_enabled: req.tradingDaysEnabled,
|
|
83
|
+
challenge_type: req.challengeType,
|
|
84
|
+
final_target_profit_bps: req.finalTargetProfitBps,
|
|
85
|
+
price_multiplier_bps: req.priceMultiplierBps,
|
|
86
|
+
});
|
|
87
|
+
const q = raw.quote;
|
|
88
|
+
const quote = {
|
|
89
|
+
accountOwner: q.accountOwner,
|
|
90
|
+
payer: q.payer,
|
|
91
|
+
builder: q.builder,
|
|
92
|
+
referrer: q.referrer,
|
|
93
|
+
allocation: BigInt(q.allocation),
|
|
94
|
+
drawdownBps: Number(q.drawdownBps),
|
|
95
|
+
dailyDrawdownEnabled: q.dailyDrawdownEnabled,
|
|
96
|
+
tradingDaysEnabled: q.tradingDaysEnabled,
|
|
97
|
+
challengeType: Number(q.challengeType),
|
|
98
|
+
finalTargetProfitBps: Number(q.finalTargetProfitBps),
|
|
99
|
+
priceMultiplierBps: Number(q.priceMultiplierBps),
|
|
100
|
+
quotedChallengeFee: BigInt(q.quotedChallengeFee),
|
|
101
|
+
minBuilderVaultAmount: BigInt(q.minBuilderVaultAmount),
|
|
102
|
+
deadline: BigInt(q.deadline),
|
|
103
|
+
nonce: BigInt(q.nonce),
|
|
104
|
+
quoteConfigNonce: BigInt(q.quoteConfigNonce),
|
|
105
|
+
builderQuoteEpoch: BigInt(q.builderQuoteEpoch),
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
quote,
|
|
109
|
+
builderSignature: raw.builderSignature,
|
|
110
|
+
quoteDigest: raw.quoteDigest,
|
|
111
|
+
maxChallengeFee: BigInt(raw.maxChallengeFee),
|
|
112
|
+
fees: {
|
|
113
|
+
challengeFee: BigInt(raw.fees.challengeFee),
|
|
114
|
+
builderAmount: BigInt(raw.fees.builderAmount),
|
|
115
|
+
protocolFee: BigInt(raw.fees.protocolFee),
|
|
116
|
+
referralFee: BigInt(raw.fees.referralFee),
|
|
117
|
+
maxNotional: BigInt(raw.fees.maxNotional),
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Submit a signed open intent to the relayer (gasless; relayer pays gas). */
|
|
122
|
+
async submitOpenIntent(signed) {
|
|
123
|
+
const { intent, signature } = signed;
|
|
124
|
+
return this.postSubmit("/intents/open", {
|
|
125
|
+
owner: intent.owner,
|
|
126
|
+
account: intent.account,
|
|
127
|
+
market: intent.market,
|
|
128
|
+
is_long: intent.isLong,
|
|
129
|
+
margin: intent.margin.toString(),
|
|
130
|
+
notional: intent.notional.toString(),
|
|
131
|
+
max_price: ChallengeApiClient.toJsonNumber(intent.maxPrice, "maxPrice"),
|
|
132
|
+
min_price: ChallengeApiClient.toJsonNumber(intent.minPrice, "minPrice"),
|
|
133
|
+
nonce: intent.nonce.toString(),
|
|
134
|
+
deadline: ChallengeApiClient.toJsonNumber(intent.deadline, "deadline"),
|
|
135
|
+
signature,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** Submit a signed close intent to the relayer (gasless; relayer pays gas). */
|
|
139
|
+
async submitCloseIntent(signed) {
|
|
140
|
+
const { intent, signature } = signed;
|
|
141
|
+
return this.postSubmit("/intents/close", {
|
|
142
|
+
owner: intent.owner,
|
|
143
|
+
account: intent.account,
|
|
144
|
+
position_id: ChallengeApiClient.toJsonNumber(intent.positionId, "positionId"),
|
|
145
|
+
max_price: ChallengeApiClient.toJsonNumber(intent.maxPrice, "maxPrice"),
|
|
146
|
+
min_price: ChallengeApiClient.toJsonNumber(intent.minPrice, "minPrice"),
|
|
147
|
+
nonce: intent.nonce.toString(),
|
|
148
|
+
deadline: ChallengeApiClient.toJsonNumber(intent.deadline, "deadline"),
|
|
149
|
+
signature,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Gasless challenge purchase: a ForwardRequest signed by the payer whose `data` MUST be
|
|
154
|
+
* buyChallengeWithPermit calldata targeting the factory — the service strictly decodes
|
|
155
|
+
* that selector and requires permitValue >= quotedChallengeFee; plain buyChallenge
|
|
156
|
+
* calldata is rejected with a validation error. Build the calldata with
|
|
157
|
+
* ChallengeFactoryModule.encodeBuyChallengeWithPermit, wrap it via
|
|
158
|
+
* ForwarderModule.signRequest({ to: factory, data }), and submit here. The service
|
|
159
|
+
* consumes its own builder quotes only.
|
|
160
|
+
*/
|
|
161
|
+
async purchase(request) {
|
|
162
|
+
return this.postSubmit("/purchase", {
|
|
163
|
+
from: request.from,
|
|
164
|
+
to: request.to,
|
|
165
|
+
value: request.value.toString(),
|
|
166
|
+
gas: request.gas.toString(),
|
|
167
|
+
deadline: request.deadline,
|
|
168
|
+
data: request.data,
|
|
169
|
+
signature: request.signature,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/challenge/api.ts"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IAKnB;IAJO,OAAO,CAAS;IAEjC,YACE,OAAe,EACP,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;QAE9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,IAAa;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI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,CAAC,QAAQ,EAAE,UAAU,CAAC;YACtE,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE;YAClC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC/B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;YAC3B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hash, type Hex, type PublicClient, type WalletClient } from "viem";
|
|
2
|
+
import type { ChallengeFeeBreakdown, ChallengePricingConfig, ChallengeQuote, ChallengeTerms, QuoteVerification } from "./types.js";
|
|
3
|
+
export declare const CHALLENGE_QUOTE_TYPES: {
|
|
4
|
+
readonly ChallengeQuote: readonly [{
|
|
5
|
+
readonly name: "accountOwner";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "payer";
|
|
9
|
+
readonly type: "address";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "builder";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "referrer";
|
|
15
|
+
readonly type: "address";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "allocation";
|
|
18
|
+
readonly type: "uint96";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "drawdownBps";
|
|
21
|
+
readonly type: "uint16";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "dailyDrawdownEnabled";
|
|
24
|
+
readonly type: "bool";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "tradingDaysEnabled";
|
|
27
|
+
readonly type: "bool";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "challengeType";
|
|
30
|
+
readonly type: "uint8";
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "finalTargetProfitBps";
|
|
33
|
+
readonly type: "uint16";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "priceMultiplierBps";
|
|
36
|
+
readonly type: "uint16";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "quotedChallengeFee";
|
|
39
|
+
readonly type: "uint256";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "minBuilderVaultAmount";
|
|
42
|
+
readonly type: "uint256";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "deadline";
|
|
45
|
+
readonly type: "uint64";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "nonce";
|
|
48
|
+
readonly type: "uint256";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "quoteConfigNonce";
|
|
51
|
+
readonly type: "uint256";
|
|
52
|
+
}, {
|
|
53
|
+
readonly name: "builderQuoteEpoch";
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
}];
|
|
56
|
+
};
|
|
57
|
+
type AddressResolver = Address | (() => Promise<Address>);
|
|
58
|
+
/**
|
|
59
|
+
* ChallengeFactory module — signed-quote purchases plus builder quote administration.
|
|
60
|
+
*
|
|
61
|
+
* Quotes are priced and signed by the builder's quote-signer service; the SDK's job is to
|
|
62
|
+
* verify them (verifyQuote / previewQuote) and spend them (buyChallenge). Owner pricing/risk
|
|
63
|
+
* config setters are multisig territory and intentionally not covered.
|
|
64
|
+
*/
|
|
65
|
+
export declare class ChallengeFactoryModule {
|
|
66
|
+
private publicClient;
|
|
67
|
+
private walletClient;
|
|
68
|
+
private chain;
|
|
69
|
+
private addressResolver;
|
|
70
|
+
/** builderRegistry is immutable on the factory — cached after the first delegate check. */
|
|
71
|
+
private builderRegistryCache;
|
|
72
|
+
private resolvedAddress;
|
|
73
|
+
private addressPromise;
|
|
74
|
+
constructor(publicClient: PublicClient, walletClient: WalletClient | undefined, chain: Chain, addressResolver: AddressResolver);
|
|
75
|
+
/**
|
|
76
|
+
* Resolved ChallengeFactory address, lazily fetched when constructed with a resolver
|
|
77
|
+
* function (e.g. from the indexer's ProtocolConfig). The in-flight promise is cached so
|
|
78
|
+
* concurrent callers share one lookup; a failed resolution clears the cache for retry.
|
|
79
|
+
* Once resolved, the address is memoized so the synchronous `address`/`quoteDigest`
|
|
80
|
+
* accessors below work without an extra round trip.
|
|
81
|
+
*/
|
|
82
|
+
getAddress(): Promise<Address>;
|
|
83
|
+
/** Throws if constructed with a resolver and no async method has resolved it yet — see getAddress(). */
|
|
84
|
+
get address(): Address;
|
|
85
|
+
private requireWallet;
|
|
86
|
+
private write;
|
|
87
|
+
/** Factory wiring + quote freshness anchors (quoteConfigNonce invalidates all quotes on config change). */
|
|
88
|
+
getConfig(): Promise<{
|
|
89
|
+
vault: Address;
|
|
90
|
+
oracle: Address;
|
|
91
|
+
implementation: Address;
|
|
92
|
+
builderRegistry: Address;
|
|
93
|
+
owner: Address;
|
|
94
|
+
pendingOwner: Address;
|
|
95
|
+
quoteConfigNonce: bigint;
|
|
96
|
+
maxOpenPositions: number;
|
|
97
|
+
minHoldBlocks: bigint;
|
|
98
|
+
accountsCount: bigint;
|
|
99
|
+
}>;
|
|
100
|
+
getPricingConfig(): Promise<ChallengePricingConfig>;
|
|
101
|
+
/** Immutable terms a challenge account was minted with. */
|
|
102
|
+
getChallengeTerms(account: Address): Promise<ChallengeTerms>;
|
|
103
|
+
/**
|
|
104
|
+
* On-chain fee re-derivation for a quote. This is the authoritative pricing check —
|
|
105
|
+
* do NOT re-implement ChallengePricingLib math off-chain, it drifts on config changes.
|
|
106
|
+
*/
|
|
107
|
+
previewQuote(quote: ChallengeQuote): Promise<ChallengeFeeBreakdown>;
|
|
108
|
+
/** Local EIP-712 digest of a quote (no RPC; matches challengeQuoteDigest on-chain). Requires the address to already be resolved — see getAddress(). */
|
|
109
|
+
quoteDigest(quote: ChallengeQuote): Hex;
|
|
110
|
+
private digestFor;
|
|
111
|
+
/**
|
|
112
|
+
* Verify a builder quote signature before paying for it. Recovers the ECDSA signer locally,
|
|
113
|
+
* accepts the builder EOA directly, and falls back to a MainVault.delegateBuilder registry
|
|
114
|
+
* check over RPC. ERC-1271 contract signatures cannot be recovered off-chain — those return
|
|
115
|
+
* valid=false and must be validated by on-chain simulation instead.
|
|
116
|
+
*/
|
|
117
|
+
verifyQuote(quote: ChallengeQuote, signature: Hex): Promise<QuoteVerification>;
|
|
118
|
+
/** Deterministic clone address for the trader's next challenge with this builder. */
|
|
119
|
+
predictChallengeAccount(trader: Address, builder: Address): Promise<Address>;
|
|
120
|
+
getAccountAt(index: bigint): Promise<Address>;
|
|
121
|
+
/** Current per-builder epoch; bumping it (incrementBuilderQuoteEpoch) voids all prior quotes. */
|
|
122
|
+
getBuilderQuoteEpoch(builder: Address): Promise<bigint>;
|
|
123
|
+
isQuoteNonceUsed(builder: Address, nonce: bigint): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Direct-gas purchase of a builder-signed quote. Requires prior USDC allowance from the
|
|
126
|
+
* payer to the ChallengeVault. `maxChallengeFee` defaults to the quoted fee (no slippage).
|
|
127
|
+
* For gasless UX submit through the challenge-service /purchase route instead.
|
|
128
|
+
*/
|
|
129
|
+
buyChallenge(quote: ChallengeQuote, builderSignature: Hex, maxChallengeFee?: bigint): Promise<Hash>;
|
|
130
|
+
/**
|
|
131
|
+
* Calldata for buyChallengeWithPermit — the ONLY call shape the challenge-service
|
|
132
|
+
* gasless POST /purchase route accepts (it strictly decodes this selector and requires
|
|
133
|
+
* permitValue >= quotedChallengeFee). Wrap it in a ForwardRequest via
|
|
134
|
+
* ForwarderModule.signRequest({ to: factory, data }) and submit with
|
|
135
|
+
* ChallengeApiClient.purchase.
|
|
136
|
+
*/
|
|
137
|
+
static encodeBuyChallengeWithPermit(p: {
|
|
138
|
+
quote: ChallengeQuote;
|
|
139
|
+
builderSignature: Hex;
|
|
140
|
+
maxChallengeFee?: bigint;
|
|
141
|
+
permitValue: bigint;
|
|
142
|
+
permitDeadline: bigint;
|
|
143
|
+
v: number;
|
|
144
|
+
r: Hex;
|
|
145
|
+
s: Hex;
|
|
146
|
+
}): Hex;
|
|
147
|
+
/** Purchase with an ERC-2612 permit (first-time users with no vault allowance). */
|
|
148
|
+
buyChallengeWithPermit(p: {
|
|
149
|
+
quote: ChallengeQuote;
|
|
150
|
+
builderSignature: Hex;
|
|
151
|
+
maxChallengeFee?: bigint;
|
|
152
|
+
permitValue: bigint;
|
|
153
|
+
permitDeadline: bigint;
|
|
154
|
+
v: number;
|
|
155
|
+
r: Hex;
|
|
156
|
+
s: Hex;
|
|
157
|
+
}): Promise<Hash>;
|
|
158
|
+
/** Void one outstanding quote nonce (builder or its delegate). */
|
|
159
|
+
cancelQuoteNonce(nonce: bigint): Promise<Hash>;
|
|
160
|
+
cancelQuoteNonces(nonces: bigint[]): Promise<Hash>;
|
|
161
|
+
/** Void ALL outstanding quotes of the calling builder at once. */
|
|
162
|
+
incrementBuilderQuoteEpoch(): Promise<Hash>;
|
|
163
|
+
}
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/challenge/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,YAAY,EAElB,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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