@intent-engine/cli 0.1.46 → 0.1.48
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/src/agent/create.d.ts +84 -15
- package/dist/src/agent/create.js +107 -104
- package/dist/src/agent/create.js.map +1 -1
- package/dist/src/agent/everyday.js +1 -0
- package/dist/src/agent/everyday.js.map +1 -1
- package/dist/src/agent/job-claims.d.ts +10 -0
- package/dist/src/agent/job-claims.js +31 -0
- package/dist/src/agent/job-claims.js.map +1 -0
- package/dist/src/agent/jobs.js +11 -4
- package/dist/src/agent/jobs.js.map +1 -1
- package/dist/src/agent/mcp.d.ts +2 -0
- package/dist/src/agent/mcp.js +3 -1
- package/dist/src/agent/mcp.js.map +1 -1
- package/dist/src/agent/problems.d.ts +2 -0
- package/dist/src/agent/problems.js +2 -0
- package/dist/src/agent/problems.js.map +1 -1
- package/dist/src/agent/spec.js +5 -1
- package/dist/src/agent/spec.js.map +1 -1
- package/dist/src/agent/wallet/attest.d.ts +5 -0
- package/dist/src/agent/wallet/attest.js +22 -4
- package/dist/src/agent/wallet/attest.js.map +1 -1
- package/dist/src/agent/wallet/committee.js +5 -2
- package/dist/src/agent/wallet/committee.js.map +1 -1
- package/dist/src/agent/wallet/costs.d.ts +30 -0
- package/dist/src/agent/wallet/costs.js +65 -0
- package/dist/src/agent/wallet/costs.js.map +1 -0
- package/dist/src/agent/wallet/delivery.d.ts +3 -0
- package/dist/src/agent/wallet/delivery.js +61 -22
- package/dist/src/agent/wallet/delivery.js.map +1 -1
- package/dist/src/agent/wallet/escrow.d.ts +7 -1
- package/dist/src/agent/wallet/escrow.js +80 -16
- package/dist/src/agent/wallet/escrow.js.map +1 -1
- package/dist/src/agent/wallet/history-work.d.ts +51 -0
- package/dist/src/agent/wallet/history-work.js +166 -0
- package/dist/src/agent/wallet/history-work.js.map +1 -0
- package/dist/src/agent/wallet/history.js +35 -16
- package/dist/src/agent/wallet/history.js.map +1 -1
- package/dist/src/agent/wallet/offer.d.ts +3 -0
- package/dist/src/agent/wallet/offer.js +4 -2
- package/dist/src/agent/wallet/offer.js.map +1 -1
- package/dist/src/agent/wallet/receipt.d.ts +6 -1
- package/dist/src/agent/wallet/receipt.js +95 -15
- package/dist/src/agent/wallet/receipt.js.map +1 -1
- package/dist/src/agent/wallet/releases.d.ts +4 -0
- package/dist/src/agent/wallet/releases.js +11 -0
- package/dist/src/agent/wallet/releases.js.map +1 -1
- package/dist/src/agent/wallet/seal.d.ts +7 -0
- package/dist/src/agent/wallet/seal.js +62 -0
- package/dist/src/agent/wallet/seal.js.map +1 -0
- package/dist/src/agent/wallet/split.js +11 -3
- package/dist/src/agent/wallet/split.js.map +1 -1
- package/dist/src/agent/wallet/wait.d.ts +1 -0
- package/dist/src/agent/wallet/wait.js +22 -2
- package/dist/src/agent/wallet/wait.js.map +1 -1
- package/dist/src/agent/wallet.js +2 -0
- package/dist/src/agent/wallet.js.map +1 -1
- package/dist/src/delivery-fetch.d.ts +5 -0
- package/dist/src/delivery-fetch.js +5 -2
- package/dist/src/delivery-fetch.js.map +1 -1
- package/dist/src/flows.js +2 -2
- package/dist/src/flows.js.map +1 -1
- package/dist/src/job-commands.js +2 -1
- package/dist/src/job-commands.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { decodeEvent, formatAmount, IntentStatus, tokenName } from "@intent-engine/core";
|
|
2
|
+
import { chainTime, deliveriesIn, earlier, intentAt, loadClaimsOf, opensWith, paidWalletsOf, recordedRelease, releaseShareOf, } from "@intent-engine/client";
|
|
3
|
+
import { account, choice, flag, nullable, object, text, time } from "../schema.js";
|
|
4
|
+
import { createdMint, heldMint, releaseLookup, releasedMint } from "./releases.js";
|
|
5
|
+
export const OWN_TRANSACTIONS = 250;
|
|
6
|
+
const ESCROW_EVENTS = 20;
|
|
7
|
+
const STAKE_TO_WORKER = 0;
|
|
8
|
+
const SOL_DECIMALS = 9;
|
|
9
|
+
export const STAKE_OUTCOMES = ["held", "returned", "forfeited", "unknown"];
|
|
10
|
+
export const UNPAID_REASONS = ["released_to_other", "open", "cancelled", "expired", "unknown"];
|
|
11
|
+
const CLAIM_ACTIONS = ["claimed", "dropped"];
|
|
12
|
+
const landedAt = (what) => nullable(time(`unix seconds ${what} landed, when the cluster reports it`));
|
|
13
|
+
export const workItem = object({
|
|
14
|
+
intent: account("the escrow the work was announced to"),
|
|
15
|
+
signature: text("the announcement's transaction"),
|
|
16
|
+
at: landedAt("the announcement"),
|
|
17
|
+
paid: flag("whether a release of the escrow paid this wallet for this announcement"),
|
|
18
|
+
amount: nullable(text("whole tokens the release paid this wallet")),
|
|
19
|
+
token: nullable(text("SOL, TEST or the mint the release paid")),
|
|
20
|
+
release: nullable(text("the release's transaction")),
|
|
21
|
+
unpaid_reason: nullable(choice(UNPAID_REASONS, "null when paid; released_to_other: a release paid released_to, not this wallet; open: the escrow is still open; cancelled or expired: it ended unpaid; unknown: not found")),
|
|
22
|
+
released_to: nullable(account("with released_to_other: the wallet the release paid; for a split, its first recipient")),
|
|
23
|
+
});
|
|
24
|
+
export const claimItem = object({
|
|
25
|
+
intent: account("the escrow whose claim this wallet took or dropped"),
|
|
26
|
+
action: choice(CLAIM_ACTIONS, "claimed: this wallet took the claim; dropped: it gave the claim up"),
|
|
27
|
+
stake: text("whole SOL the claim staked, or that dropping returned"),
|
|
28
|
+
stake_outcome: choice(STAKE_OUTCOMES, "held: the stake still sits on the claim; returned: it went back to this wallet; forfeited: it went to the escrow's owner; unknown: what became of it was not found"),
|
|
29
|
+
signature: text("the transaction that took or dropped the claim"),
|
|
30
|
+
at: landedAt("the claim or drop"),
|
|
31
|
+
});
|
|
32
|
+
const newestFirst = (items) => [...items].sort((a, b) => (a.slot === b.slot ? 0 : a.slot < b.slot ? 1 : -1));
|
|
33
|
+
function eventsIn(transactions) {
|
|
34
|
+
return transactions
|
|
35
|
+
.filter(({ failed }) => !failed)
|
|
36
|
+
.flatMap(({ signature, slot, blockTime, emitted }) => emitted.map((data) => decodeEvent(data)).flatMap((event) => (event === null ? [] : [{ ...event, signature, slot, blockTime }])));
|
|
37
|
+
}
|
|
38
|
+
async function paidFor(transport, delivery, wallet, lookup, tokens) {
|
|
39
|
+
const { release, transactions } = lookup;
|
|
40
|
+
if (release === null || !earlier(delivery, release.tx)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const event = release.event;
|
|
44
|
+
if (event.name !== "IntentAttested" && event.name !== "IntentSplit") {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const recorded = recordedRelease(transactions, release.tx, event.fields.attestor);
|
|
48
|
+
if (recorded?.salt !== undefined && !opensWith(delivery, recorded.salt, recorded.sha256)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const share = await releaseShareOf(transport, { event, transaction: release.tx }, delivery.intent, wallet);
|
|
52
|
+
if (share === null) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const payee = event.name === "IntentAttested" ? event.fields.payee : undefined;
|
|
56
|
+
const mint = releasedMint(release.tx, delivery.intent, payee) ?? createdMint(transactions, delivery.intent) ?? (await heldMint(transport, delivery.intent));
|
|
57
|
+
return {
|
|
58
|
+
amount: mint === undefined ? null : await tokens(mint, share),
|
|
59
|
+
token: mint === undefined ? null : (tokenName(mint) ?? mint),
|
|
60
|
+
release: release.tx.signature,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const ENDED = { IntentCancelled: "cancelled", IntentExpired: "expired" };
|
|
64
|
+
async function unpaidOf(transport, intent, wallet, lookup) {
|
|
65
|
+
const { release, transactions } = lookup;
|
|
66
|
+
if (release !== null) {
|
|
67
|
+
const wallets = await paidWalletsOf(transport, { event: release.event, transaction: release.tx }, intent);
|
|
68
|
+
const [first] = wallets ?? [];
|
|
69
|
+
return wallets === null || first === undefined || wallets.includes(wallet) ? { reason: "unknown", releasedTo: null } : { reason: "released_to_other", releasedTo: first };
|
|
70
|
+
}
|
|
71
|
+
const held = await intentAt(transport, intent);
|
|
72
|
+
if (held !== null && held.status === IntentStatus.Open) {
|
|
73
|
+
return { reason: held.expiresAt > (await chainTime(transport)) ? "open" : "expired", releasedTo: null };
|
|
74
|
+
}
|
|
75
|
+
const ending = eventsIn(transactions).find((event) => event.name in ENDED && event.fields["intent"] === intent);
|
|
76
|
+
return { reason: ending === undefined ? "unknown" : (ENDED[ending.name] ?? "unknown"), releasedTo: null };
|
|
77
|
+
}
|
|
78
|
+
export async function workOf(transport, wallet, transactions, limit, tokens) {
|
|
79
|
+
const announced = newestFirst(deliveriesIn(transactions).filter(({ worker }) => worker === wallet));
|
|
80
|
+
const lookups = new Map();
|
|
81
|
+
const work = [];
|
|
82
|
+
for (const delivery of announced.slice(0, limit)) {
|
|
83
|
+
const { intent } = delivery;
|
|
84
|
+
const lookup = lookups.get(intent) ?? releaseLookup(transport, intent);
|
|
85
|
+
lookups.set(intent, lookup);
|
|
86
|
+
const paid = await paidFor(transport, delivery, wallet, await lookup, tokens);
|
|
87
|
+
const unpaid = paid === null ? await unpaidOf(transport, intent, wallet, await lookup) : { reason: null, releasedTo: null };
|
|
88
|
+
work.push({
|
|
89
|
+
intent,
|
|
90
|
+
signature: delivery.signature,
|
|
91
|
+
at: delivery.blockTime,
|
|
92
|
+
paid: paid !== null,
|
|
93
|
+
amount: paid?.amount ?? null,
|
|
94
|
+
token: paid?.token ?? null,
|
|
95
|
+
release: paid?.release ?? null,
|
|
96
|
+
unpaid_reason: unpaid.reason,
|
|
97
|
+
released_to: unpaid.releasedTo,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return { work, more: announced.length > limit };
|
|
101
|
+
}
|
|
102
|
+
function claimsIn(transactions, wallet) {
|
|
103
|
+
return eventsIn(transactions).flatMap((event) => {
|
|
104
|
+
const { signature, slot, blockTime } = event;
|
|
105
|
+
if (event.name === "JobClaimed" && event.fields.worker === wallet) {
|
|
106
|
+
return [{ intent: event.fields.intent, action: "claimed", stake: event.fields.stake, signature, slot, blockTime }];
|
|
107
|
+
}
|
|
108
|
+
if (event.name === "ClaimDropped" && event.fields.worker === wallet) {
|
|
109
|
+
return [{ intent: event.fields.intent, action: "dropped", stake: event.fields.refunded, signature, slot, blockTime }];
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function stakeEndsIn(transactions, wallet, intent) {
|
|
115
|
+
return eventsIn(transactions).flatMap((event) => {
|
|
116
|
+
const { signature, slot, blockTime } = event;
|
|
117
|
+
if (event.name === "ClaimDropped" && event.fields.worker === wallet && event.fields.intent === intent) {
|
|
118
|
+
return [{ outcome: "returned", signature, slot, blockTime }];
|
|
119
|
+
}
|
|
120
|
+
if (event.name === "StakeMoved" && event.fields.worker === wallet && event.fields.intent === intent) {
|
|
121
|
+
return [{ outcome: event.fields.role === STAKE_TO_WORKER ? "returned" : "forfeited", signature, slot, blockTime }];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const endAfter = (claim, ends) => ends.filter((end) => earlier(claim, end)).reduce((first, end) => (first === undefined || earlier(end, first) ? end : first), undefined);
|
|
127
|
+
async function heldBy(transport, wallet, intents) {
|
|
128
|
+
try {
|
|
129
|
+
const views = await loadClaimsOf(transport, intents);
|
|
130
|
+
return new Set(intents.filter((_, at) => views[at]?.worker === wallet));
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return new Set();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export async function claimsOf(transport, wallet, transactions, limit) {
|
|
137
|
+
const found = newestFirst(claimsIn(transactions, wallet));
|
|
138
|
+
const shown = found.slice(0, limit);
|
|
139
|
+
const histories = new Map();
|
|
140
|
+
const outcomes = [];
|
|
141
|
+
for (const claim of shown) {
|
|
142
|
+
if (claim.action === "dropped") {
|
|
143
|
+
outcomes.push("returned");
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
let end = endAfter(claim, stakeEndsIn(transactions, wallet, claim.intent));
|
|
147
|
+
if (end === undefined) {
|
|
148
|
+
const history = histories.get(claim.intent) ?? (await transport.engineTransactions(ESCROW_EVENTS, claim.intent));
|
|
149
|
+
histories.set(claim.intent, history);
|
|
150
|
+
end = endAfter(claim, stakeEndsIn(history, wallet, claim.intent));
|
|
151
|
+
}
|
|
152
|
+
outcomes.push(end?.outcome ?? "unknown");
|
|
153
|
+
}
|
|
154
|
+
const open = [...new Set(shown.filter((claim, at) => claim.action === "claimed" && outcomes[at] === "unknown").map(({ intent }) => intent))];
|
|
155
|
+
const held = open.length === 0 ? new Set() : await heldBy(transport, wallet, open);
|
|
156
|
+
const claims = shown.map((claim, at) => ({
|
|
157
|
+
intent: claim.intent,
|
|
158
|
+
action: claim.action,
|
|
159
|
+
stake: formatAmount(claim.stake, SOL_DECIMALS),
|
|
160
|
+
stake_outcome: outcomes[at] === "unknown" && held.has(claim.intent) ? "held" : (outcomes[at] ?? "unknown"),
|
|
161
|
+
signature: claim.signature,
|
|
162
|
+
at: claim.blockTime,
|
|
163
|
+
}));
|
|
164
|
+
return { claims, more: found.length > limit };
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=history-work.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-work.js","sourceRoot":"","sources":["../../../../src/agent/wallet/history-work.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAoB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EACL,SAAS,EAET,YAAY,EACZ,OAAO,EAEP,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,EACb,eAAe,EACf,cAAc,GAEf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAA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CAAC,CAAC;IAC7I,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAW,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5F,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC;QAC9C,aAAa,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAgB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC;QACrH,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,EAAE,EAAE,KAAK,CAAC,SAAS;KACpB,CAAC,CAAC,CAAC;IACJ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { findIntentPda, formatAmount, kindName, tokenName } from "@intent-engine/core";
|
|
2
|
-
import { createClient, mintOf } from "@intent-engine/client";
|
|
1
|
+
import { findIntentPda, formatAmount, Kind, kindName, tokenName } from "@intent-engine/core";
|
|
2
|
+
import { createClient, mintOf, ownHistory, paidWalletsOf, transactionAt } from "@intent-engine/client";
|
|
3
3
|
import { define } from "../actions.js";
|
|
4
4
|
import { tool } from "../names.js";
|
|
5
5
|
import { account, amount, choice, flag, integer, list, nullable, object, optional, text, time } from "../schema.js";
|
|
6
6
|
import { signerOf } from "./guard.js";
|
|
7
|
+
import { claimItem, claimsOf, OWN_TRANSACTIONS, workItem, workOf } from "./history-work.js";
|
|
7
8
|
export const HISTORY_DEFAULT = 10;
|
|
8
9
|
export const HISTORY_MAX = 25;
|
|
9
10
|
const EVENTS_PER_INTENT = 20;
|
|
@@ -17,28 +18,39 @@ const ENDINGS = {
|
|
|
17
18
|
IntentCancelled: "cancelled",
|
|
18
19
|
IntentExpired: "expired",
|
|
19
20
|
};
|
|
21
|
+
async function paidWalletOf(transport, ending, intent) {
|
|
22
|
+
const { signature, slot, blockTime } = ending;
|
|
23
|
+
const transaction = (await transactionAt(transport, signature, intent)) ?? { signature, slot, blockTime, failed: false, emitted: [] };
|
|
24
|
+
return (await paidWalletsOf(transport, { event: ending, transaction }, intent))?.[0] ?? null;
|
|
25
|
+
}
|
|
20
26
|
export const walletHistory = define({
|
|
21
27
|
name: tool("wallet_history"),
|
|
22
28
|
title: "Show the wallet's history",
|
|
23
|
-
description: `Shows the user what this wallet did, newest first:
|
|
29
|
+
description: `Shows the user what this wallet did, newest first, read from the chain: orders (intents) it created and how each ended, closed ones included; work it announced with ${tool("wallet_deliver")} whether a release paid it, and why not; claims it took or dropped and the stake's outcome. It leaves out transfers, releases it judged, fills of others' orders, and standby lines.`,
|
|
24
30
|
effect: "read",
|
|
25
|
-
input: object({
|
|
31
|
+
input: object({
|
|
32
|
+
limit: optional(integer(1, HISTORY_MAX, `how many of the newest intents, and of the newest announcements and claims, to show; default ${HISTORY_DEFAULT}`)),
|
|
33
|
+
}),
|
|
26
34
|
output: object({
|
|
27
|
-
wallet: account(),
|
|
35
|
+
wallet: account("this server's wallet, whose history this is"),
|
|
28
36
|
activity: list(object({
|
|
29
|
-
nonce: amount(),
|
|
30
|
-
intent: account(),
|
|
31
|
-
kind: text(),
|
|
32
|
-
outcome: choice(OUTCOMES),
|
|
37
|
+
nonce: amount("the intent's nonce, its number among this wallet's intents"),
|
|
38
|
+
intent: account("the intent's address"),
|
|
39
|
+
kind: text("the kind of intent, such as AttestedResult for an escrow or SwapExactIn for a swap"),
|
|
40
|
+
outcome: choice(OUTCOMES, "how it ended: open, filled, released, cancelled, expired, or unknown when its history was not found"),
|
|
33
41
|
sold: text("whole tokens the intent escrowed"),
|
|
34
42
|
sell_token: text("SOL, TEST or the mint"),
|
|
35
43
|
received: nullable(text("whole tokens delivered by the fill")),
|
|
36
|
-
receive_token: text("SOL, TEST or the mint"),
|
|
37
|
-
paid_to: nullable(account("the wallet a release paid")),
|
|
44
|
+
receive_token: nullable(text("SOL, TEST or the mint a fill delivers; null for a work escrow, which pays a worker and receives nothing")),
|
|
45
|
+
paid_to: nullable(account("the wallet a release paid: the owner of payee")),
|
|
46
|
+
payee: nullable(account("the token account a release paid into, owned by paid_to; for SOL it holds wrapped SOL")),
|
|
38
47
|
signature: nullable(text("the transaction that ended it")),
|
|
39
48
|
at: nullable(time("unix seconds of the last event, when the cluster reports it")),
|
|
40
|
-
}), HISTORY_MAX),
|
|
49
|
+
}), HISTORY_MAX, "the intents this wallet created, newest first"),
|
|
41
50
|
more: flag("true when older intents exist beyond limit"),
|
|
51
|
+
work: list(workItem, HISTORY_MAX, `the work this wallet announced with ${tool("wallet_deliver")}, newest first`),
|
|
52
|
+
claims: list(claimItem, HISTORY_MAX, "the claims this wallet took or dropped, newest first"),
|
|
53
|
+
more_work: flag(`true when older announcements or claims exist beyond limit, or this wallet has transactions older than the newest ${OWN_TRANSACTIONS} read`),
|
|
42
54
|
}),
|
|
43
55
|
run: async (ctx, input) => {
|
|
44
56
|
const wallet = (await signerOf(ctx)).address;
|
|
@@ -63,25 +75,32 @@ export const walletHistory = define({
|
|
|
63
75
|
if (inputMint === undefined || outputMint === undefined) {
|
|
64
76
|
continue;
|
|
65
77
|
}
|
|
78
|
+
const kind = Number(created["kind"]);
|
|
66
79
|
const ending = events.find((e) => e.name in ENDINGS);
|
|
67
80
|
const outcome = ending === undefined ? ((await ctx.transport.getAccount(intent)) === null ? "unknown" : "open") : (ENDINGS[ending.name] ?? "unknown");
|
|
68
81
|
const ended = fields(ending);
|
|
69
82
|
const delivered = outcome === "filled" ? ended["delivered"] : undefined;
|
|
83
|
+
const attested = ending?.name === "IntentAttested" ? ending : undefined;
|
|
70
84
|
activity.push({
|
|
71
85
|
nonce,
|
|
72
86
|
intent,
|
|
73
|
-
kind: kindName(
|
|
87
|
+
kind: kindName(kind) ?? "unknown",
|
|
74
88
|
outcome,
|
|
75
89
|
sold: await tokens(inputMint, created["escrowed"]),
|
|
76
90
|
sell_token: tokenName(inputMint) ?? inputMint,
|
|
77
91
|
received: delivered === undefined ? null : await tokens(outputMint, delivered),
|
|
78
|
-
receive_token: tokenName(outputMint) ?? outputMint,
|
|
79
|
-
paid_to:
|
|
92
|
+
receive_token: kind === Kind.AttestedResult ? null : (tokenName(outputMint) ?? outputMint),
|
|
93
|
+
paid_to: attested === undefined ? null : await paidWalletOf(ctx.transport, attested, intent),
|
|
94
|
+
payee: attested === undefined ? null : attested.fields.payee,
|
|
80
95
|
signature: ending?.signature ?? null,
|
|
81
96
|
at: (ending ?? events[0])?.blockTime ?? null,
|
|
82
97
|
});
|
|
83
98
|
}
|
|
84
|
-
|
|
99
|
+
const own = await ownHistory(ctx.transport, wallet, OWN_TRANSACTIONS);
|
|
100
|
+
const count = Number(limit);
|
|
101
|
+
const { work, more: moreWork } = await workOf(ctx.transport, wallet, own.transactions, count, tokens);
|
|
102
|
+
const { claims, more: moreClaims } = await claimsOf(ctx.transport, wallet, own.transactions, count);
|
|
103
|
+
return { wallet, activity, more: oldest > 0n, work, claims, more_work: moreWork || moreClaims || !own.complete };
|
|
85
104
|
},
|
|
86
105
|
});
|
|
87
106
|
//# sourceMappingURL=history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../../../src/agent/wallet/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file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CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC;gBAC5F,KAAK,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK;gBAC5D,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,IAAI;gBACpC,EAAE,EAAE,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,IAAI,IAAI;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACtG,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACpG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,IAAI,UAAU,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACnH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { Address } from "@solana/kit";
|
|
|
2
2
|
import { mintOf } from "@intent-engine/client";
|
|
3
3
|
import type { AgentContext } from "../actions.js";
|
|
4
4
|
import type { Call } from "../claims.js";
|
|
5
|
+
import { type AfterCreate } from "../create.js";
|
|
5
6
|
import { type Schema } from "../schema.js";
|
|
6
7
|
import { orderSchema } from "../shapes.js";
|
|
7
8
|
export declare const offerFields: {
|
|
@@ -47,6 +48,8 @@ export declare function offered(ctx: AgentContext, call: Call, input: {
|
|
|
47
48
|
buy: string;
|
|
48
49
|
pay_to?: Address | undefined;
|
|
49
50
|
send?: boolean | undefined;
|
|
51
|
+
after?: AfterCreate | undefined;
|
|
52
|
+
priced?: ((network: bigint) => void) | undefined;
|
|
50
53
|
}, terms: (sold: Token, bought: Token, now: bigint, inputMint: Address, outputMint: Address) => Promise<Terms> | Terms, done?: string): Promise<{
|
|
51
54
|
sent: boolean;
|
|
52
55
|
next: string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { chainTime, CLOCK_SYSVAR, explain, mintOf, unmemoized } from "@intent-engine/client";
|
|
3
|
-
import {
|
|
3
|
+
import { createIntent } from "../create.js";
|
|
4
4
|
import { AgentRefusal, problemOf } from "../problems.js";
|
|
5
5
|
import { account, amount, flag, list, object, optional, text } from "../schema.js";
|
|
6
6
|
import { orderSchema } from "../shapes.js";
|
|
7
|
+
import { networkFee } from "./costs.js";
|
|
7
8
|
import { walletEmpty, access, signerOf, mintNamed, limited, bookOf, live, salesOf, checkSale, sent, refusedBeforeSending, deviceOutput } from "./guard.js";
|
|
8
9
|
export const offerFields = {
|
|
9
10
|
intent: account(),
|
|
@@ -35,11 +36,12 @@ export async function offered(ctx, call, input, terms, done) {
|
|
|
35
36
|
const guard = wallet.limits;
|
|
36
37
|
checkSale(guard, inputMint, inputToken.decimals, sold, now, await salesOf(wallet, now));
|
|
37
38
|
const created = async (context) => {
|
|
38
|
-
const view = (await
|
|
39
|
+
const view = (await createIntent(context, { owner: signer.address, input_mint: inputMint, output_mint: outputMint, ...(input.pay_to === undefined ? {} : { pay_to: input.pay_to }), ...made }, call, input.after));
|
|
39
40
|
const { intent, nonce, summary, warnings, prepared } = view;
|
|
40
41
|
return { intent, nonce, summary, warnings, prepared };
|
|
41
42
|
};
|
|
42
43
|
const first = await created(ctx);
|
|
44
|
+
input.priced?.(networkFee(first.prepared));
|
|
43
45
|
if (input.send !== true) {
|
|
44
46
|
return sent(ctx, signer, first, input.send, call, { done });
|
|
45
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../src/agent/wallet/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAG7F,OAAO,
|
|
1
|
+
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../src/agent/wallet/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAG7F,OAAO,EAAoB,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAe,IAAI,EAAE,MAAM,cAAc,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE3J,MAAM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,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -4,9 +4,13 @@ export declare const NOT_RELEASED = "no release of this escrow is in its history
|
|
|
4
4
|
export declare const PAID_WRAPPED: string;
|
|
5
5
|
export declare const RECEIPT_PARTIAL = "the escrow's history after this release could not be read in full: it is longer than the pages read or the RPC node could not return some of its transactions yet, so a follow-up recording the delivered work may be missing, and without release given, the escrow address may have been made again since; pass release, the signature the release returned, or call again in a few seconds";
|
|
6
6
|
export declare const stillUnreleased: (name: string) => string;
|
|
7
|
+
export declare const ALSO_MAX = 9;
|
|
8
|
+
export declare const noneReleased: (name: string, count: number) => string;
|
|
9
|
+
export declare const noneKnown: (name: string, count: number) => string;
|
|
7
10
|
export declare const RELEASE_LANDING = "the escrow is marked released on chain, but the RPC node has not returned the release transaction yet, so who it paid is not known; call again in a few seconds";
|
|
8
11
|
export declare const stillUnknown: (name: string) => string;
|
|
9
|
-
export
|
|
12
|
+
export { NO_CLOCK } from "./wait.js";
|
|
13
|
+
export declare const paidOther: (wallets: readonly Address[], self: Address) => string;
|
|
10
14
|
export declare const walletReceipt: import("../actions.js").AnyAction;
|
|
11
15
|
export declare const getReceipt: import("../actions.js").AnyAction;
|
|
12
16
|
export declare function escrowReceipt(transport: Transport, owner: Address, nonce: bigint, sha256: string | undefined, releaseSignature?: string): Promise<{
|
|
@@ -35,6 +39,7 @@ export declare function escrowReceipt(transport: Transport, owner: Address, nonc
|
|
|
35
39
|
paid: string;
|
|
36
40
|
mint?: Address;
|
|
37
41
|
recipients: bigint;
|
|
42
|
+
paid_wallets?: Address[];
|
|
38
43
|
} | {
|
|
39
44
|
intent: Address<string>;
|
|
40
45
|
released: boolean;
|
|
@@ -1,26 +1,87 @@
|
|
|
1
1
|
import { getAddressDecoder } from "@solana/kit";
|
|
2
|
-
import { findIntentPda, formatAmount, IntentStatus, Kind, NATIVE_MINT } from "@intent-engine/core";
|
|
2
|
+
import { findIntentPda, formatAmount, IntentStatus, Kind, MAX_RECIPIENTS, NATIVE_MINT } from "@intent-engine/core";
|
|
3
3
|
import { intentAt, memoized, mintOf, paidWalletsOf, recordedRelease, releaseStandingOf, unmemoized } from "@intent-engine/client";
|
|
4
4
|
import { define } from "../actions.js";
|
|
5
5
|
import { tool } from "../names.js";
|
|
6
6
|
import { AgentRefusal } from "../problems.js";
|
|
7
|
-
import { account, amount, flag, integer, object, optional, text } from "../schema.js";
|
|
7
|
+
import { account, amount, flag, integer, list, object, optional, text } from "../schema.js";
|
|
8
8
|
import { WAIT_MAX, signerOf, sha256Of } from "./guard.js";
|
|
9
|
-
import { poll } from "./wait.js";
|
|
9
|
+
import { NO_CLOCK, poll } from "./wait.js";
|
|
10
10
|
import { RESULT_MEANS } from "./attest.js";
|
|
11
11
|
import { RELEASE_INPUT, releaseOf, otherLifecycle, coverageOf } from "./record.js";
|
|
12
12
|
import { RELEASE_UNKNOWN, outlives, releaseLookup, namedRelease, releasedMint, createdMint, heldMint } from "./releases.js";
|
|
13
13
|
export const NOT_RELEASED = "no release of this escrow is in its history yet; check again later";
|
|
14
14
|
export const PAID_WRAPPED = `paid as wrapped SOL; ${tool("wallet_unwrap")} turns it into plain SOL`;
|
|
15
15
|
export const RECEIPT_PARTIAL = "the escrow's history after this release could not be read in full: it is longer than the pages read or the RPC node could not return some of its transactions yet, so a follow-up recording the delivered work may be missing, and without release given, the escrow address may have been made again since; pass release, the signature the release returned, or call again in a few seconds";
|
|
16
|
-
export const stillUnreleased = (name) => `not released
|
|
16
|
+
export const stillUnreleased = (name) => `not released yet; call ${tool(name)} again with wait, in seconds, to wait for the release`;
|
|
17
|
+
export const ALSO_MAX = 9;
|
|
18
|
+
export const noneReleased = (name, count) => `none of the ${count} escrows is released yet; call ${tool(name)} again with wait, in seconds, to wait for the first release`;
|
|
19
|
+
export const noneKnown = (name, count) => `no release of the ${count} escrows was found, but the history of some could not be read in full, so whether they were released is unknown; call ${tool(name)} again in a few seconds, or read each alone`;
|
|
17
20
|
export const RELEASE_LANDING = "the escrow is marked released on chain, but the RPC node has not returned the release transaction yet, so who it paid is not known; call again in a few seconds";
|
|
18
21
|
export const stillUnknown = (name) => `the RPC node had not returned the escrow's release when the wait ran out, so whether and how it was paid is still unknown; call ${tool(name)} again with wait in a few seconds`;
|
|
19
|
-
export
|
|
20
|
-
const waitInput = optional(integer(1, WAIT_MAX, "most seconds to wait for
|
|
21
|
-
|
|
22
|
+
export { NO_CLOCK } from "./wait.js";
|
|
23
|
+
const waitInput = optional(integer(1, WAIT_MAX, "most seconds to wait for a release; without it, the tool reads once"));
|
|
24
|
+
const alsoInput = optional(list(object({ owner: account("the wallet that made this escrow"), nonce: amount("this escrow's nonce") }), ALSO_MAX, `up to ${ALSO_MAX} more escrows, each by owner and nonce, read with the one nonce names; the result is the first released, and its owner and nonce say which, and escrows gives the state of each; sha256 and release apply only to the one nonce names`));
|
|
25
|
+
const unknownIn = (receipt) => "complete" in receipt && receipt.complete === false;
|
|
26
|
+
const paidWalletsIn = (paid) => (!paid.released ? undefined : paid.paid_to !== undefined ? [paid.paid_to] : paid.paid_wallets);
|
|
27
|
+
const stateOf = ({ owner, nonce }, receipt) => {
|
|
28
|
+
const paid = receipt;
|
|
29
|
+
return {
|
|
30
|
+
owner,
|
|
31
|
+
nonce,
|
|
32
|
+
intent: receipt.intent,
|
|
33
|
+
released: receipt.released,
|
|
34
|
+
...(unknownIn(receipt) ? { complete: false } : {}),
|
|
35
|
+
...(!paid.released ? {} : paid.paid_to !== undefined ? { paid_to: paid.paid_to } : paid.paid_wallets !== undefined ? { paid_wallets: paid.paid_wallets } : {}),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
async function firstReleased(transport, escrows) {
|
|
39
|
+
const read = [];
|
|
40
|
+
for (const { owner, nonce, sha256, release } of escrows) {
|
|
41
|
+
read.push(await escrowReceipt(transport, owner, nonce, sha256, release));
|
|
42
|
+
}
|
|
43
|
+
const [first] = read;
|
|
44
|
+
if (escrows.length === 1) {
|
|
45
|
+
return first;
|
|
46
|
+
}
|
|
47
|
+
const states = escrows.map((escrow, at) => stateOf(escrow, read[at]));
|
|
48
|
+
const at = read.findIndex(({ released }) => released);
|
|
49
|
+
const escrow = escrows[at];
|
|
50
|
+
if (escrow !== undefined) {
|
|
51
|
+
return { ...read[at], owner: escrow.owner, nonce: escrow.nonce, escrows: states };
|
|
52
|
+
}
|
|
53
|
+
return read.some(unknownIn) ? { intent: first.intent, released: false, complete: false, next: "", escrows: states } : { ...first, escrows: states };
|
|
54
|
+
}
|
|
55
|
+
export const paidOther = (wallets, self) => `this release paid ${wallets.join(", ")}, not this wallet ${self}: matches and valid describe the recorded work, and this wallet was not paid for it`;
|
|
56
|
+
function forWallet(receipt, self) {
|
|
57
|
+
const paid = (state) => {
|
|
58
|
+
const wallets = paidWalletsIn(state);
|
|
59
|
+
return wallets === undefined ? {} : { paid_this_wallet: wallets.includes(self) };
|
|
60
|
+
};
|
|
61
|
+
const escrows = receipt.escrows?.map((state) => ({ ...state, ...paid(state) }));
|
|
62
|
+
const own = paid(receipt);
|
|
63
|
+
const wallets = paidWalletsIn(receipt);
|
|
64
|
+
const shown = { ...receipt, ...own, ...(escrows === undefined ? {} : { escrows }) };
|
|
65
|
+
if (own.paid_this_wallet !== false || wallets === undefined) {
|
|
66
|
+
return shown;
|
|
67
|
+
}
|
|
68
|
+
const prior = "next" in receipt ? receipt.next : undefined;
|
|
69
|
+
const line = paidOther(wallets, self);
|
|
70
|
+
return { ...shown, next: typeof prior === "string" && prior !== "" ? `${line}; ${prior}` : line };
|
|
71
|
+
}
|
|
72
|
+
async function waitedReceipt(ctx, name, wait, escrows) {
|
|
73
|
+
const many = escrows.length > 1;
|
|
74
|
+
const told = (last) => last.released
|
|
75
|
+
? last
|
|
76
|
+
: unknownIn(last)
|
|
77
|
+
? many
|
|
78
|
+
? { ...last, next: noneKnown(name, escrows.length) }
|
|
79
|
+
: wait === undefined
|
|
80
|
+
? last
|
|
81
|
+
: { ...last, next: stillUnknown(name) }
|
|
82
|
+
: { ...last, next: many ? noneReleased(name, escrows.length) : stillUnreleased(name) };
|
|
22
83
|
if (wait === undefined) {
|
|
23
|
-
return
|
|
84
|
+
return told(await firstReleased(ctx.transport, escrows));
|
|
24
85
|
}
|
|
25
86
|
const clock = ctx.wallet ?? ctx.clock;
|
|
26
87
|
if (clock === undefined) {
|
|
@@ -29,12 +90,12 @@ async function waitedReceipt(ctx, name, wait, read) {
|
|
|
29
90
|
const fresh = unmemoized(ctx.transport);
|
|
30
91
|
let receipt;
|
|
31
92
|
await poll(clock, wait, async () => {
|
|
32
|
-
receipt = await
|
|
93
|
+
receipt = await firstReleased(memoized(fresh), escrows);
|
|
33
94
|
return receipt.released;
|
|
34
95
|
});
|
|
35
|
-
|
|
36
|
-
return last.released ? last : { ...last, next: "complete" in last && last.complete === false ? stillUnknown(name) : stillUnreleased(name) };
|
|
96
|
+
return told(receipt);
|
|
37
97
|
}
|
|
98
|
+
const escrowsOf = (first, also) => [first, ...(also ?? [])];
|
|
38
99
|
const receiptOutput = object({
|
|
39
100
|
intent: account(),
|
|
40
101
|
released: flag(),
|
|
@@ -52,12 +113,26 @@ const receiptOutput = object({
|
|
|
52
113
|
delivered_salt: optional(text("the payee's salt the release recorded, which opens the payee's announcement")),
|
|
53
114
|
valid: optional(flag("given with delivered_salt: whether that salt opens an announcement by the payee to the recorded sha256")),
|
|
54
115
|
refuted_by: optional(text("an earlier announcement of the same work that a published opening shows, so the release paid a later announcer")),
|
|
116
|
+
paid_wallets: optional(list(account(), MAX_RECIPIENTS, "the wallets a split release paid")),
|
|
117
|
+
paid_this_wallet: optional(flag("wallet_receipt with a released escrow whose payees are known: whether the release paid this server's wallet")),
|
|
118
|
+
owner: optional(account("given with also: the owner of the escrow released")),
|
|
119
|
+
nonce: optional(amount("given with also: the nonce of the escrow released")),
|
|
120
|
+
escrows: optional(list(object({
|
|
121
|
+
owner: account(),
|
|
122
|
+
nonce: amount(),
|
|
123
|
+
intent: account(),
|
|
124
|
+
released: flag(),
|
|
125
|
+
complete: optional(flag("false when the history read was not enough to know whether it was released")),
|
|
126
|
+
paid_to: optional(account("the wallet the release paid")),
|
|
127
|
+
paid_wallets: optional(list(account(), MAX_RECIPIENTS, "the wallets a split release paid")),
|
|
128
|
+
paid_this_wallet: optional(flag("wallet_receipt only: whether the release paid this server's wallet")),
|
|
129
|
+
}), ALSO_MAX + 1, "given with also: every named escrow in the order given, released or not, with whom each release paid")),
|
|
55
130
|
next: optional(text()),
|
|
56
131
|
});
|
|
57
132
|
export const walletReceipt = define({
|
|
58
133
|
name: tool("wallet_receipt"),
|
|
59
134
|
title: "Check an escrow release",
|
|
60
|
-
description: `Shows whether an escrow was released: to whom, for how much, by which attestor (judge), and which work it recorded. A
|
|
135
|
+
description: `Shows whether an escrow was released: to whom, for how much, by which attestor (judge), and which work it recorded. A worker passes the job's owner and nonce from ${tool("wallet_deliver")}, and in also up to ${ALSO_MAX} more jobs. Give sha256 to check the paid work. Pass wait, in seconds, to wait for the first release. It sends nothing.`,
|
|
61
136
|
effect: "read",
|
|
62
137
|
input: object({
|
|
63
138
|
owner: optional(account("the wallet that made the escrow; default this server's wallet")),
|
|
@@ -65,11 +140,13 @@ export const walletReceipt = define({
|
|
|
65
140
|
sha256: optional(text("the sha256, as 64 hex digits, of the work, to compare with the one the release recorded")),
|
|
66
141
|
release: optional(text(RELEASE_INPUT)),
|
|
67
142
|
wait: waitInput,
|
|
143
|
+
also: alsoInput,
|
|
68
144
|
}),
|
|
69
145
|
output: receiptOutput,
|
|
70
146
|
run: async (ctx, input) => {
|
|
71
147
|
const self = (await signerOf(ctx)).address;
|
|
72
|
-
const
|
|
148
|
+
const escrows = escrowsOf({ owner: input.owner ?? self, nonce: input.nonce, sha256: input.sha256, release: input.release }, input.also);
|
|
149
|
+
const receipt = forWallet(await waitedReceipt(ctx, "wallet_receipt", input.wait, escrows), self);
|
|
73
150
|
const wrapped = "paid_to" in receipt && receipt.paid_to === self && receipt.mint === NATIVE_MINT;
|
|
74
151
|
if (!wrapped) {
|
|
75
152
|
return receipt;
|
|
@@ -82,7 +159,7 @@ export const walletReceipt = define({
|
|
|
82
159
|
export const getReceipt = define({
|
|
83
160
|
name: tool("get_receipt"),
|
|
84
161
|
title: "Check any owner's escrow release",
|
|
85
|
-
description: `Look up whether an escrow was released: to whom, for how much, by which attestor, and which delivered work the release recorded. Give sha256, the hash of the work you received, to check it is the work that was paid for, and release, the signature the release returned, to read the release from that one transaction however long the escrow's history grew. It reads the escrow's own transactions, sends nothing and needs no wallet. Pass wait, in seconds, to wait for the release.`,
|
|
162
|
+
description: `Look up whether an escrow was released: to whom, for how much, by which attestor, and which delivered work the release recorded. Give sha256, the hash of the work you received, to check it is the work that was paid for, and release, the signature the release returned, to read the release from that one transaction however long the escrow's history grew. It reads the escrow's own transactions, sends nothing and needs no wallet. Pass wait, in seconds, to wait for the release, and in also up to ${ALSO_MAX} more escrows by owner and nonce, to wait for the first release among them.`,
|
|
86
163
|
effect: "read",
|
|
87
164
|
input: object({
|
|
88
165
|
owner: account("the wallet that made the escrow"),
|
|
@@ -90,9 +167,10 @@ export const getReceipt = define({
|
|
|
90
167
|
sha256: optional(text("the sha256, as 64 hex digits, of the work you received, to compare with the one the release recorded")),
|
|
91
168
|
release: optional(text(RELEASE_INPUT)),
|
|
92
169
|
wait: waitInput,
|
|
170
|
+
also: alsoInput,
|
|
93
171
|
}),
|
|
94
172
|
output: receiptOutput,
|
|
95
|
-
run: async (ctx, input) => waitedReceipt(ctx, "get_receipt", input.wait, (
|
|
173
|
+
run: async (ctx, input) => waitedReceipt(ctx, "get_receipt", input.wait, escrowsOf({ owner: input.owner, nonce: input.nonce, sha256: input.sha256, release: input.release }, input.also)),
|
|
96
174
|
});
|
|
97
175
|
export async function escrowReceipt(transport, owner, nonce, sha256, releaseSignature) {
|
|
98
176
|
const wanted = sha256 === undefined ? undefined : sha256Of(sha256, "sha256");
|
|
@@ -144,11 +222,13 @@ export async function escrowReceipt(transport, owner, nonce, sha256, releaseSign
|
|
|
144
222
|
if (release.event.name === "IntentSplit") {
|
|
145
223
|
mint ??= await heldMint(transport, intent);
|
|
146
224
|
const decimals = mint === undefined ? undefined : (await mintOf(transport, mint)).decimals;
|
|
225
|
+
const wallets = await paidWalletsOf(transport, { event: release.event, transaction: tx }, intent);
|
|
147
226
|
return {
|
|
148
227
|
...common,
|
|
149
228
|
paid: formatAmount(fields["net"], decimals),
|
|
150
229
|
...(mint === undefined ? {} : { mint }),
|
|
151
230
|
recipients: BigInt(fields["recipients"]),
|
|
231
|
+
...(wallets === null ? {} : { paid_wallets: wallets }),
|
|
152
232
|
};
|
|
153
233
|
}
|
|
154
234
|
const payee = fields["payee"];
|