@pickhooks/sdk 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +418 -3
- package/dist/abis/agents.d.ts +2418 -0
- package/dist/abis/agents.js +4 -0
- package/dist/abis/any3.d.ts +2123 -0
- package/dist/abis/any3.js +3 -0
- package/dist/abis/anytax.d.ts +1786 -0
- package/dist/abis/anytax.js +3 -0
- package/dist/abis/calls.d.ts +2515 -0
- package/dist/abis/calls.js +4 -0
- package/dist/abis/common.d.ts +449 -0
- package/dist/abis/common.js +91 -0
- package/dist/abis/dips.d.ts +897 -0
- package/dist/abis/dips.js +2 -0
- package/dist/abis/index.d.ts +14 -0
- package/dist/abis/index.js +14 -0
- package/dist/abis/infra.d.ts +701 -0
- package/dist/abis/infra.js +4 -0
- package/dist/abis/lever.d.ts +1710 -0
- package/dist/abis/lever.js +5 -0
- package/dist/abis/lever2.d.ts +2710 -0
- package/dist/abis/lever2.js +5 -0
- package/dist/abis/pools.d.ts +1898 -0
- package/dist/abis/pools.js +4 -0
- package/dist/abis/sticky.d.ts +953 -0
- package/dist/abis/sticky.js +4 -0
- package/dist/abis/sticky2.d.ts +3750 -0
- package/dist/abis/sticky2.js +8 -0
- package/dist/abis/v1.d.ts +1627 -0
- package/dist/abis/v1.js +5 -0
- package/dist/abis/v2.d.ts +3264 -0
- package/dist/abis/v2.js +8 -0
- package/dist/addresses.d.ts +100 -0
- package/dist/addresses.js +71 -0
- package/dist/agents-catalog.d.ts +318 -0
- package/dist/agents-catalog.js +353 -0
- package/dist/agents.d.ts +543 -0
- package/dist/agents.js +667 -0
- package/dist/any.d.ts +447 -0
- package/dist/any.js +729 -0
- package/dist/api.d.ts +62 -0
- package/dist/api.js +30 -0
- package/dist/blocks.d.ts +107 -0
- package/dist/blocks.js +126 -0
- package/dist/coin-rules-config.d.ts +8 -0
- package/dist/coin-rules-config.js +13 -0
- package/dist/coin-rules.d.ts +383 -0
- package/dist/coin-rules.js +878 -0
- package/dist/coins.d.ts +217 -0
- package/dist/coins.js +520 -0
- package/dist/desks.d.ts +298 -0
- package/dist/desks.js +343 -0
- package/dist/dips.d.ts +133 -0
- package/dist/dips.js +148 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.js +414 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +91 -0
- package/dist/infinity.d.ts +63 -0
- package/dist/infinity.js +96 -0
- package/dist/infra.d.ts +112 -0
- package/dist/infra.js +114 -0
- package/dist/lever.d.ts +391 -0
- package/dist/lever.js +419 -0
- package/dist/pools.d.ts +274 -0
- package/dist/pools.js +405 -0
- package/dist/sticky-rules.d.ts +179 -0
- package/dist/sticky-rules.js +580 -0
- package/dist/sticky-sim.d.ts +125 -0
- package/dist/sticky-sim.js +637 -0
- package/dist/sticky.d.ts +286 -0
- package/dist/sticky.js +420 -0
- package/dist/tlock.d.ts +67 -0
- package/dist/tlock.js +185 -0
- package/dist/tx.d.ts +72 -0
- package/dist/tx.js +78 -0
- package/dist/v2.d.ts +106 -0
- package/dist/v2.js +61 -0
- package/dist/v3.d.ts +42 -0
- package/dist/v3.js +98 -0
- package/dist/wallet.d.ts +80 -0
- package/dist/wallet.js +115 -0
- package/dist/watch.d.ts +82 -0
- package/dist/watch.js +194 -0
- package/package.json +67 -4
package/dist/dips.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Ctx, type SendOptions, type Sent, type TxRequest } from "./tx.js";
|
|
3
|
+
/**
|
|
4
|
+
* Dip bids (desk 0xc73b…65bf, one desk for every coin, no oracle, no pool touched): a dip buyer locks BNB at their price
|
|
5
|
+
* (the strike) and names a premium; a holder pays that premium for a floor, the right to hand coins in at the strike
|
|
6
|
+
* until it runs out. Pump: the holder keeps the coins. Dump: the coins go to the dip buyer, the holder takes the BNB.
|
|
7
|
+
* Prices: a strike is BNB wei per whole coin (1e18 units).
|
|
8
|
+
*/
|
|
9
|
+
export type DipBid = {
|
|
10
|
+
id: bigint;
|
|
11
|
+
maker: Address;
|
|
12
|
+
token: Address;
|
|
13
|
+
/** BNB wei per whole coin */
|
|
14
|
+
strike: bigint;
|
|
15
|
+
/** how long a floor bought on it runs, seconds */
|
|
16
|
+
duration: number;
|
|
17
|
+
premiumBps: number;
|
|
18
|
+
/** the bid takes new floors until then */
|
|
19
|
+
until: number;
|
|
20
|
+
closed: boolean;
|
|
21
|
+
/** the smallest floor's cover, BNB wei */
|
|
22
|
+
minCover: bigint;
|
|
23
|
+
/** BNB free for new floors, and BNB locked for floors bought */
|
|
24
|
+
free: bigint;
|
|
25
|
+
locked: bigint;
|
|
26
|
+
/** it takes a new floor now */
|
|
27
|
+
live: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type DipFloor = {
|
|
30
|
+
id: bigint;
|
|
31
|
+
bid: bigint;
|
|
32
|
+
owner: Address;
|
|
33
|
+
coins: bigint;
|
|
34
|
+
cover: bigint;
|
|
35
|
+
premium: bigint;
|
|
36
|
+
bought: number;
|
|
37
|
+
expiry: number;
|
|
38
|
+
feeBps: number;
|
|
39
|
+
};
|
|
40
|
+
export type DipPost = {
|
|
41
|
+
token: Address;
|
|
42
|
+
/** BNB per coin (a number), or `strike` in BNB wei per whole coin */
|
|
43
|
+
price?: number;
|
|
44
|
+
strike?: bigint;
|
|
45
|
+
/** seconds a floor runs: 10 minutes to 7 days */
|
|
46
|
+
duration: number;
|
|
47
|
+
/** what a floor costs, basis points of what it covers (up to 50 %) */
|
|
48
|
+
premiumBps: number;
|
|
49
|
+
/** unix time the bid stops taking floors */
|
|
50
|
+
until: number;
|
|
51
|
+
/** the smallest floor, BNB wei of cover (at least the desk's MIN_COVER) */
|
|
52
|
+
minCover: bigint;
|
|
53
|
+
/** BNB the bid locks (at least the desk's MIN_DEPOSIT and its smallest floor) */
|
|
54
|
+
deposit: bigint;
|
|
55
|
+
};
|
|
56
|
+
/** strike = BNB wei per whole coin, from a price in BNB per coin */
|
|
57
|
+
export declare function strikeFromPrice(priceBnb: number): bigint;
|
|
58
|
+
/** BNB wei a floor of `coins` units covers at `strike` (as the desk rounds: down) */
|
|
59
|
+
export declare const coverOf: (coins: bigint, strike: bigint) => bigint;
|
|
60
|
+
/** coin units whose cover is `coverWei` at `strike` (rounded down) */
|
|
61
|
+
export declare const coinsFor: (coverWei: bigint, strike: bigint) => bigint;
|
|
62
|
+
export declare function dipsModule(ctx: Ctx): {
|
|
63
|
+
desk: `0x${string}`;
|
|
64
|
+
terms: () => Promise<{
|
|
65
|
+
premiumFeeBps: number;
|
|
66
|
+
exerciseFeeBps: number;
|
|
67
|
+
minDeposit: bigint;
|
|
68
|
+
minCover: bigint;
|
|
69
|
+
minDuration: number;
|
|
70
|
+
maxDuration: number;
|
|
71
|
+
maxPremiumBps: number;
|
|
72
|
+
}>;
|
|
73
|
+
bids: (token: Address, o?: {
|
|
74
|
+
limit?: number;
|
|
75
|
+
}) => Promise<DipBid[]>;
|
|
76
|
+
bid: (id: bigint) => Promise<DipBid>;
|
|
77
|
+
floorsOf: (holder: Address) => Promise<DipFloor[]>;
|
|
78
|
+
quote: (bidId: bigint, coins: bigint) => Promise<{
|
|
79
|
+
cover: bigint;
|
|
80
|
+
premium: bigint;
|
|
81
|
+
fee: bigint;
|
|
82
|
+
payout: bigint;
|
|
83
|
+
}>;
|
|
84
|
+
dryExercise: (floorId: bigint, coins: bigint, owner: Address) => Promise<{
|
|
85
|
+
ok: true;
|
|
86
|
+
out: bigint;
|
|
87
|
+
} | {
|
|
88
|
+
ok: false;
|
|
89
|
+
why: string;
|
|
90
|
+
}>;
|
|
91
|
+
pending: (who: Address) => Promise<bigint>;
|
|
92
|
+
strikeFromPrice: typeof strikeFromPrice;
|
|
93
|
+
coverOf: (coins: bigint, strike: bigint) => bigint;
|
|
94
|
+
coinsFor: (coverWei: bigint, strike: bigint) => bigint;
|
|
95
|
+
build: {
|
|
96
|
+
post: (p: DipPost) => TxRequest;
|
|
97
|
+
fund: (id: bigint, wei: bigint) => TxRequest;
|
|
98
|
+
withdraw: (id: bigint, wei: bigint) => TxRequest;
|
|
99
|
+
close: (id: bigint) => TxRequest;
|
|
100
|
+
/** value = the quoted premium */
|
|
101
|
+
buyFloor: (bidId: bigint, coins: bigint, premium: bigint) => TxRequest;
|
|
102
|
+
/** needs the coin approved to the desk */
|
|
103
|
+
exercise: (floorId: bigint, coins: bigint, minBnb: bigint) => TxRequest;
|
|
104
|
+
end: (floorId: bigint) => TxRequest;
|
|
105
|
+
give: (floorId: bigint, to: Address) => TxRequest;
|
|
106
|
+
withdrawPending: () => TxRequest;
|
|
107
|
+
};
|
|
108
|
+
/** posts a bid with its deposit; returns the bid id */
|
|
109
|
+
post: (p: DipPost, s?: SendOptions) => Promise<Sent & {
|
|
110
|
+
id: bigint;
|
|
111
|
+
}>;
|
|
112
|
+
fund: (id: bigint, wei: bigint, s?: SendOptions) => Promise<Sent>;
|
|
113
|
+
withdraw: (id: bigint, wei: bigint, s?: SendOptions) => Promise<Sent>;
|
|
114
|
+
close: (id: bigint, s?: SendOptions) => Promise<Sent>;
|
|
115
|
+
/** pays exactly the quoted premium; returns the floor id */
|
|
116
|
+
buyFloor: (bidId: bigint, coins: bigint, s?: SendOptions) => Promise<Sent & {
|
|
117
|
+
id: bigint;
|
|
118
|
+
premium: bigint;
|
|
119
|
+
}>;
|
|
120
|
+
/** approves the coin to the desk if needed, then hands `coins` in for at least the dry run's payout less slippageBps */
|
|
121
|
+
exercise: (o: {
|
|
122
|
+
floorId: bigint;
|
|
123
|
+
coins: bigint;
|
|
124
|
+
token: Address;
|
|
125
|
+
slippageBps?: number;
|
|
126
|
+
}, s?: SendOptions) => Promise<Sent & {
|
|
127
|
+
paid: bigint;
|
|
128
|
+
}>;
|
|
129
|
+
end: (floorId: bigint, s?: SendOptions) => Promise<Sent>;
|
|
130
|
+
give: (floorId: bigint, to: Address, s?: SendOptions) => Promise<Sent>;
|
|
131
|
+
withdrawPending: (s?: SendOptions) => Promise<Sent>;
|
|
132
|
+
};
|
|
133
|
+
export type DipsModule = ReturnType<typeof dipsModule>;
|
package/dist/dips.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { encodeFunctionData, parseEventLogs } from "viem";
|
|
2
|
+
import { dipDeskAbi } from "./abis/dips.js";
|
|
3
|
+
import { PickhooksError, toPickhooksError } from "./errors.js";
|
|
4
|
+
import { minusBps, sendTx, signer } from "./tx.js";
|
|
5
|
+
import { approvalFor } from "./v3.js";
|
|
6
|
+
/** strike = BNB wei per whole coin, from a price in BNB per coin */
|
|
7
|
+
export function strikeFromPrice(priceBnb) {
|
|
8
|
+
if (!(priceBnb > 0) || !Number.isFinite(priceBnb))
|
|
9
|
+
return 0n;
|
|
10
|
+
return BigInt(Math.max(1, Math.round(priceBnb * 1e18)));
|
|
11
|
+
}
|
|
12
|
+
/** BNB wei a floor of `coins` units covers at `strike` (as the desk rounds: down) */
|
|
13
|
+
export const coverOf = (coins, strike) => (coins * strike) / 10n ** 18n;
|
|
14
|
+
/** coin units whose cover is `coverWei` at `strike` (rounded down) */
|
|
15
|
+
export const coinsFor = (coverWei, strike) => (strike > 0n ? (coverWei * 10n ** 18n) / strike : 0n);
|
|
16
|
+
export function dipsModule(ctx) {
|
|
17
|
+
const { pub, a } = ctx;
|
|
18
|
+
const D = dipDeskAbi;
|
|
19
|
+
const desk = a.dipsDesk;
|
|
20
|
+
const call = (functionName, args = []) => pub.readContract({ address: desk, abi: D, functionName, args });
|
|
21
|
+
const now = async () => Number((await pub.getBlock({ blockTag: "latest" })).timestamp);
|
|
22
|
+
const toBid = (id, b, t) => ({
|
|
23
|
+
id,
|
|
24
|
+
maker: b.maker,
|
|
25
|
+
token: b.token,
|
|
26
|
+
strike: b.strike,
|
|
27
|
+
duration: Number(b.duration),
|
|
28
|
+
premiumBps: Number(b.premiumBps),
|
|
29
|
+
until: Number(b.until),
|
|
30
|
+
closed: b.closed,
|
|
31
|
+
minCover: b.minCover,
|
|
32
|
+
free: b.free,
|
|
33
|
+
locked: b.locked,
|
|
34
|
+
live: !b.closed && Number(b.until) > t && b.free >= b.minCover,
|
|
35
|
+
});
|
|
36
|
+
/** The desk's fees and limits. */
|
|
37
|
+
async function terms() {
|
|
38
|
+
const fns = ["premiumFeeBps", "exerciseFeeBps", "MIN_DEPOSIT", "MIN_COVER", "MIN_DURATION", "MAX_DURATION", "MAX_PREMIUM_BPS"];
|
|
39
|
+
const r = await pub.multicall({ contracts: fns.map((functionName) => ({ address: desk, abi: D, functionName })), allowFailure: false });
|
|
40
|
+
return { premiumFeeBps: Number(r[0]), exerciseFeeBps: Number(r[1]), minDeposit: r[2], minCover: r[3], minDuration: Number(r[4]), maxDuration: Number(r[5]), maxPremiumBps: Number(r[6]) };
|
|
41
|
+
}
|
|
42
|
+
/** The newest bids on a coin (up to `limit`), with whether each takes a floor now. */
|
|
43
|
+
async function bids(token, o = {}) {
|
|
44
|
+
const [r, t] = await Promise.all([call("bidsOf", [token, BigInt(o.limit ?? 200)]), now()]);
|
|
45
|
+
return r[0].map((id, i) => toBid(id, r[1][i], t));
|
|
46
|
+
}
|
|
47
|
+
async function bid(id) {
|
|
48
|
+
const [b, t] = await Promise.all([call("bidOf", [id]), now()]);
|
|
49
|
+
if (/^0x0{40}$/i.test(b.maker))
|
|
50
|
+
throw new PickhooksError("There is no bid with this id.", { code: "NoBid" });
|
|
51
|
+
return toBid(id, b, t);
|
|
52
|
+
}
|
|
53
|
+
/** A holder's floors (still holding coins), newest last. */
|
|
54
|
+
async function floorsOf(holder) {
|
|
55
|
+
const [ids] = await call("floorIdsOf", [holder, 0n, 1000n]);
|
|
56
|
+
if (!ids.length)
|
|
57
|
+
return [];
|
|
58
|
+
const r = await pub.multicall({ contracts: ids.map((id) => ({ address: desk, abi: D, functionName: "floorOf", args: [id] })), allowFailure: true });
|
|
59
|
+
const out = [];
|
|
60
|
+
r.forEach((x, i) => {
|
|
61
|
+
if (x.status !== "success")
|
|
62
|
+
return;
|
|
63
|
+
const f = x.result;
|
|
64
|
+
if (f.coins === 0n || f.owner.toLowerCase() !== holder.toLowerCase())
|
|
65
|
+
return;
|
|
66
|
+
out.push({ id: ids[i], bid: f.bid, owner: f.owner, coins: f.coins, cover: f.cover, premium: f.premium, bought: Number(f.bought), expiry: Number(f.expiry), feeBps: Number(f.feeBps) });
|
|
67
|
+
});
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/** What a floor of `coins` on a bid covers, costs (premium, the desk's fee in it) and pays the maker. */
|
|
71
|
+
async function quote(bidId, coins) {
|
|
72
|
+
try {
|
|
73
|
+
const [cover, premium, fee, payout] = await call("quote", [bidId, coins]);
|
|
74
|
+
return { cover, premium, fee, payout };
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
throw toPickhooksError(e, "The desk refused this floor.");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** What handing in `coins` of a floor would pay `owner` now (the coins must be there and approved), or the refusal. */
|
|
81
|
+
async function dryExercise(floorId, coins, owner) {
|
|
82
|
+
try {
|
|
83
|
+
const r = await pub.simulateContract({ address: desk, abi: D, functionName: "exercise", args: [floorId, coins, 0n], account: owner });
|
|
84
|
+
return { ok: true, out: r.result };
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return { ok: false, why: toPickhooksError(e, "The coin refused the hand in.").message };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const tx = (fn, args = [], value = 0n, label) => ({ to: desk, value, data: encodeFunctionData({ abi: D, functionName: fn, args }), label });
|
|
91
|
+
const build = {
|
|
92
|
+
post: (p) => tx("post", [p.token, p.strike ?? strikeFromPrice(p.price ?? 0), p.duration, p.premiumBps, p.until, p.minCover], p.deposit, "Posting the bid"),
|
|
93
|
+
fund: (id, wei) => tx("fund", [id], wei, "Funding the bid"),
|
|
94
|
+
withdraw: (id, wei) => tx("withdraw", [id, wei], 0n, "Taking free BNB back"),
|
|
95
|
+
close: (id) => tx("close", [id], 0n, "Closing the bid"),
|
|
96
|
+
/** value = the quoted premium */
|
|
97
|
+
buyFloor: (bidId, coins, premium) => tx("buy", [bidId, coins], premium, "Buying the floor"),
|
|
98
|
+
/** needs the coin approved to the desk */
|
|
99
|
+
exercise: (floorId, coins, minBnb) => tx("exercise", [floorId, coins, minBnb], 0n, "Handing coins in"),
|
|
100
|
+
end: (floorId) => tx("end", [floorId], 0n, "Ending the floor"),
|
|
101
|
+
give: (floorId, to) => tx("give", [floorId, to], 0n, "Giving the floor away"),
|
|
102
|
+
withdrawPending: () => tx("withdrawPending", [], 0n, "Taking pending BNB"),
|
|
103
|
+
};
|
|
104
|
+
const idFrom = (sent, eventName) => parseEventLogs({ abi: D, logs: sent.receipt.logs.filter((l) => l.address.toLowerCase() === desk.toLowerCase()) }).find((e) => e.eventName === eventName)?.args.id ?? 0n;
|
|
105
|
+
return {
|
|
106
|
+
desk,
|
|
107
|
+
terms,
|
|
108
|
+
bids,
|
|
109
|
+
bid,
|
|
110
|
+
floorsOf,
|
|
111
|
+
quote,
|
|
112
|
+
dryExercise,
|
|
113
|
+
pending: (who) => call("pending", [who]),
|
|
114
|
+
strikeFromPrice,
|
|
115
|
+
coverOf,
|
|
116
|
+
coinsFor,
|
|
117
|
+
build,
|
|
118
|
+
/** posts a bid with its deposit; returns the bid id */
|
|
119
|
+
post: async (p, s = {}) => {
|
|
120
|
+
const sent = await sendTx(ctx, build.post(p), s);
|
|
121
|
+
return { ...sent, id: idFrom(sent, "BidPosted") };
|
|
122
|
+
},
|
|
123
|
+
fund: (id, wei, s = {}) => sendTx(ctx, build.fund(id, wei), s),
|
|
124
|
+
withdraw: (id, wei, s = {}) => sendTx(ctx, build.withdraw(id, wei), s),
|
|
125
|
+
close: (id, s = {}) => sendTx(ctx, build.close(id), s),
|
|
126
|
+
/** pays exactly the quoted premium; returns the floor id */
|
|
127
|
+
buyFloor: async (bidId, coins, s = {}) => {
|
|
128
|
+
const q = await quote(bidId, coins);
|
|
129
|
+
const sent = await sendTx(ctx, build.buyFloor(bidId, coins, q.premium), s);
|
|
130
|
+
return { ...sent, id: idFrom(sent, "FloorBought"), premium: q.premium };
|
|
131
|
+
},
|
|
132
|
+
/** approves the coin to the desk if needed, then hands `coins` in for at least the dry run's payout less slippageBps */
|
|
133
|
+
exercise: async (o, s = {}) => {
|
|
134
|
+
const { address } = await signer(ctx, s.wallet);
|
|
135
|
+
const ap = await approvalFor(ctx, address, o.token, o.coins, desk, "Allowing the desk");
|
|
136
|
+
if (ap)
|
|
137
|
+
await sendTx(ctx, ap, s);
|
|
138
|
+
const dry = await dryExercise(o.floorId, o.coins, address);
|
|
139
|
+
if (!dry.ok)
|
|
140
|
+
throw new PickhooksError(dry.why, { code: "dips" });
|
|
141
|
+
const sent = await sendTx(ctx, build.exercise(o.floorId, o.coins, minusBps(dry.out, o.slippageBps ?? 100)), s);
|
|
142
|
+
return { ...sent, paid: dry.out };
|
|
143
|
+
},
|
|
144
|
+
end: (floorId, s = {}) => sendTx(ctx, build.end(floorId), s),
|
|
145
|
+
give: (floorId, to, s = {}) => sendTx(ctx, build.give(floorId, to), s),
|
|
146
|
+
withdrawPending: (s = {}) => sendTx(ctx, build.withdrawPending(), s),
|
|
147
|
+
};
|
|
148
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
/** What hook any coin's factory.check() answers, in words. */
|
|
3
|
+
export declare const CHECK_TEXT: Record<number, string>;
|
|
4
|
+
/** An error of the SDK: `code` is the contract's error name (or "wallet", "reverted", "input"), `text` a sentence. */
|
|
5
|
+
export declare class PickhooksError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly args?: readonly unknown[];
|
|
8
|
+
readonly hash?: Hex;
|
|
9
|
+
constructor(text: string, opts: {
|
|
10
|
+
code: string;
|
|
11
|
+
args?: readonly unknown[];
|
|
12
|
+
hash?: Hex;
|
|
13
|
+
cause?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** The revert data inside a viem error (it nests them), or null. */
|
|
17
|
+
export declare function findRevertData(err: unknown): Hex | null;
|
|
18
|
+
/** A decoded contract error, searched at the start of the revert data and, for wrapped errors, anywhere inside it. */
|
|
19
|
+
export declare function decodeRevert(data: Hex): {
|
|
20
|
+
name: string;
|
|
21
|
+
args: readonly unknown[];
|
|
22
|
+
} | null;
|
|
23
|
+
/** A contract error as a sentence. */
|
|
24
|
+
export declare function errorText(name: string, args: readonly unknown[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* Any error as a code and a sentence: a wallet refusal, a pickhooks contract's error (wrapped by PancakeSwap or not), one
|
|
27
|
+
* of PancakeSwap's trade errors, or the fallback.
|
|
28
|
+
*/
|
|
29
|
+
export declare function explain(err: unknown, fallback?: string): {
|
|
30
|
+
code: string;
|
|
31
|
+
text: string;
|
|
32
|
+
args?: readonly unknown[];
|
|
33
|
+
};
|
|
34
|
+
/** Wraps any error as a PickhooksError (keeps the original as `cause`). */
|
|
35
|
+
export declare function toPickhooksError(err: unknown, fallback?: string, hash?: Hex): PickhooksError;
|