@moonbeam-foundation/sdk 0.5.2 → 0.7.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/README.md +137 -38
- package/dist/abi/index.d.ts +55 -0
- package/dist/abi/index.d.ts.map +1 -0
- package/dist/abi/index.js +227 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/acp/events.d.ts +38 -38
- package/dist/acp/events.d.ts.map +1 -1
- package/dist/acp/events.js.map +1 -1
- package/dist/acp/moonbeam-acp.generated.d.ts +50 -0
- package/dist/acp/moonbeam-acp.generated.d.ts.map +1 -0
- package/dist/acp/moonbeam-acp.generated.js +56 -0
- package/dist/acp/moonbeam-acp.generated.js.map +1 -0
- package/dist/acp/pipeline.js.map +1 -1
- package/dist/acp/registry.d.ts.map +1 -1
- package/dist/acp/registry.js +5 -3
- package/dist/acp/registry.js.map +1 -1
- package/dist/actors/track-record.js.map +1 -1
- package/dist/adapters/acp.js.map +1 -1
- package/dist/adapters/stamp.d.ts +1 -1
- package/dist/adapters/stamp.d.ts.map +1 -1
- package/dist/arbitration/index.d.ts +120 -0
- package/dist/arbitration/index.d.ts.map +1 -0
- package/dist/arbitration/index.js +116 -0
- package/dist/arbitration/index.js.map +1 -0
- package/dist/assurance/assurance-shared.d.ts +1924 -0
- package/dist/assurance/assurance-shared.d.ts.map +1 -0
- package/dist/assurance/assurance-shared.js +2225 -0
- package/dist/assurance/assurance-shared.js.map +1 -0
- package/dist/assurance/index.d.ts +57 -0
- package/dist/assurance/index.d.ts.map +1 -0
- package/dist/assurance/index.js +49 -0
- package/dist/assurance/index.js.map +1 -0
- package/dist/attest/index.d.ts +19 -0
- package/dist/attest/index.d.ts.map +1 -0
- package/dist/attest/index.js +17 -0
- package/dist/attest/index.js.map +1 -0
- package/dist/client/index.d.ts +16 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +21 -1
- package/dist/client/index.js.map +1 -1
- package/dist/connect/logs.js.map +1 -1
- package/dist/core/money.js.map +1 -1
- package/dist/core/settle.js.map +1 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/erc8004/index.d.ts +9 -9
- package/dist/erc8004/index.d.ts.map +1 -1
- package/dist/erc8004/index.js.map +1 -1
- package/dist/erc8183/index.d.ts +12 -12
- package/dist/erc8183/index.d.ts.map +1 -1
- package/dist/erc8183/index.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/judge/index.d.ts +35 -3
- package/dist/judge/index.d.ts.map +1 -1
- package/dist/judge/index.js +41 -2
- package/dist/judge/index.js.map +1 -1
- package/dist/launcher/index.d.ts +3 -3
- package/dist/launcher/index.d.ts.map +1 -1
- package/dist/onboard/index.d.ts +64 -24
- package/dist/onboard/index.d.ts.map +1 -1
- package/dist/onboard/index.js +90 -15
- package/dist/onboard/index.js.map +1 -1
- package/dist/pools/index.d.ts +49 -7
- package/dist/pools/index.d.ts.map +1 -1
- package/dist/pools/index.js +30 -6
- package/dist/pools/index.js.map +1 -1
- package/dist/proof/index.d.ts +117 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +81 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/resale/index.d.ts +120 -0
- package/dist/resale/index.d.ts.map +1 -0
- package/dist/resale/index.js +117 -0
- package/dist/resale/index.js.map +1 -0
- package/dist/resale/payment-scheme.d.mts +46 -0
- package/dist/resale/payment-scheme.mjs +351 -0
- package/dist/resale/payment-scheme.pin.json +6 -0
- package/dist/rpc/index.d.ts +24 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +66 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/x402/index.d.ts +90 -0
- package/dist/x402/index.d.ts.map +1 -0
- package/dist/x402/index.js +75 -0
- package/dist/x402/index.js.map +1 -0
- package/examples/03-end-to-end-offline.mjs +2 -2
- package/examples/14-grade-record.mjs +6 -4
- package/examples/17-grade-live.mjs +1 -1
- package/examples/20-onboard-client.mjs +2 -2
- package/examples/24-resell-on-base.mjs +17 -0
- package/examples/{30-read-a-real-job.mjs → 30-read-a-job.mjs} +2 -2
- package/examples/32-read-live-from-base.mjs +8 -11
- package/examples/40-the-article.mjs +1 -1
- package/examples/50-x402-pay-a-wall.mjs +17 -0
- package/examples/51-read-a-proof.mjs +21 -0
- package/examples/52-arbitration-calls.mjs +13 -0
- package/examples/53-attested-by-default.mjs +19 -0
- package/examples/README.md +13 -6
- package/examples/data/proof-base-tx-52587000.json +116 -0
- package/package.json +51 -10
- package/skills/moonbeam-actor-backer/SKILL.md +1 -1
- package/skills/moonbeam-actor-challenger/SKILL.md +1 -1
- package/skills/moonbeam-actor-doubter/SKILL.md +1 -1
- package/skills/moonbeam-assurance/SKILL.md +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moonbeam-foundation/sdk/proof: read the proof that a Base transaction is inside the layer's superroot, name it with a
|
|
3
|
+
* ref (`v5:<chain>:<tx>@<superroot>`), and check the served blob with the V5 proof verifier on Base itself.
|
|
4
|
+
*
|
|
5
|
+
* readProof(t, tx) GET /v1/proof/tx/8453/<tx>: the block, the superroot, `checks`, `proven`, the blob
|
|
6
|
+
* proofRef / parseProofRef the one-line name of a proof, and back
|
|
7
|
+
* verifyCall(blob) the unsigned eth_call the verifier answers (`verify(blob)`)
|
|
8
|
+
* verifyOnBase(reader, p) that eth_call on Base: true, false, or the verifier's own error name
|
|
9
|
+
*
|
|
10
|
+
* What the on-chain check proves today: the superroot commits to the Base header the blob names (L1–L3). The deployed
|
|
11
|
+
* verifier folds the snapshot tip's header, so a transaction's block is bound to that tip by the served `inclusion`
|
|
12
|
+
* path, which this module reports and does not re-fold. The verifier has no superroot anchor configured yet
|
|
13
|
+
* (`superrootAnchor` is the zero address), so the superroot is asserted by the verifier, not anchored: `anchored: false`.
|
|
14
|
+
*/
|
|
15
|
+
import type { OnboardTransport } from '../onboard/index.js';
|
|
16
|
+
import { type BaseReader } from '../rpc/index.js';
|
|
17
|
+
/** TaifoonV5ProofVerifier (gated) on Base, from the address registry */
|
|
18
|
+
export declare const V5_VERIFIER: `0x${string}`;
|
|
19
|
+
export type Header = {
|
|
20
|
+
chainId: number;
|
|
21
|
+
chainType: number;
|
|
22
|
+
blockNumber: number;
|
|
23
|
+
blockHash: string;
|
|
24
|
+
miniMmrRoot: string;
|
|
25
|
+
twigCount: number;
|
|
26
|
+
stateRoot: string;
|
|
27
|
+
};
|
|
28
|
+
export type ProofBlob = {
|
|
29
|
+
superroot: {
|
|
30
|
+
superrootHash: string;
|
|
31
|
+
batchId: number;
|
|
32
|
+
chainCount: number;
|
|
33
|
+
totalTwigs: number;
|
|
34
|
+
};
|
|
35
|
+
chainHeaders: Header[];
|
|
36
|
+
superrootProof: {
|
|
37
|
+
targetChainIndex: number;
|
|
38
|
+
siblings: string[];
|
|
39
|
+
};
|
|
40
|
+
blockProof: {
|
|
41
|
+
blockIndex: number;
|
|
42
|
+
siblings: string[];
|
|
43
|
+
l4Status?: string;
|
|
44
|
+
inclusion?: {
|
|
45
|
+
blockNumber: number;
|
|
46
|
+
blockHash: string;
|
|
47
|
+
index: number;
|
|
48
|
+
siblings: string[];
|
|
49
|
+
root: string;
|
|
50
|
+
tipBlockNumber: number;
|
|
51
|
+
tipBlockHash: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
finality: {
|
|
55
|
+
finalityType: number;
|
|
56
|
+
finalizedBlockNumber: number;
|
|
57
|
+
finalizedBlockHash: string;
|
|
58
|
+
proof: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type TxProof = {
|
|
62
|
+
ok: true;
|
|
63
|
+
chain_id: number;
|
|
64
|
+
tx: string;
|
|
65
|
+
block_number: number;
|
|
66
|
+
block_hash: string;
|
|
67
|
+
is_finalized: boolean;
|
|
68
|
+
super_root_hash: string | null;
|
|
69
|
+
checks: Record<string, boolean>;
|
|
70
|
+
blob: ProofBlob | null;
|
|
71
|
+
/** every check the layer names is true */
|
|
72
|
+
proven: boolean;
|
|
73
|
+
ref: string | null;
|
|
74
|
+
};
|
|
75
|
+
/** Read the proof of one Base transaction from the layer (keyless). Throws on a malformed hash or a refused read. */
|
|
76
|
+
export declare function readProof(t: OnboardTransport, tx: string): Promise<TxProof>;
|
|
77
|
+
/** `v5:<chain>:<tx>@<superroot>`: the one-line name of a proof */
|
|
78
|
+
export declare const proofRef: (p: {
|
|
79
|
+
chainId: number;
|
|
80
|
+
tx: string;
|
|
81
|
+
superroot: string;
|
|
82
|
+
}) => string;
|
|
83
|
+
export declare function parseProofRef(ref: string): {
|
|
84
|
+
chainId: number;
|
|
85
|
+
tx: string;
|
|
86
|
+
superroot: string;
|
|
87
|
+
};
|
|
88
|
+
export declare const VERIFY_SIG = "verify(((bytes32 superrootHash,uint64 batchId,uint32 chainCount,uint64 totalTwigs) superroot,(uint64 chainId,uint8 chainType,uint64 blockNumber,bytes32 blockHash,bytes32 miniMmrRoot,uint64 twigCount,bytes32 stateRoot)[] chainHeaders,(uint32 targetChainIndex,bytes32[] siblings) superrootProof,(uint64 blockIndex,bytes32[] siblings) blockProof,(uint8 chainType,bytes encoded) event_,(uint8 finalityType,uint64 finalizedBlockNumber,bytes32 finalizedBlockHash,bytes finalityProof) finality) blob)";
|
|
89
|
+
/** The verifier's `verify(blob)` call for a served blob. The header is placed at its index in the superroot (the other
|
|
90
|
+
* slots zero, as the encoder does) and bound at the snapshot tip the inclusion path names; the event is the header's
|
|
91
|
+
* carrier event (topics = [blockHash]). */
|
|
92
|
+
export declare function verifyCall(blob: ProofBlob): {
|
|
93
|
+
to: string;
|
|
94
|
+
data: string;
|
|
95
|
+
boundAt: {
|
|
96
|
+
blockNumber: number;
|
|
97
|
+
blockHash: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
/** the verifier's error names, by selector (from its ABI) */
|
|
101
|
+
export declare const VERIFIER_ERRORS: Readonly<Record<string, string>>;
|
|
102
|
+
export type OnChainCheck = {
|
|
103
|
+
verifier: string;
|
|
104
|
+
verified: boolean;
|
|
105
|
+
error: string | null;
|
|
106
|
+
/** the verifier checked the superroot against an on-chain anchor (false while superrootAnchor is unset) */
|
|
107
|
+
anchored: boolean;
|
|
108
|
+
boundAt: {
|
|
109
|
+
blockNumber: number;
|
|
110
|
+
blockHash: string;
|
|
111
|
+
};
|
|
112
|
+
/** the block → tip binding the layer served (not re-folded here) */
|
|
113
|
+
inclusion: 'served' | 'none';
|
|
114
|
+
};
|
|
115
|
+
/** Ask the V5 verifier on Base whether the served blob verifies (an eth_call: no key, no gas). */
|
|
116
|
+
export declare function verifyOnBase(reader: BaseReader, blob: ProofBlob): Promise<OnChainCheck>;
|
|
117
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proof/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGxE,wEAAwE;AACxE,eAAO,MAAM,WAAW,eAAsB,CAAC;AAE/C,MAAM,MAAM,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/J,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,C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
|
1
|
+
import { encodeFunction, decodeStatic, encodeParams } from '../abi/index.js';
|
|
2
|
+
import { keccakHex, hexToBytes } from '../onboard/index.js';
|
|
3
|
+
import { ethCall, RpcReverted } from '../rpc/index.js';
|
|
4
|
+
import { REGISTRY } from '../acp/moonbeam-acp.generated.js';
|
|
5
|
+
/** TaifoonV5ProofVerifier (gated) on Base, from the address registry */
|
|
6
|
+
export const V5_VERIFIER = REGISTRY.v5Verifier;
|
|
7
|
+
const TX_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
8
|
+
/** Read the proof of one Base transaction from the layer (keyless). Throws on a malformed hash or a refused read. */
|
|
9
|
+
export async function readProof(t, tx) {
|
|
10
|
+
if (!TX_RE.test(tx))
|
|
11
|
+
throw new RangeError('a transaction hash is 0x + 64 hex');
|
|
12
|
+
const r = await t.fetch(`${t.base}/proof/tx/8453/${tx}`, { method: 'GET', headers: { accept: 'application/json', ...(t.apiKey ? { 'x-api-key': t.apiKey } : {}) } });
|
|
13
|
+
const j = (await r.json().catch(() => null));
|
|
14
|
+
if (!r.ok || !j?.ok)
|
|
15
|
+
throw new Error(j?.error ?? `GET /proof/tx/8453/${tx} → ${r.status}`);
|
|
16
|
+
const checks = j.checks ?? {};
|
|
17
|
+
const proven = Object.keys(checks).length > 0 && Object.values(checks).every(Boolean) && j.blob !== null;
|
|
18
|
+
const root = j.super_root_hash ? (j.super_root_hash.startsWith('0x') ? j.super_root_hash : `0x${j.super_root_hash}`) : null;
|
|
19
|
+
return { ...j, super_root_hash: root, checks, proven, ref: root ? proofRef({ chainId: j.chain_id, tx: j.tx, superroot: root }) : null };
|
|
20
|
+
}
|
|
21
|
+
/** `v5:<chain>:<tx>@<superroot>`: the one-line name of a proof */
|
|
22
|
+
export const proofRef = (p) => `v5:${p.chainId}:${p.tx.toLowerCase()}@${p.superroot.toLowerCase()}`;
|
|
23
|
+
export function parseProofRef(ref) {
|
|
24
|
+
const m = /^v5:(\d+):(0x[0-9a-fA-F]{64})@(0x[0-9a-fA-F]{64})$/.exec(ref.trim());
|
|
25
|
+
if (!m)
|
|
26
|
+
throw new RangeError('a proof ref is v5:<chain>:<tx>@<superroot>');
|
|
27
|
+
return { chainId: Number(m[1]), tx: m[2].toLowerCase(), superroot: m[3].toLowerCase() };
|
|
28
|
+
}
|
|
29
|
+
const BLOB_T = '(bytes32 superrootHash,uint64 batchId,uint32 chainCount,uint64 totalTwigs) superroot,(uint64 chainId,uint8 chainType,uint64 blockNumber,bytes32 blockHash,bytes32 miniMmrRoot,uint64 twigCount,bytes32 stateRoot)[] chainHeaders,(uint32 targetChainIndex,bytes32[] siblings) superrootProof,(uint64 blockIndex,bytes32[] siblings) blockProof,(uint8 chainType,bytes encoded) event_,(uint8 finalityType,uint64 finalizedBlockNumber,bytes32 finalizedBlockHash,bytes finalityProof) finality';
|
|
30
|
+
const EVM_EVENT_T = '(bytes32 txHash,uint32 txIndex,bytes32[] txMerkleProof,bytes32 receiptsRoot,bytes32[] receiptProof,uint8 receiptStatus,uint64 gasUsed,address contractAddress,uint32 logIndex,bytes32[] topics,bytes data,bytes32 eventHash)';
|
|
31
|
+
export const VERIFY_SIG = `verify((${BLOB_T}) blob)`;
|
|
32
|
+
const Z32 = `0x${'0'.repeat(64)}`;
|
|
33
|
+
/** The verifier's `verify(blob)` call for a served blob. The header is placed at its index in the superroot (the other
|
|
34
|
+
* slots zero, as the encoder does) and bound at the snapshot tip the inclusion path names; the event is the header's
|
|
35
|
+
* carrier event (topics = [blockHash]). */
|
|
36
|
+
export function verifyCall(blob) {
|
|
37
|
+
const h0 = blob.chainHeaders[0];
|
|
38
|
+
if (!h0)
|
|
39
|
+
throw new Error('the blob names no chain header');
|
|
40
|
+
const inc = blob.blockProof.inclusion;
|
|
41
|
+
const h = inc ? { ...h0, blockNumber: inc.tipBlockNumber, blockHash: inc.tipBlockHash } : h0;
|
|
42
|
+
const tci = blob.superrootProof.targetChainIndex;
|
|
43
|
+
const zero = { chainId: 0, chainType: 0, blockNumber: 0, blockHash: Z32, miniMmrRoot: Z32, twigCount: 0, stateRoot: Z32 };
|
|
44
|
+
const headers = Array.from({ length: tci + 1 }, (_, i) => (i === tci ? h : zero));
|
|
45
|
+
const topics = [h.blockHash];
|
|
46
|
+
const eventHash = keccakHex(hexToBytes(encodeParams(['bytes32[]', 'bytes'], [topics, '0x'])));
|
|
47
|
+
const encoded = encodeParams([EVM_EVENT_T], [{ txHash: Z32, txIndex: 0, txMerkleProof: [], receiptsRoot: Z32, receiptProof: [], receiptStatus: 0, gasUsed: 0, contractAddress: `0x${'0'.repeat(40)}`, logIndex: 0, topics, data: '0x', eventHash }]);
|
|
48
|
+
const data = encodeFunction(VERIFY_SIG, [{
|
|
49
|
+
superroot: blob.superroot, chainHeaders: headers, superrootProof: blob.superrootProof,
|
|
50
|
+
blockProof: { blockIndex: blob.blockProof.blockIndex, siblings: [] }, event_: { chainType: 0, encoded },
|
|
51
|
+
finality: { finalityType: blob.finality.finalityType, finalizedBlockNumber: blob.finality.finalizedBlockNumber, finalizedBlockHash: blob.finality.finalizedBlockHash, finalityProof: blob.finality.proof },
|
|
52
|
+
}]);
|
|
53
|
+
return { to: V5_VERIFIER, data, boundAt: { blockNumber: h.blockNumber, blockHash: h.blockHash } };
|
|
54
|
+
}
|
|
55
|
+
/** the verifier's error names, by selector (from its ABI) */
|
|
56
|
+
export const VERIFIER_ERRORS = { '0xd3137376': 'L3_SuperrootPathInvalid' };
|
|
57
|
+
/** Ask the V5 verifier on Base whether the served blob verifies (an eth_call: no key, no gas). */
|
|
58
|
+
export async function verifyOnBase(reader, blob) {
|
|
59
|
+
const c = verifyCall(blob);
|
|
60
|
+
let anchored = false;
|
|
61
|
+
try {
|
|
62
|
+
const [a] = decodeStatic(['address'], await ethCall(reader, V5_VERIFIER, encodeFunction('superrootAnchor()', [])));
|
|
63
|
+
anchored = a !== `0x${'0'.repeat(40)}`;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
anchored = false;
|
|
67
|
+
}
|
|
68
|
+
const base = { verifier: V5_VERIFIER, anchored, boundAt: c.boundAt, inclusion: blob.blockProof.inclusion ? 'served' : 'none' };
|
|
69
|
+
try {
|
|
70
|
+
const out = await ethCall(reader, c.to, c.data);
|
|
71
|
+
return { ...base, verified: decodeStatic(['bool'], out)[0] === true, error: null };
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (e instanceof RpcReverted) {
|
|
75
|
+
const sel = (e.data ?? '').slice(0, 10);
|
|
76
|
+
return { ...base, verified: false, error: VERIFIER_ERRORS[sel] ?? (sel || e.message) };
|
|
77
|
+
}
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proof/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC;AAkB/C,MAAM,KAAK,GAAG,qBAAqB,CAAC;AAEpC,qHAAqH;AACrH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,CAAmB,EAAE,EAAU;IAC7D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAC;IAC/E,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,kBAAkB,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,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AC;IAAC,MAAM,CAAC;QAAC,QAAQ,GAAG,KAAK,CAAC;IAAC,CAAC;IAC/L,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,QAAiB,CAAC,CAAC,CAAC,MAAe,EAAE,CAAC;IACjJ,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACrF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC;YAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAAC,OAAO,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QAAC,CAAC;QAClK,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moonbeam-foundation/sdk/resale — reselling on Base, the Moonbeam profile of the coordination layer's ONE payment scheme.
|
|
3
|
+
*
|
|
4
|
+
* A reseller is a tenant of the layer whose visitors buy on child keys. Every number a reseller shows or charges comes from the
|
|
5
|
+
* one scheme the layer itself prices with (payment-scheme.mjs, a byte-identical vendored copy pinned by its sha256):
|
|
6
|
+
*
|
|
7
|
+
* price_to_buyer = seller_price + our_fee + venue_fee(in) + venue_fee(out) [+ reseller_markup]
|
|
8
|
+
*
|
|
9
|
+
* The Moonbeam profile restricts the venues to Base (the owner's rule: Moonbeam resells on Base only) and GLMR stays the money of
|
|
10
|
+
* the assurance hook; the markup is the reseller's own leg (`reseller_markup`), never part of the layer's fee. Everything here is
|
|
11
|
+
* pure except the two reads, which take a transport (a fetch and the site's own same-origin proxy base, as ./onboard does).
|
|
12
|
+
*/
|
|
13
|
+
import { legsOfPayment, venueFeeOf, grossUp, sumOf, FORMULA, RULE, SCHEME_ID, LEGS, VENUE_FEES, OUR_FEE, type Quote, type Reseller, type FeeRule, type SchemeLeg, type Units } from './payment-scheme.mjs';
|
|
14
|
+
import type { OnboardTransport } from '../onboard/index.js';
|
|
15
|
+
export { legsOfPayment, venueFeeOf, grossUp, sumOf, FORMULA, RULE, SCHEME_ID, LEGS, VENUE_FEES, OUR_FEE };
|
|
16
|
+
export type { Quote, Reseller, FeeRule, SchemeLeg, Units };
|
|
17
|
+
/** a quote that was not refused */
|
|
18
|
+
export type OkQuote = Extract<Quote, {
|
|
19
|
+
ok: true;
|
|
20
|
+
}>;
|
|
21
|
+
/** The venues a Moonbeam reseller may buy on or hire on: the five Base venues of the standard, and the layer's own doors. */
|
|
22
|
+
export declare const BASE_VENUES: readonly ["x402-base", "erc8183-base", "memoacp-base", "bitagent-base", "olas-base"];
|
|
23
|
+
/** The layer's own labels a quote may name on the selling side (our products, a reseller's own key, the devnet). */
|
|
24
|
+
export declare const OWN_LABELS: readonly ["coord", "reseller", "mcp", "a2a", "n8n", "erc8004"];
|
|
25
|
+
export type BaseVenue = (typeof BASE_VENUES)[number];
|
|
26
|
+
export type OwnLabel = (typeof OWN_LABELS)[number];
|
|
27
|
+
export declare const isBaseVenue: (v: string) => v is BaseVenue;
|
|
28
|
+
export type BaseQuoteInput = {
|
|
29
|
+
venue_in: BaseVenue | OwnLabel;
|
|
30
|
+
venue_out: BaseVenue | OwnLabel;
|
|
31
|
+
/** the doer's own price, in the payment's smallest unit (USDC: 6 decimals) */
|
|
32
|
+
seller_price: Units;
|
|
33
|
+
class?: string | null;
|
|
34
|
+
/** the reseller's leg: its tenant id and its markup in basis points of the list price, or in units */
|
|
35
|
+
reseller?: Reseller | null;
|
|
36
|
+
our_fee?: FeeRule;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The quote a Moonbeam reseller shows: the same numbers the layer charges, on Base venues only. A venue outside Base is refused
|
|
40
|
+
* before the scheme is asked. Pure.
|
|
41
|
+
*/
|
|
42
|
+
export declare function quoteBase(i: BaseQuoteInput): Quote | {
|
|
43
|
+
ok: false;
|
|
44
|
+
why: string;
|
|
45
|
+
};
|
|
46
|
+
/** The reseller's leg of a quote: what the tenant earns on this sale (0 when its markup is 0). Pure. */
|
|
47
|
+
export declare function markupLeg(q: OkQuote): {
|
|
48
|
+
units: bigint;
|
|
49
|
+
tenant: string | null;
|
|
50
|
+
bps_of_list: number;
|
|
51
|
+
};
|
|
52
|
+
/** The legs of a quote by name, summed: our_fee · venue_fee · seller_share · reseller_markup. Pure. */
|
|
53
|
+
export declare function legsByName(q: OkQuote): Record<'our_fee' | 'venue_fee' | 'seller_share' | 'reseller_markup', bigint>;
|
|
54
|
+
/** A reseller's markup policy as the layer takes it: basis points per product, `'*'` the default. */
|
|
55
|
+
export type MarkupPolicy = Readonly<Record<string, number>>;
|
|
56
|
+
/**
|
|
57
|
+
* What a reseller child key is, in the layer's own words: the terms a reseller agrees to when it mints one. Pure data; the
|
|
58
|
+
* markup policy is checked by the layer when the key is minted (`POST /v1/tenant/keys { action: 'child' }`).
|
|
59
|
+
*/
|
|
60
|
+
export declare function childKeyTerms(markup?: MarkupPolicy): {
|
|
61
|
+
readonly rail: 'balance';
|
|
62
|
+
readonly payment_method: 'reseller-child';
|
|
63
|
+
readonly markup: MarkupPolicy;
|
|
64
|
+
readonly says: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
/** The unsigned plan of minting a child key: the call the reseller sends with its own key. Nothing is sent here. Pure. */
|
|
67
|
+
export declare function childKeyPlan(markup?: MarkupPolicy, label?: string | null): {
|
|
68
|
+
method: 'POST';
|
|
69
|
+
path: '/tenant/keys';
|
|
70
|
+
body: {
|
|
71
|
+
action: 'child';
|
|
72
|
+
markup_bps: MarkupPolicy;
|
|
73
|
+
label?: string;
|
|
74
|
+
};
|
|
75
|
+
signer: 'the reseller tenant (its own key, X-API-Key)';
|
|
76
|
+
};
|
|
77
|
+
/** The unsigned plan of a child topping up its balance through the layer's subscribe door (the x402 quote comes back as a 402). Pure. */
|
|
78
|
+
export declare function subscribePlan(o?: {
|
|
79
|
+
chainId?: 8453;
|
|
80
|
+
usdc: number;
|
|
81
|
+
create_key?: boolean;
|
|
82
|
+
}): {
|
|
83
|
+
method: 'POST';
|
|
84
|
+
path: '/access/subscribe';
|
|
85
|
+
body: {
|
|
86
|
+
chainId: 8453;
|
|
87
|
+
usdc: number;
|
|
88
|
+
create_key: boolean;
|
|
89
|
+
};
|
|
90
|
+
says: string;
|
|
91
|
+
};
|
|
92
|
+
/** One resale sale as the layer records it (GET /v1/resale/sales/{id}): the delivery grade and the seller's listing as it stands. */
|
|
93
|
+
export type ResaleSale = {
|
|
94
|
+
ok: true;
|
|
95
|
+
rule: string;
|
|
96
|
+
} & Record<string, unknown>;
|
|
97
|
+
export declare const SALE_ID_RE: RegExp;
|
|
98
|
+
/** Read one resale sale by its id through the transport (reads only; a bad id is refused before any call). */
|
|
99
|
+
export declare function readSale(t: OnboardTransport, saleId: string): Promise<ResaleSale>;
|
|
100
|
+
/** The reseller's own view (GET /v1/access/reseller): its children, their calls, what it paid at list, what they owe, the margin. */
|
|
101
|
+
export declare function readResellerView(t: OnboardTransport): Promise<Record<string, unknown>>;
|
|
102
|
+
import { type Attested, type MoonbeamAttestOptions } from '../attest/index.js';
|
|
103
|
+
/** quoteSale over the Base venues: the layer's own quoteSale, refused outside Base (the same as quoteBase). Pure. */
|
|
104
|
+
export declare const quoteSale: typeof quoteBase;
|
|
105
|
+
/** The steps of a resale the SDK attests: quoted (the terms), paid (the buyer's payment), delivered, settled (the legs). */
|
|
106
|
+
export type SaleStep = 'quoted' | 'paid' | 'delivered' | 'settled' | 'refunded';
|
|
107
|
+
/**
|
|
108
|
+
* The attested mark, the decision-log attestation and (for delivered, settled, refunded) the stamp of one resale step,
|
|
109
|
+
* Base by default (`networks: 'none'` opts out). The subject is the sale key on the contract the step pays through (the
|
|
110
|
+
* wall's payTo, a venue escrow) or the zero address when there is none; the digest is keccak256 of the step's canonical body.
|
|
111
|
+
*/
|
|
112
|
+
export declare function attestSale(a: {
|
|
113
|
+
saleKey: string;
|
|
114
|
+
step: SaleStep;
|
|
115
|
+
quote?: OkQuote;
|
|
116
|
+
tx?: string | null;
|
|
117
|
+
contract?: string;
|
|
118
|
+
body?: unknown;
|
|
119
|
+
}, opts?: MoonbeamAttestOptions): Attested;
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resale/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACuB,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAC1H,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EACpE,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC1G,YAAY,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U,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9E,eAAO,MAAM,UAAU,QAAiC,CAAC;AAEzD,8GAA8G;AAC9G,wBAAsB,QAAQ,CAAC,CAAC,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMvF;AAED,qIAAqI;AACrI,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAK5F;AAGD,OAAO,EAAwB,KAAK,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAErG,qHAAqH;AACrH,eAAO,MAAM,SAAS,kBAAY,CAAC;AAEnC,4HAA4H;AAC5H,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAIhF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,IAAI,GAAE,qBAA0B,GAAG,QAAQ,CAUrL"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moonbeam-foundation/sdk/resale — reselling on Base, the Moonbeam profile of the coordination layer's ONE payment scheme.
|
|
3
|
+
*
|
|
4
|
+
* A reseller is a tenant of the layer whose visitors buy on child keys. Every number a reseller shows or charges comes from the
|
|
5
|
+
* one scheme the layer itself prices with (payment-scheme.mjs, a byte-identical vendored copy pinned by its sha256):
|
|
6
|
+
*
|
|
7
|
+
* price_to_buyer = seller_price + our_fee + venue_fee(in) + venue_fee(out) [+ reseller_markup]
|
|
8
|
+
*
|
|
9
|
+
* The Moonbeam profile restricts the venues to Base (the owner's rule: Moonbeam resells on Base only) and GLMR stays the money of
|
|
10
|
+
* the assurance hook; the markup is the reseller's own leg (`reseller_markup`), never part of the layer's fee. Everything here is
|
|
11
|
+
* pure except the two reads, which take a transport (a fetch and the site's own same-origin proxy base, as ./onboard does).
|
|
12
|
+
*/
|
|
13
|
+
import { quoteSale as coreQuoteSale, legsOfPayment, venueFeeOf, grossUp, sumOf, FORMULA, RULE, SCHEME_ID, LEGS, VENUE_FEES, OUR_FEE, } from './payment-scheme.mjs';
|
|
14
|
+
export { legsOfPayment, venueFeeOf, grossUp, sumOf, FORMULA, RULE, SCHEME_ID, LEGS, VENUE_FEES, OUR_FEE };
|
|
15
|
+
/** The venues a Moonbeam reseller may buy on or hire on: the five Base venues of the standard, and the layer's own doors. */
|
|
16
|
+
export const BASE_VENUES = Object.freeze(['x402-base', 'erc8183-base', 'memoacp-base', 'bitagent-base', 'olas-base']);
|
|
17
|
+
/** The layer's own labels a quote may name on the selling side (our products, a reseller's own key, the devnet). */
|
|
18
|
+
export const OWN_LABELS = Object.freeze(['coord', 'reseller', 'mcp', 'a2a', 'n8n', 'erc8004']);
|
|
19
|
+
export const isBaseVenue = (v) => BASE_VENUES.includes(v);
|
|
20
|
+
const allowed = (v) => isBaseVenue(v) || OWN_LABELS.includes(v);
|
|
21
|
+
/**
|
|
22
|
+
* The quote a Moonbeam reseller shows: the same numbers the layer charges, on Base venues only. A venue outside Base is refused
|
|
23
|
+
* before the scheme is asked. Pure.
|
|
24
|
+
*/
|
|
25
|
+
export function quoteBase(i) {
|
|
26
|
+
for (const [k, v] of [['venue_in', i.venue_in], ['venue_out', i.venue_out]]) {
|
|
27
|
+
if (!allowed(v))
|
|
28
|
+
return { ok: false, why: `${k} ${v} is not a Base venue of the Moonbeam profile (${BASE_VENUES.join(' · ')}) nor one of the layer's own labels (${OWN_LABELS.join(' · ')})` };
|
|
29
|
+
}
|
|
30
|
+
return coreQuoteSale({ venue_in: i.venue_in, venue_out: i.venue_out, class: i.class ?? null, seller_price: i.seller_price, reseller: i.reseller ?? null, our_fee: i.our_fee ?? { rule: 'wall' } });
|
|
31
|
+
}
|
|
32
|
+
/** The reseller's leg of a quote: what the tenant earns on this sale (0 when its markup is 0). Pure. */
|
|
33
|
+
export function markupLeg(q) {
|
|
34
|
+
const leg = q.legs.find((l) => l.leg === 'reseller_markup');
|
|
35
|
+
const units = BigInt(leg?.units ?? '0');
|
|
36
|
+
const list = BigInt(q.list_units);
|
|
37
|
+
return { units, tenant: leg?.to ?? null, bps_of_list: list > 0n ? Number((units * 10000n) / list) : 0 };
|
|
38
|
+
}
|
|
39
|
+
/** The legs of a quote by name, summed: our_fee · venue_fee · seller_share · reseller_markup. Pure. */
|
|
40
|
+
export function legsByName(q) {
|
|
41
|
+
const of = (leg) => q.legs.filter((l) => l.leg === leg).reduce((a, l) => a + BigInt(l.units), 0n);
|
|
42
|
+
return { our_fee: of('our_fee'), venue_fee: of('venue_fee'), seller_share: of('seller_share'), reseller_markup: of('reseller_markup') };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a reseller child key is, in the layer's own words: the terms a reseller agrees to when it mints one. Pure data; the
|
|
46
|
+
* markup policy is checked by the layer when the key is minted (`POST /v1/tenant/keys { action: 'child' }`).
|
|
47
|
+
*/
|
|
48
|
+
export function childKeyTerms(markup = { '*': 0 }) {
|
|
49
|
+
const def = markup['*'] ?? 0;
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
rail: 'balance', payment_method: 'reseller-child', markup,
|
|
52
|
+
says: Object.freeze([
|
|
53
|
+
'the child pays from the reseller’s balance: the wholesale (the list price) leaves the reseller’s balance for the layer’s vault',
|
|
54
|
+
`the child owes the reseller the list price plus its markup (${def} bps by default${Object.keys(markup).filter((k) => k !== '*').length ? ', per product where set' : ''}); the markup is the reseller’s own leg (reseller_markup), never part of the layer’s fee`,
|
|
55
|
+
'the markup is booked by the layer as a ledger row; how a markup above 0 bps is paid out (netted against the wholesale balance, or sent at period close) is the owner’s open decision (register step reseller-markup-payout)',
|
|
56
|
+
'a child’s free grades a day are counted per child and per visitor address, never per user',
|
|
57
|
+
]),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** The unsigned plan of minting a child key: the call the reseller sends with its own key. Nothing is sent here. Pure. */
|
|
61
|
+
export function childKeyPlan(markup = { '*': 0 }, label = null) {
|
|
62
|
+
for (const [k, v] of Object.entries(markup)) {
|
|
63
|
+
if (!Number.isInteger(v) || v < 0 || v > 100_000)
|
|
64
|
+
throw new RangeError(`markup_bps.${k} must be a whole number of basis points between 0 and 100000`);
|
|
65
|
+
}
|
|
66
|
+
return { method: 'POST', path: '/tenant/keys', body: { action: 'child', markup_bps: markup, ...(label ? { label } : {}) }, signer: 'the reseller tenant (its own key, X-API-Key)' };
|
|
67
|
+
}
|
|
68
|
+
/** The unsigned plan of a child topping up its balance through the layer's subscribe door (the x402 quote comes back as a 402). Pure. */
|
|
69
|
+
export function subscribePlan(o = { usdc: 1 }) {
|
|
70
|
+
if (!(Number.isFinite(o.usdc) && o.usdc > 0))
|
|
71
|
+
throw new RangeError('usdc must be a positive amount');
|
|
72
|
+
return { method: 'POST', path: '/access/subscribe', body: { chainId: 8453, usdc: o.usdc, create_key: o.create_key ?? false },
|
|
73
|
+
says: 'the layer answers with the x402 quote (a 402: accepts[] with the vault as payTo on Base); the child signs the USDC transferWithAuthorization with its own wallet; the balance is credited to the key' };
|
|
74
|
+
}
|
|
75
|
+
export const SALE_ID_RE = /^rs_[0-9a-z]+_[0-9a-f]{10}$/i;
|
|
76
|
+
/** Read one resale sale by its id through the transport (reads only; a bad id is refused before any call). */
|
|
77
|
+
export async function readSale(t, saleId) {
|
|
78
|
+
if (!SALE_ID_RE.test(saleId))
|
|
79
|
+
throw new RangeError('a sale id is rs_<stamp>_<10 hex> (the `sale.id` of a class wall’s 200 answer)');
|
|
80
|
+
const r = await t.fetch(`${t.base}/resale/sales/${saleId}`, { method: 'GET', headers: { accept: 'application/json', ...(t.apiKey ? { 'x-api-key': t.apiKey } : {}) } });
|
|
81
|
+
const j = (await r.json().catch(() => null));
|
|
82
|
+
if (!r.ok || !j?.ok)
|
|
83
|
+
throw new Error(j?.error ?? `GET /resale/sales/${saleId} → ${r.status}`);
|
|
84
|
+
return j;
|
|
85
|
+
}
|
|
86
|
+
/** The reseller's own view (GET /v1/access/reseller): its children, their calls, what it paid at list, what they owe, the margin. */
|
|
87
|
+
export async function readResellerView(t) {
|
|
88
|
+
const r = await t.fetch(`${t.base}/access/reseller`, { method: 'GET', headers: { accept: 'application/json', ...(t.apiKey ? { 'x-api-key': t.apiKey } : {}) } });
|
|
89
|
+
const j = (await r.json().catch(() => null));
|
|
90
|
+
if (!r.ok || !j?.ok)
|
|
91
|
+
throw new Error(j?.error ?? `GET /access/reseller → ${r.status}${j?.code ? ` (${j.code})` : ''}`);
|
|
92
|
+
return j;
|
|
93
|
+
}
|
|
94
|
+
// ── quoteSale and the attested resale steps (0.7.0) ──────────────────────────────────────────────────────────────────
|
|
95
|
+
import { attest, attestKeccak } from '../attest/index.js';
|
|
96
|
+
/** quoteSale over the Base venues: the layer's own quoteSale, refused outside Base (the same as quoteBase). Pure. */
|
|
97
|
+
export const quoteSale = quoteBase;
|
|
98
|
+
const STEP_VERDICT = { delivered: 1, settled: 1, refunded: 3 };
|
|
99
|
+
const quoteBody = (q) => JSON.parse(JSON.stringify(q, (_k, v) => (typeof v === 'bigint' ? v.toString() : v)));
|
|
100
|
+
/**
|
|
101
|
+
* The attested mark, the decision-log attestation and (for delivered, settled, refunded) the stamp of one resale step,
|
|
102
|
+
* Base by default (`networks: 'none'` opts out). The subject is the sale key on the contract the step pays through (the
|
|
103
|
+
* wall's payTo, a venue escrow) or the zero address when there is none; the digest is keccak256 of the step's canonical body.
|
|
104
|
+
*/
|
|
105
|
+
export function attestSale(a, opts = {}) {
|
|
106
|
+
if (!a.saleKey)
|
|
107
|
+
throw new RangeError('a sale key names the sale');
|
|
108
|
+
return attest({
|
|
109
|
+
kind: `resale.${a.step}`,
|
|
110
|
+
subject: { chainId: 8453, contract: a.contract ?? `0x${'0'.repeat(40)}`, jobId: attestKeccak(a.saleKey) },
|
|
111
|
+
body: { v: 'resale.step.v1', sale: a.saleKey, step: a.step, quote: a.quote ? quoteBody(a.quote) : null, tx: a.tx ?? null, extra: a.body ?? null },
|
|
112
|
+
model: `det:resale-${a.step}-v1`,
|
|
113
|
+
verdict: STEP_VERDICT[a.step] ?? null,
|
|
114
|
+
mode: 1,
|
|
115
|
+
}, opts);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resale/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,SAAS,IAAI,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,GAE3H,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAK1G,6HAA6H;AAC7H,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,CAAU,CAAC,CAAC;AAC/H,oHAAoH;AACpH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAA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AAC,CAAC;AAEvH;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,CAA8G,EAAE,IAAI,GAA0B,EAAE;IACzK,IAAI,CAAC,CAAC,CAAC,OAAO;QAAE,MAAM,IAAI,UAAU,CAAC,2BAA2B,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC;QACZ,IAAI,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;QACzG,IAAI,EAAE,EAAE,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE;QACjJ,KAAK,EAAE,cAAc,CAAC,CAAC,IAAI,KAAK;QAChC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI;QACrC,IAAI,EAAE,CAAC;KACR,EAAE,IAAI,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Types of src/resale/payment-scheme.mjs (the byte-identical copy of the coordination layer’s packages/resale/core/payment-scheme.mjs, _ONE_PAYMENT_SCHEME_v1_):
|
|
2
|
+
// ONE payment scheme for every sale the layer makes as seller of record, whatever the venue pair.
|
|
3
|
+
// price_to_buyer = seller_price + our_fee + venue_fee(in) + venue_fee(out) [+ reseller_markup]
|
|
4
|
+
export const RULE: 'ONE_PAYMENT_SCHEME_v1';
|
|
5
|
+
export const SCHEME_ID: 'taifoon.payment.scheme.v1';
|
|
6
|
+
export const FORMULA: string;
|
|
7
|
+
export const BPS: bigint;
|
|
8
|
+
export const OWN_VENUES: readonly string[];
|
|
9
|
+
export type Units = bigint | number | string;
|
|
10
|
+
export type SchemeLegId = 'our_fee' | 'venue_fee' | 'seller_share' | 'reseller_markup' | 'provider' | 'graders' | 'ecosystem';
|
|
11
|
+
export const LEGS: readonly { id: SchemeLegId; ledger_leg: string; account: string; to: string; what: string; sides?: readonly ('in' | 'out')[] }[];
|
|
12
|
+
export const ENDING_LEGS: readonly string[];
|
|
13
|
+
export type FeeRule = { rule: 'wall' } | { rule: 'job_quote'; units: Units } | { rule: 'metered' } | { rule: 'none' };
|
|
14
|
+
export const OUR_FEE: { rules: { wall: { id: 'wall'; door: string; bps: number; min_units: number; rounding: 'ceil'; base: string; never_above: string; code: string }; job_quote: { id: 'job_quote'; door: string; base: string; on_top: true; code: string }; metered: { id: 'metered'; door: string; base: string; legs: readonly string[]; code: string } } };
|
|
15
|
+
/** an entry of the address registry (src/lib/addresses.generated.ts contract(system, chain, name)): a venue's contract is named by reference, never by a literal */
|
|
16
|
+
export type RegistryRef = { system: string; chain: number; name: string };
|
|
17
|
+
export type VenueFeePart = { part: 'platform' | 'evaluator'; bps: number; to: string; to_address: string | null; to_ref: RegistryRef | null; when: 'always' | 'evaluator_set' };
|
|
18
|
+
export type VenueFeeFacts = {
|
|
19
|
+
status: 'read' | 'none'; /** false: a venue the resolver walks that the standard has no adapter for yet */ adapter?: false; taken: 'at_source' | 'from_payment' | null; rounding: 'floor' | 'ceil'; base: string; parts: readonly VenueFeePart[];
|
|
20
|
+
on_refund: { venue_ending: string; venue_ending_why: string; after_paid_ending: string; after_paid_ending_why: string };
|
|
21
|
+
evidence: { contract: RegistryRef | null; chain: number | string | null; name: string; reads: readonly string[]; block: number | null; read_at: string; how: string };
|
|
22
|
+
};
|
|
23
|
+
export const VENUE_FEES: Readonly<Record<string, VenueFeeFacts>>;
|
|
24
|
+
export type VenueFee = { venue: string; base: bigint; total: bigint; net: bigint; parts: { part: string; bps: number | null; units: string; to: string; to_address: string | null; to_ref?: RegistryRef | null }[]; taken: 'at_source' | 'from_payment' | null; rounding: 'floor' | 'ceil' };
|
|
25
|
+
export type FeeOpts = { facts?: Record<string, VenueFeeFacts>; evaluator_set?: boolean; as_read?: { platform_bps?: number | null; evaluator_bps?: number | null } | null };
|
|
26
|
+
export function venueFeeOf(venue: string, base: Units, o?: FeeOpts): VenueFee;
|
|
27
|
+
export function grossUp(venue: string, net: Units, o?: FeeOpts): { venue: string; net: bigint; gross: bigint; fee: VenueFee };
|
|
28
|
+
export function ourFeeOf(fee: FeeRule, base: Units): bigint;
|
|
29
|
+
export function listPriceOf(fee: FeeRule, sellerPrice: Units): bigint;
|
|
30
|
+
export type SchemeLeg = { leg: SchemeLegId | 'refund' | 'loss'; ledger_leg: string; units: string; side: 'in' | 'out' | null; venue: string | null; part: string | null; bps: number | null; to: string | null; to_address: string | null; to_ref: RegistryRef | null; taken: string | null };
|
|
31
|
+
export function sumOf(legs: readonly { units: string }[]): bigint;
|
|
32
|
+
export type Reseller = { tenant: string; markup_bps?: number; markup_units?: Units };
|
|
33
|
+
export type Quote = { ok: true; schema: 'taifoon.payment.quote.v1'; rule: string; formula: string; venue_in: string; venue_out: string; class: string | null; seller_price: string; fee_rule: string;
|
|
34
|
+
list_units: string; out_units: string; net_in_units: string; price_to_buyer: string; legs: SchemeLeg[]; venue_fee: { in: { venue: string; units: string; taken: string | null }; out: { venue: string; units: string; taken: string | null } } } | { ok: false; why: string };
|
|
35
|
+
export function quoteSale(o: { venue_in: string; venue_out: string; class?: string | null; seller_price: Units; reseller?: Reseller | null; our_fee?: FeeRule; evaluator_set_in?: boolean; evaluator_set_out?: boolean; facts?: Record<string, VenueFeeFacts> }): Quote;
|
|
36
|
+
export type Observed = { provider: Units; evaluator?: Units };
|
|
37
|
+
export type PaymentLegs = { ok: true; rule: string; ending: string; venue_in?: string; venue_out?: string; paid_units?: string; net_in_units: string; out_units?: string; legs: SchemeLeg[]; sum_ok: boolean; fee_rule_ok: boolean | null; fees_as: string;
|
|
38
|
+
venue_fee?: { in: { venue: string; units: string; taken: string | null }; out: { venue: string; units: string; taken: string | null } }; venue_fee_on_refund?: string } | { ok: false; why: string };
|
|
39
|
+
export function legsOfPayment(p: { venue_in: string; venue_out: string; paid_units: Units; out_units?: Units; reseller?: Reseller | null; lost_units?: Units; out_direct?: boolean; ending?: 'paid' | 'venue_refund' | 'share_refund'; our_fee?: FeeRule;
|
|
40
|
+
observed?: { in?: Observed | null; out?: Observed | null } | null; as_read_in?: FeeOpts['as_read']; as_read_out?: FeeOpts['as_read']; evaluator_set_in?: boolean; evaluator_set_out?: boolean; facts?: Record<string, VenueFeeFacts> }): PaymentLegs;
|
|
41
|
+
export function pairsOf(adapters: readonly { venue: string; transforms?: Record<string, { state?: string }> }[]): { venue_in: string; venue_out: string }[];
|
|
42
|
+
export function schemeGaps(adapters: readonly { venue: string }[], facts?: Record<string, VenueFeeFacts>): { missing: string[]; extra: string[] };
|
|
43
|
+
export type VenueFeeRow = { venue: string; status: string; adapter?: false; platform_bps: number; evaluator_bps: number; total_bps: number; taken: string | null; rounding: string; to: string | null; on_refund: string; after_paid_ending: string; contract: string | null; contract_ref: RegistryRef | null; chain: number | string | null; block: number | null; net_of_10000: string; gross_for_10000: string };
|
|
44
|
+
export type Resolve = { addressOf?: ((r: RegistryRef) => string) | null };
|
|
45
|
+
export function venueFeeTable(facts?: Record<string, VenueFeeFacts>, o?: Resolve): VenueFeeRow[];
|
|
46
|
+
export function schemeBlock(facts?: Record<string, VenueFeeFacts>, o?: Resolve): Record<string, unknown>;
|