@telaro/sdk 0.1.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/QUICKSTART.md +216 -0
  3. package/README.md +129 -0
  4. package/dist/accounts.d.ts +51 -0
  5. package/dist/accounts.d.ts.map +1 -0
  6. package/dist/accounts.js +169 -0
  7. package/dist/accounts.js.map +1 -0
  8. package/dist/api.d.ts +177 -0
  9. package/dist/api.d.ts.map +1 -0
  10. package/dist/api.js +158 -0
  11. package/dist/api.js.map +1 -0
  12. package/dist/borsh.d.ts +33 -0
  13. package/dist/borsh.d.ts.map +1 -0
  14. package/dist/borsh.js +100 -0
  15. package/dist/borsh.js.map +1 -0
  16. package/dist/client.d.ts +70 -0
  17. package/dist/client.d.ts.map +1 -0
  18. package/dist/client.js +164 -0
  19. package/dist/client.js.map +1 -0
  20. package/dist/constants.d.ts +46 -0
  21. package/dist/constants.d.ts.map +1 -0
  22. package/dist/constants.js +47 -0
  23. package/dist/constants.js.map +1 -0
  24. package/dist/credit.d.ts +61 -0
  25. package/dist/credit.d.ts.map +1 -0
  26. package/dist/credit.js +133 -0
  27. package/dist/credit.js.map +1 -0
  28. package/dist/decimal.d.ts +36 -0
  29. package/dist/decimal.d.ts.map +1 -0
  30. package/dist/decimal.js +87 -0
  31. package/dist/decimal.js.map +1 -0
  32. package/dist/discriminators.d.ts +86 -0
  33. package/dist/discriminators.d.ts.map +1 -0
  34. package/dist/discriminators.js +100 -0
  35. package/dist/discriminators.js.map +1 -0
  36. package/dist/events.d.ts +268 -0
  37. package/dist/events.d.ts.map +1 -0
  38. package/dist/events.js +223 -0
  39. package/dist/events.js.map +1 -0
  40. package/dist/format.d.ts +10 -0
  41. package/dist/format.d.ts.map +1 -0
  42. package/dist/format.js +39 -0
  43. package/dist/format.js.map +1 -0
  44. package/dist/hash.d.ts +9 -0
  45. package/dist/hash.d.ts.map +1 -0
  46. package/dist/hash.js +33 -0
  47. package/dist/hash.js.map +1 -0
  48. package/dist/index.d.ts +17 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +17 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/instructions.d.ts +368 -0
  53. package/dist/instructions.d.ts.map +1 -0
  54. package/dist/instructions.js +841 -0
  55. package/dist/instructions.js.map +1 -0
  56. package/dist/metaplex.d.ts +64 -0
  57. package/dist/metaplex.d.ts.map +1 -0
  58. package/dist/metaplex.js +123 -0
  59. package/dist/metaplex.js.map +1 -0
  60. package/dist/pda.d.ts +35 -0
  61. package/dist/pda.d.ts.map +1 -0
  62. package/dist/pda.js +84 -0
  63. package/dist/pda.js.map +1 -0
  64. package/dist/realtime.d.ts +67 -0
  65. package/dist/realtime.d.ts.map +1 -0
  66. package/dist/realtime.js +112 -0
  67. package/dist/realtime.js.map +1 -0
  68. package/dist/score.d.ts +51 -0
  69. package/dist/score.d.ts.map +1 -0
  70. package/dist/score.js +63 -0
  71. package/dist/score.js.map +1 -0
  72. package/dist/types.d.ts +139 -0
  73. package/dist/types.d.ts.map +1 -0
  74. package/dist/types.js +51 -0
  75. package/dist/types.js.map +1 -0
  76. package/package.json +88 -0
package/dist/client.js ADDED
@@ -0,0 +1,164 @@
1
+ import { Transaction, sendAndConfirmTransaction, } from "@solana/web3.js";
2
+ import { getAssociatedTokenAddress } from "@solana/spl-token";
3
+ import { PROGRAM_ID } from "./constants.js";
4
+ import { hashAction } from "./hash.js";
5
+ import { findAgentPda, findClaimPda } from "./pda.js";
6
+ import { buildArbiterResolveIx, buildArbiterTimeoutIx, buildEscalateClaimIx, buildRecordActionIx, buildRegisterAndBondIxs, buildResolveClaimIx, buildSubmitClaimIx, buildTopUpIx, buildUpdateScoreIx, buildViewBondIx, buildWithdrawBondIx, } from "./instructions.js";
7
+ import { ActionKind, ActionOutcome, ResolveAction, } from "./types.js";
8
+ /**
9
+ * High-level client. Wraps the on-chain instructions for the agent-side flow
10
+ * (register / record_action / top_up / withdraw) and the user-side flow
11
+ * (submit_claim / resolve_claim).
12
+ */
13
+ export class TelaroClient {
14
+ connection;
15
+ signer;
16
+ programId;
17
+ commitment;
18
+ constructor(connection, signer, opts = {}) {
19
+ this.connection = connection;
20
+ this.signer = signer;
21
+ this.programId = opts.programId ?? PROGRAM_ID;
22
+ this.commitment = opts.commitment ?? "confirmed";
23
+ }
24
+ get controller() {
25
+ return this.signer.publicKey;
26
+ }
27
+ agentPda(controller = this.controller) {
28
+ return findAgentPda(controller, this.programId)[0];
29
+ }
30
+ async registerAgent(input) {
31
+ const ata = await getAssociatedTokenAddress(input.bondMint, this.controller);
32
+ const [initIx, bondIx] = buildRegisterAndBondIxs({
33
+ controller: this.controller,
34
+ controllerBondAta: ata,
35
+ framework: input.framework,
36
+ metadataUri: input.metadataUri,
37
+ scorer: input.scorer,
38
+ bondMint: input.bondMint,
39
+ bondAmount: input.bondAmount,
40
+ }, this.programId);
41
+ return this.send(initIx, bondIx);
42
+ }
43
+ async recordAction(input) {
44
+ const hash = input.actionHash ?? hashAction(input.payload ?? {});
45
+ const ix = buildRecordActionIx(this.controller, {
46
+ actionHash: hash,
47
+ kind: input.kind,
48
+ outcome: input.outcome,
49
+ valueAtomic: input.valueAtomic,
50
+ }, this.programId);
51
+ return this.send(ix);
52
+ }
53
+ async topUpBond(args) {
54
+ const ata = await getAssociatedTokenAddress(args.bondMint, this.controller);
55
+ const ix = buildTopUpIx({
56
+ agent: args.agent,
57
+ bondMint: args.bondMint,
58
+ payer: this.controller,
59
+ payerBondAta: ata,
60
+ }, args.amount, this.programId);
61
+ return this.send(ix);
62
+ }
63
+ async submitClaim(input, bondMint) {
64
+ const ata = await getAssociatedTokenAddress(bondMint, this.controller);
65
+ const ix = buildSubmitClaimIx({
66
+ agent: input.agent,
67
+ bondMint,
68
+ claimer: this.controller,
69
+ claimerBondAta: ata,
70
+ }, {
71
+ actionHash: input.actionHash,
72
+ claimedAmount: input.claimedAmount,
73
+ evidenceUri: input.evidenceUri,
74
+ }, this.programId);
75
+ return this.send(ix);
76
+ }
77
+ async resolveClaim(args) {
78
+ const [claim] = findClaimPda(args.agent, args.actionHash, args.claimer, this.programId);
79
+ const claimerAta = await getAssociatedTokenAddress(args.bondMint, args.claimer);
80
+ const ix = buildResolveClaimIx({
81
+ agent: args.agent,
82
+ claim,
83
+ bondMint: args.bondMint,
84
+ claimerBondAta: claimerAta,
85
+ signer: this.controller,
86
+ }, args.action, this.programId);
87
+ return this.send(ix);
88
+ }
89
+ /** v0.3: User escalates a rejected claim within 24h. Posts an
90
+ * additional 5% deposit. */
91
+ async escalateClaim(args) {
92
+ const [claim] = findClaimPda(args.agent, args.actionHash, this.controller, this.programId);
93
+ const ata = await getAssociatedTokenAddress(args.bondMint, this.controller);
94
+ const ix = buildEscalateClaimIx({
95
+ claim,
96
+ agent: args.agent,
97
+ bondMint: args.bondMint,
98
+ claimerBondAta: ata,
99
+ claimer: this.controller,
100
+ }, this.programId);
101
+ return this.send(ix);
102
+ }
103
+ /** v0.3: Protocol arbiter rules ForUser (0) or ForBuilder (1). Caller
104
+ * must be the configured PROTOCOL_ARBITER pubkey. */
105
+ async arbiterResolve(args) {
106
+ const [claim] = findClaimPda(args.agent, args.actionHash, args.claimer, this.programId);
107
+ const claimerAta = await getAssociatedTokenAddress(args.bondMint, args.claimer);
108
+ const ix = buildArbiterResolveIx({
109
+ claim,
110
+ agent: args.agent,
111
+ bondMint: args.bondMint,
112
+ claimerBondAta: claimerAta,
113
+ arbiter: this.controller,
114
+ }, args.ruling, this.programId);
115
+ return this.send(ix);
116
+ }
117
+ /** v0.3: Anyone can crank after 7d arbiter window. Defaults ForUser. */
118
+ async arbiterTimeout(args) {
119
+ const [claim] = findClaimPda(args.agent, args.actionHash, args.claimer, this.programId);
120
+ const claimerAta = await getAssociatedTokenAddress(args.bondMint, args.claimer);
121
+ const ix = buildArbiterTimeoutIx({
122
+ claim,
123
+ agent: args.agent,
124
+ bondMint: args.bondMint,
125
+ claimerBondAta: claimerAta,
126
+ cranker: this.controller,
127
+ }, this.programId);
128
+ return this.send(ix);
129
+ }
130
+ async updateScore(agent, newScore, bondRatioBps) {
131
+ const ix = buildUpdateScoreIx(agent, this.controller, { newScore, bondRatioBps }, this.programId);
132
+ return this.send(ix);
133
+ }
134
+ async withdrawBond(args) {
135
+ const ata = await getAssociatedTokenAddress(args.bondMint, this.controller);
136
+ const ix = buildWithdrawBondIx({
137
+ agent: args.agent,
138
+ bondMint: args.bondMint,
139
+ controller: this.controller,
140
+ controllerBondAta: ata,
141
+ }, args.amount, this.programId);
142
+ return this.send(ix);
143
+ }
144
+ async previewViewBond(agent, minBond, minScore) {
145
+ const ix = buildViewBondIx(agent, { minBond, minScore }, this.programId);
146
+ try {
147
+ const tx = new Transaction().add(ix);
148
+ const { blockhash } = await this.connection.getLatestBlockhash();
149
+ tx.recentBlockhash = blockhash;
150
+ tx.feePayer = this.controller;
151
+ const sim = await this.connection.simulateTransaction(tx);
152
+ return sim.value.err === null;
153
+ }
154
+ catch {
155
+ return false;
156
+ }
157
+ }
158
+ async send(...ixs) {
159
+ const tx = new Transaction().add(...ixs);
160
+ return sendAndConfirmTransaction(this.connection, tx, [this.signer], { commitment: this.commitment });
161
+ }
162
+ }
163
+ export { ActionKind, ActionOutcome, ResolveAction };
164
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,yBAAyB,GAE1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAEL,qBAAqB,EACrB,qBAAqB,EACrB,oBA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,CAAC,kBAAkB,EAAE,CAAC;YACjE,EAAE,CAAC,eAAe,GAAG,SAAS,CAAC;YAC/B,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;YAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;YAC1D,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,IAAI,CAAC,GAAG,GAAuD;QAC3E,MAAM,EAAE,GAAG,IAAI,WAAW,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;QACzC,OAAO,yBAAyB,CAC9B,IAAI,CAAC,UAAU,EACf,EAAE,EACF,CAAC,IAAI,CAAC,MAAiB,CAAC,EACxB,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAChC,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ export declare const PROGRAM_ID: PublicKey;
3
+ /** USDC has 6 decimals; bond floor = 1 USDC. */
4
+ export declare const MIN_BOND_USDC = 1000000n;
5
+ /** 5% of claimed amount, in basis points. */
6
+ export declare const CLAIM_DEPOSIT_BPS = 500n;
7
+ /** 1% — bond fraction moved to treasury when builder accepts a claim.
8
+ * Drops the ROI of self-claim sock-puppet attacks. */
9
+ export declare const ACCEPT_COST_BPS = 100n;
10
+ /** 1% — bond fraction moved to treasury when builder rejects a claim.
11
+ * Makes spam-rejecting expensive (50 rejects ≈ 50% of bond). */
12
+ export declare const REJECTION_COST_BPS = 100n;
13
+ /** Total bps denominator (10_000 = 100%). */
14
+ export declare const TOTAL_BPS = 10000n;
15
+ /** 24h escalation window after a claim is rejected. */
16
+ export declare const ESCALATION_WINDOW_SECONDS: number;
17
+ /** 7d arbiter window after a claim is escalated. */
18
+ export declare const ARBITER_WINDOW_SECONDS: number;
19
+ /** 5% additional deposit posted when escalating. Refunded if arbiter
20
+ * rules ForUser, lost to treasury if ForBuilder. */
21
+ export declare const ESCALATION_DEPOSIT_BPS = 500n;
22
+ /** 100% — bond → user penalty (in addition to claimed_amount) when
23
+ * arbiter rules ForUser. Capped at current_bond. */
24
+ export declare const ARBITER_PENALTY_BPS = 10000n;
25
+ /** 2% — arbiter fee (bond → treasury) on ForUser ruling. Halved if
26
+ * ruling time exceeds ARBITER_SPEED_BONUS_SECONDS. */
27
+ export declare const ARBITER_FEE_BPS = 200n;
28
+ /** 24h — full arbiter fee window. Beyond this, the fee halves to
29
+ * incentivize fast turnaround. */
30
+ export declare const ARBITER_SPEED_BONUS_SECONDS: number;
31
+ /** 5x — max ratio of value_handled_30d to current_bond enforced by
32
+ * view_bond CPI. Prevents bond rotation attacks. */
33
+ export declare const MAX_LEVERAGE_RATIO = 5n;
34
+ /** Protocol arbiter pubkey for v0.3 (single-key). v1 → Squads multisig. */
35
+ export declare const PROTOCOL_ARBITER: PublicKey;
36
+ /** 7 days. */
37
+ export declare const CLAIM_WINDOW_SECONDS: number;
38
+ /** 30 days from last action before bond can be withdrawn. */
39
+ export declare const WITHDRAWAL_COOLDOWN_SECONDS: number;
40
+ export declare const MAX_SCORE = 1000;
41
+ export declare const BASE_SCORE = 500;
42
+ export declare const RING_CAPACITY = 128;
43
+ /** 10% — liquid reserve floor enforced by `route_to_marginfi`. Matches
44
+ * `programs/telaro/src/state.rs::RESERVE_BUFFER_BPS`. */
45
+ export declare const RESERVE_BUFFER_BPS = 1000n;
46
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,UAAU,WAEtB,CAAC;AAEF,gDAAgD;AAChD,eAAO,MAAM,aAAa,WAAa,CAAC;AAExC,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;uDACuD;AACvD,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC;iEACiE;AACjE,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,6CAA6C;AAC7C,eAAO,MAAM,SAAS,SAAU,CAAC;AAIjC,uDAAuD;AACvD,eAAO,MAAM,yBAAyB,QAAe,CAAC;AAEtD,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,QAAmB,CAAC;AAEvD;qDACqD;AACrD,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C;qDACqD;AACrD,eAAO,MAAM,mBAAmB,SAAU,CAAC;AAE3C;uDACuD;AACvD,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC;mCACmC;AACnC,eAAO,MAAM,2BAA2B,QAAe,CAAC;AAExD;qDACqD;AACrD,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,WAE5B,CAAC;AAEF,cAAc;AACd,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAErD,6DAA6D;AAC7D,eAAO,MAAM,2BAA2B,QAAoB,CAAC;AAE7D,eAAO,MAAM,SAAS,OAAO,CAAC;AAC9B,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC;0DAC0D;AAC1D,eAAO,MAAM,kBAAkB,QAAQ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ export const PROGRAM_ID = new PublicKey("3DUrvVWEziYLtEbiDtfxqh1ioXRFX6DNvV4iTsGed2rs");
3
+ /** USDC has 6 decimals; bond floor = 1 USDC. */
4
+ export const MIN_BOND_USDC = 1000000n;
5
+ /** 5% of claimed amount, in basis points. */
6
+ export const CLAIM_DEPOSIT_BPS = 500n;
7
+ /** 1% — bond fraction moved to treasury when builder accepts a claim.
8
+ * Drops the ROI of self-claim sock-puppet attacks. */
9
+ export const ACCEPT_COST_BPS = 100n;
10
+ /** 1% — bond fraction moved to treasury when builder rejects a claim.
11
+ * Makes spam-rejecting expensive (50 rejects ≈ 50% of bond). */
12
+ export const REJECTION_COST_BPS = 100n;
13
+ /** Total bps denominator (10_000 = 100%). */
14
+ export const TOTAL_BPS = 10000n;
15
+ /* v0.3: arbiter escalation flow */
16
+ /** 24h escalation window after a claim is rejected. */
17
+ export const ESCALATION_WINDOW_SECONDS = 24 * 60 * 60;
18
+ /** 7d arbiter window after a claim is escalated. */
19
+ export const ARBITER_WINDOW_SECONDS = 7 * 24 * 60 * 60;
20
+ /** 5% additional deposit posted when escalating. Refunded if arbiter
21
+ * rules ForUser, lost to treasury if ForBuilder. */
22
+ export const ESCALATION_DEPOSIT_BPS = 500n;
23
+ /** 100% — bond → user penalty (in addition to claimed_amount) when
24
+ * arbiter rules ForUser. Capped at current_bond. */
25
+ export const ARBITER_PENALTY_BPS = 10000n;
26
+ /** 2% — arbiter fee (bond → treasury) on ForUser ruling. Halved if
27
+ * ruling time exceeds ARBITER_SPEED_BONUS_SECONDS. */
28
+ export const ARBITER_FEE_BPS = 200n;
29
+ /** 24h — full arbiter fee window. Beyond this, the fee halves to
30
+ * incentivize fast turnaround. */
31
+ export const ARBITER_SPEED_BONUS_SECONDS = 24 * 60 * 60;
32
+ /** 5x — max ratio of value_handled_30d to current_bond enforced by
33
+ * view_bond CPI. Prevents bond rotation attacks. */
34
+ export const MAX_LEVERAGE_RATIO = 5n;
35
+ /** Protocol arbiter pubkey for v0.3 (single-key). v1 → Squads multisig. */
36
+ export const PROTOCOL_ARBITER = new PublicKey("CWz9b8g4h78ytQnd4gEU9qk4fP1wtQjfa7L838HtKNps");
37
+ /** 7 days. */
38
+ export const CLAIM_WINDOW_SECONDS = 7 * 24 * 60 * 60;
39
+ /** 30 days from last action before bond can be withdrawn. */
40
+ export const WITHDRAWAL_COOLDOWN_SECONDS = 30 * 24 * 60 * 60;
41
+ export const MAX_SCORE = 1000;
42
+ export const BASE_SCORE = 500;
43
+ export const RING_CAPACITY = 128;
44
+ /** 10% — liquid reserve floor enforced by `route_to_marginfi`. Matches
45
+ * `programs/telaro/src/state.rs::RESERVE_BUFFER_BPS`. */
46
+ export const RESERVE_BUFFER_BPS = 1000n;
47
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,CACrC,8CAA8C,CAC/C,CAAC;AAEF,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,QAAU,CAAC;AAExC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC;uDACuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC;iEACiE;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,MAAO,CAAC;AAEjC,mCAAmC;AAEnC,uDAAuD;AACvD,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEtD,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEvD;qDACqD;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;qDACqD;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAO,CAAC;AAE3C;uDACuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC;mCACmC;AACnC,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAExD;qDACqD;AACrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAC3C,8CAA8C,CAC/C,CAAC;AAEF,cAAc;AACd,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAErD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAE7D,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAE9B,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAEjC;0DAC0D;AAC1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Credit module — score → loan-to-value (LTV) and under-collateralization
3
+ * parameters for bonded agents.
4
+ *
5
+ * The Telaro trust score (0–1000) is more than reputation: it's a credit
6
+ * grade. Higher score = more trust = the agent can post less than 100%
7
+ * of their slashable bond and borrow the rest from the underwriter pool
8
+ * (Phase D credit market).
9
+ *
10
+ * Mechanic in plain English:
11
+ * - Score ≤ 600 → must post 100% bond themselves (no credit line)
12
+ * - Score 700 → only 80% required, 20% credit line from the pool
13
+ * - Score 800 → 50% required, 50% credit
14
+ * - Score 900 → 30% required, 70% credit
15
+ * - Score 1000 → 10% required, 90% credit
16
+ *
17
+ * Interest rate: lower score → higher rate (risk pricing). Default tier
18
+ * (`baseRateBps`) is 800 bps (8% APY) at the floor (700) and falls to
19
+ * 300 bps (3%) at the ceiling (1000).
20
+ *
21
+ * No on-chain code yet — this module is the reference policy that the
22
+ * `request_credit` ix (planned) will mirror, just like `computeScore`
23
+ * mirrors what `update_score` will compute on-chain at v1.
24
+ */
25
+ export interface CreditTerms {
26
+ /** Eligible for under-collateralized credit at all? */
27
+ eligible: boolean;
28
+ /** Required own-bond as a fraction of the slashable amount (0–1). */
29
+ requiredCollateralRatio: number;
30
+ /** Credit line as a fraction of the slashable amount (0–1). */
31
+ creditLineRatio: number;
32
+ /** Required own-bond in basis points (e.g. 5_000 = 50%). */
33
+ requiredCollateralBps: number;
34
+ /** Credit line ratio in basis points. */
35
+ creditLineBps: number;
36
+ /** Annual interest rate on the credit portion, in basis points (8% = 800). */
37
+ interestRateBps: number;
38
+ /** Human-readable tier label for UI. */
39
+ tier: CreditTier;
40
+ /** How many score points to the next tier (0 if maxed). */
41
+ pointsToNextTier: number;
42
+ }
43
+ export type CreditTier = "no-credit" | "starter" | "standard" | "premium" | "elite";
44
+ /** Map a score (0–1000) to credit terms. */
45
+ export declare function creditTermsForScore(score: number): CreditTerms;
46
+ /**
47
+ * Convenience: given an agent's score and the slash-coverage they want
48
+ * to maintain, compute (a) own-bond they must post and (b) how much
49
+ * credit they'd draw from the pool. Pure math, no on-chain calls.
50
+ *
51
+ * @param totalCoverageAtomic Slashable amount the agent wants the pool
52
+ * to vouch for, in atomic units (e.g. USDC 6dp).
53
+ */
54
+ export declare function splitCoverage(score: number, totalCoverageAtomic: bigint): {
55
+ ownBondAtomic: bigint;
56
+ creditAtomic: bigint;
57
+ terms: CreditTerms;
58
+ };
59
+ /** Human-friendly label used by UI. */
60
+ export declare function creditTierLabel(tier: CreditTier): string;
61
+ //# sourceMappingURL=credit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit.d.ts","sourceRoot":"","sources":["../src/credit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,QAAQ,EAAE,OAAO,CAAC;IAClB,qEAAqE;IACrE,uBAAuB,EAAE,MAAM,CAAC;IAChC,+DAA+D;IAC/D,eAAe,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yCAAyC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,EAAE,MAAM,CAAC;IACxB,wCAAwC;IACxC,IAAI,EAAE,UAAU,CAAC;IACjB,2DAA2D;IAC3D,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,UAAU,GAClB,WAAW,GACX,SAAS,GACT,UAAU,GACV,SAAS,GACT,OAAO,CAAC;AA+DZ,4CAA4C;AAC5C,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAuC9D;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,MAAM,GAC1B;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAMrE;AAED,uCAAuC;AACvC,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAQxD"}
package/dist/credit.js ADDED
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Credit module — score → loan-to-value (LTV) and under-collateralization
3
+ * parameters for bonded agents.
4
+ *
5
+ * The Telaro trust score (0–1000) is more than reputation: it's a credit
6
+ * grade. Higher score = more trust = the agent can post less than 100%
7
+ * of their slashable bond and borrow the rest from the underwriter pool
8
+ * (Phase D credit market).
9
+ *
10
+ * Mechanic in plain English:
11
+ * - Score ≤ 600 → must post 100% bond themselves (no credit line)
12
+ * - Score 700 → only 80% required, 20% credit line from the pool
13
+ * - Score 800 → 50% required, 50% credit
14
+ * - Score 900 → 30% required, 70% credit
15
+ * - Score 1000 → 10% required, 90% credit
16
+ *
17
+ * Interest rate: lower score → higher rate (risk pricing). Default tier
18
+ * (`baseRateBps`) is 800 bps (8% APY) at the floor (700) and falls to
19
+ * 300 bps (3%) at the ceiling (1000).
20
+ *
21
+ * No on-chain code yet — this module is the reference policy that the
22
+ * `request_credit` ix (planned) will mirror, just like `computeScore`
23
+ * mirrors what `update_score` will compute on-chain at v1.
24
+ */
25
+ const FULL_BPS = 10_000;
26
+ const CREDIT_FLOOR_SCORE = 700;
27
+ const CREDIT_CEILING_SCORE = 1000;
28
+ /**
29
+ * Bracket table — required collateral % and interest rate are LINEARLY
30
+ * interpolated within each bracket so a score of 850 falls between 800
31
+ * (50%, 6%) and 900 (30%, 4%) at exactly 40%, 5%.
32
+ */
33
+ const BRACKETS = [
34
+ {
35
+ tier: "no-credit",
36
+ minScore: 0,
37
+ requiredCollateralBps: FULL_BPS,
38
+ requiredCollateralBpsTop: FULL_BPS,
39
+ interestRateBps: 0,
40
+ interestRateBpsTop: 0,
41
+ },
42
+ {
43
+ tier: "starter",
44
+ minScore: 700,
45
+ requiredCollateralBps: 8_000, // 80%
46
+ requiredCollateralBpsTop: 7_000,
47
+ interestRateBps: 800, // 8% APY
48
+ interestRateBpsTop: 700,
49
+ },
50
+ {
51
+ tier: "standard",
52
+ minScore: 750,
53
+ requiredCollateralBps: 7_000,
54
+ requiredCollateralBpsTop: 5_500,
55
+ interestRateBps: 700,
56
+ interestRateBpsTop: 600,
57
+ },
58
+ {
59
+ tier: "premium",
60
+ minScore: 800,
61
+ requiredCollateralBps: 5_000, // 50%
62
+ requiredCollateralBpsTop: 3_000,
63
+ interestRateBps: 600,
64
+ interestRateBpsTop: 400,
65
+ },
66
+ {
67
+ tier: "elite",
68
+ minScore: 900,
69
+ requiredCollateralBps: 3_000, // 30%
70
+ requiredCollateralBpsTop: 1_000, // 10%
71
+ interestRateBps: 400,
72
+ interestRateBpsTop: 300,
73
+ },
74
+ ];
75
+ /** Map a score (0–1000) to credit terms. */
76
+ export function creditTermsForScore(score) {
77
+ const clamped = Math.max(0, Math.min(CREDIT_CEILING_SCORE, Math.round(score)));
78
+ // Find the bracket — the highest one whose minScore ≤ clamped.
79
+ let bracket = BRACKETS[0];
80
+ for (const b of BRACKETS) {
81
+ if (clamped >= b.minScore)
82
+ bracket = b;
83
+ else
84
+ break;
85
+ }
86
+ // Determine the upper edge of this bracket so we can interpolate.
87
+ const idx = BRACKETS.indexOf(bracket);
88
+ const next = BRACKETS[idx + 1];
89
+ const upperScore = next ? next.minScore : CREDIT_CEILING_SCORE;
90
+ const lowerScore = bracket.minScore;
91
+ const span = upperScore - lowerScore;
92
+ const t = span === 0 ? 0 : (clamped - lowerScore) / span;
93
+ const requiredCollateralBps = Math.round(bracket.requiredCollateralBps + (bracket.requiredCollateralBpsTop - bracket.requiredCollateralBps) * t);
94
+ const interestRateBps = Math.round(bracket.interestRateBps + (bracket.interestRateBpsTop - bracket.interestRateBps) * t);
95
+ const creditLineBps = FULL_BPS - requiredCollateralBps;
96
+ const eligible = clamped >= CREDIT_FLOOR_SCORE;
97
+ const pointsToNextTier = next ? Math.max(0, next.minScore - clamped) : 0;
98
+ return {
99
+ eligible,
100
+ requiredCollateralRatio: requiredCollateralBps / FULL_BPS,
101
+ creditLineRatio: creditLineBps / FULL_BPS,
102
+ requiredCollateralBps,
103
+ creditLineBps,
104
+ interestRateBps,
105
+ tier: bracket.tier,
106
+ pointsToNextTier,
107
+ };
108
+ }
109
+ /**
110
+ * Convenience: given an agent's score and the slash-coverage they want
111
+ * to maintain, compute (a) own-bond they must post and (b) how much
112
+ * credit they'd draw from the pool. Pure math, no on-chain calls.
113
+ *
114
+ * @param totalCoverageAtomic Slashable amount the agent wants the pool
115
+ * to vouch for, in atomic units (e.g. USDC 6dp).
116
+ */
117
+ export function splitCoverage(score, totalCoverageAtomic) {
118
+ const terms = creditTermsForScore(score);
119
+ const ownBondAtomic = (totalCoverageAtomic * BigInt(terms.requiredCollateralBps)) / BigInt(FULL_BPS);
120
+ const creditAtomic = totalCoverageAtomic - ownBondAtomic;
121
+ return { ownBondAtomic, creditAtomic, terms };
122
+ }
123
+ /** Human-friendly label used by UI. */
124
+ export function creditTierLabel(tier) {
125
+ return {
126
+ "no-credit": "No credit",
127
+ starter: "Starter",
128
+ standard: "Standard",
129
+ premium: "Premium",
130
+ elite: "Elite",
131
+ }[tier];
132
+ }
133
+ //# sourceMappingURL=credit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit.js","sourceRoot":"","sources":["../src/credit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAyClC;;;;GAIG;AACH,MAAM,QAAQ,GAAkB;IAC9B;QACE,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,CAAC;QACX,qBAAqB,EAAE,QAAQ;QAC/B,wBAAwB,EAAE,QAAQ;QAClC,eAAe,EAAE,CAAC;QAClB,kBAAkB,EAAE,CAAC;KACtB;IACD;QACE,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,GAAG;QACb,qBAAqB,EAAE,KAAK,EAAE,MAAM;QACpC,wBAAwB,EAAE,KAAK;QAC/B,eAAe,EAAE,GAAG,EAAE,SAAS;QAC/B,kBAAkB,EAAE,GAAG;KACxB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,GAAG;QACb,qBAAqB,EAAE,KAAK;QAC5B,wBAAwB,EAAE,KAAK;QAC/B,eAAe,EAAE,GAAG;QACpB,kBAAkB,EAAE,GAAG;KACxB;IACD;QACE,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,GAAG;QACb,qBAAqB,EAAE,KAAK,EAAE,MAAM;QACpC,wBAAwB,EAAE,KAAK;QAC/B,eAAe,EAAE,GAAG;QACpB,kBAAkB,EAAE,GAAG;KACxB;IACD;QACE,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,GAAG;QACb,qBAAqB,EAAE,KAAK,EAAE,MAAM;QAC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+ * USDC (and most SPL tokens we touch) are 6-decimal. Naive
5
+ * `Math.floor(human * 1_000_000)` rounds wrong on common values:
6
+ *
7
+ * 0.095129 * 1_000_000 = 95128.99999999999 → floor = 95128 (off-by-one)
8
+ *
9
+ * These helpers parse / format via integer string ops so the round-trip
10
+ * is exact: `atomicFromDecimal("0.095129", 6) === 95129n`.
11
+ *
12
+ * If the input has more decimal places than `decimals`, extra digits
13
+ * are TRUNCATED (toward zero) — never rounded up. That matches the
14
+ * Math.floor behavior callers expect when computing transfer amounts.
15
+ */
16
+ /**
17
+ * Parse a decimal string into atomic units (bigint), no float math.
18
+ *
19
+ * Accepts: `"0"`, `"0.123"`, `"-0.5"`, `"1_000"` (underscores stripped).
20
+ * Throws on garbage input ("abc", "1.2.3").
21
+ */
22
+ export declare function atomicFromDecimal(value: string | number, decimals: number): bigint;
23
+ /**
24
+ * Format a bigint atomic value as a decimal string. Trailing zeros
25
+ * removed unless `keepTrailingZeros: true`. Always uses `.` separator
26
+ * regardless of locale.
27
+ */
28
+ export declare function decimalFromAtomic(atomic: bigint, decimals: number, opts?: {
29
+ keepTrailingZeros?: boolean;
30
+ }): string;
31
+ /** Sugar — USDC is 6 decimals. */
32
+ export declare const usdcAtomic: (v: string | number) => bigint;
33
+ export declare const usdcDecimal: (a: bigint, opts?: {
34
+ keepTrailingZeros?: boolean;
35
+ }) => string;
36
+ //# sourceMappingURL=decimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../src/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA2BlF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,MAAM,CAiBR;AAED,kCAAkC;AAClC,eAAO,MAAM,UAAU,GAAI,GAAG,MAAM,GAAG,MAAM,WAA4B,CAAC;AAC1E,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,EAAE,OAAO;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,WAC9C,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Lossless decimal ↔ atomic conversion.
3
+ *
4
+ * USDC (and most SPL tokens we touch) are 6-decimal. Naive
5
+ * `Math.floor(human * 1_000_000)` rounds wrong on common values:
6
+ *
7
+ * 0.095129 * 1_000_000 = 95128.99999999999 → floor = 95128 (off-by-one)
8
+ *
9
+ * These helpers parse / format via integer string ops so the round-trip
10
+ * is exact: `atomicFromDecimal("0.095129", 6) === 95129n`.
11
+ *
12
+ * If the input has more decimal places than `decimals`, extra digits
13
+ * are TRUNCATED (toward zero) — never rounded up. That matches the
14
+ * Math.floor behavior callers expect when computing transfer amounts.
15
+ */
16
+ /**
17
+ * Parse a decimal string into atomic units (bigint), no float math.
18
+ *
19
+ * Accepts: `"0"`, `"0.123"`, `"-0.5"`, `"1_000"` (underscores stripped).
20
+ * Throws on garbage input ("abc", "1.2.3").
21
+ */
22
+ export function atomicFromDecimal(value, decimals) {
23
+ if (decimals < 0 || !Number.isInteger(decimals)) {
24
+ throw new RangeError(`decimals must be a non-negative integer; got ${decimals}`);
25
+ }
26
+ let s = typeof value === "number" ? toLosslessString(value) : String(value).trim();
27
+ s = s.replace(/_/g, "");
28
+ if (!s)
29
+ return 0n;
30
+ const negative = s.startsWith("-");
31
+ if (negative)
32
+ s = s.slice(1);
33
+ if (s.startsWith("+"))
34
+ s = s.slice(1);
35
+ if (!/^\d*(?:\.\d*)?$/.test(s)) {
36
+ throw new RangeError(`invalid decimal: ${value}`);
37
+ }
38
+ const dot = s.indexOf(".");
39
+ const whole = dot === -1 ? s : s.slice(0, dot);
40
+ const fracRaw = dot === -1 ? "" : s.slice(dot + 1);
41
+ // Truncate (don't round) excess fractional digits.
42
+ const frac = fracRaw.slice(0, decimals);
43
+ const padded = frac.padEnd(decimals, "0");
44
+ const combined = (whole === "" ? "0" : whole) + padded;
45
+ // Strip leading zeros to satisfy BigInt; "0" is fine.
46
+ const stripped = combined.replace(/^0+(?=\d)/, "");
47
+ const out = BigInt(stripped || "0");
48
+ return negative ? -out : out;
49
+ }
50
+ /**
51
+ * Format a bigint atomic value as a decimal string. Trailing zeros
52
+ * removed unless `keepTrailingZeros: true`. Always uses `.` separator
53
+ * regardless of locale.
54
+ */
55
+ export function decimalFromAtomic(atomic, decimals, opts = {}) {
56
+ if (decimals < 0 || !Number.isInteger(decimals)) {
57
+ throw new RangeError(`decimals must be a non-negative integer; got ${decimals}`);
58
+ }
59
+ const negative = atomic < 0n;
60
+ const abs = negative ? -atomic : atomic;
61
+ let s = abs.toString();
62
+ if (decimals === 0)
63
+ return (negative ? "-" : "") + s;
64
+ s = s.padStart(decimals + 1, "0");
65
+ const cut = s.length - decimals;
66
+ let whole = s.slice(0, cut);
67
+ let frac = s.slice(cut);
68
+ if (!opts.keepTrailingZeros) {
69
+ frac = frac.replace(/0+$/, "");
70
+ }
71
+ whole = whole.replace(/^0+(?=\d)/, "") || "0";
72
+ return (negative ? "-" : "") + (frac ? `${whole}.${frac}` : whole);
73
+ }
74
+ /** Sugar — USDC is 6 decimals. */
75
+ export const usdcAtomic = (v) => atomicFromDecimal(v, 6);
76
+ export const usdcDecimal = (a, opts) => decimalFromAtomic(a, 6, opts);
77
+ /**
78
+ * `Number.toString()` is mostly stable but does collapse to scientific
79
+ * notation past ±1e21. We only deal with USDC ≤ 1e9, so the simple
80
+ * conversion is sufficient. Still, guard against NaN / Infinity.
81
+ */
82
+ function toLosslessString(n) {
83
+ if (!Number.isFinite(n))
84
+ throw new RangeError(`non-finite number: ${n}`);
85
+ return n.toString();
86
+ }
87
+ //# sourceMappingURL=decimal.js.map
@@ -0,0 +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