@andrewkimjoseph/celina-sdk 0.2.11 → 0.3.1
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 +3 -0
- package/build/abis/self-registry.d.ts +194 -0
- package/build/abis/self-registry.js +120 -0
- package/build/abis/self-registry.js.map +1 -0
- package/build/analytics/amplitude.d.ts +5 -0
- package/build/analytics/amplitude.js +56 -0
- package/build/analytics/amplitude.js.map +1 -0
- package/build/analytics/config.d.ts +7 -0
- package/build/analytics/config.js +30 -0
- package/build/analytics/config.js.map +1 -0
- package/build/analytics/mcp-tool-events.d.ts +5 -0
- package/build/analytics/mcp-tool-events.js +55 -0
- package/build/analytics/mcp-tool-events.js.map +1 -0
- package/build/analytics/wrap-service.d.ts +5 -0
- package/build/analytics/wrap-service.js +36 -0
- package/build/analytics/wrap-service.js.map +1 -0
- package/build/clients/carbon-rest.d.ts +17 -0
- package/build/clients/carbon-rest.js +59 -0
- package/build/clients/carbon-rest.js.map +1 -0
- package/build/clients/carbon-sdk.d.ts +31 -0
- package/build/clients/carbon-sdk.js +48 -0
- package/build/clients/carbon-sdk.js.map +1 -0
- package/build/clients/self-api.d.ts +82 -0
- package/build/clients/self-api.js +242 -0
- package/build/clients/self-api.js.map +1 -0
- package/build/config/carbon.d.ts +12 -0
- package/build/config/carbon.js +13 -0
- package/build/config/carbon.js.map +1 -0
- package/build/config/sdk-config.d.ts +14 -0
- package/build/config/sdk-config.js +16 -0
- package/build/config/sdk-config.js.map +1 -1
- package/build/config/self.d.ts +22 -0
- package/build/config/self.js +27 -0
- package/build/config/self.js.map +1 -0
- package/build/index.d.ts +16 -0
- package/build/index.js +27 -13
- package/build/index.js.map +1 -1
- package/build/services/carbon.service.d.ts +68 -0
- package/build/services/carbon.service.js +189 -0
- package/build/services/carbon.service.js.map +1 -0
- package/build/services/self-session-store.d.ts +19 -0
- package/build/services/self-session-store.js +28 -0
- package/build/services/self-session-store.js.map +1 -0
- package/build/services/self.service.d.ts +241 -0
- package/build/services/self.service.js +692 -0
- package/build/services/self.service.js.map +1 -0
- package/build/types/carbon.d.ts +31 -0
- package/build/types/carbon.js +2 -0
- package/build/types/carbon.js.map +1 -0
- package/build/utils/carbon-prepared-flow.d.ts +11 -0
- package/build/utils/carbon-prepared-flow.js +25 -0
- package/build/utils/carbon-prepared-flow.js.map +1 -0
- package/build/utils/carbon-rest-adapter.d.ts +8 -0
- package/build/utils/carbon-rest-adapter.js +72 -0
- package/build/utils/carbon-rest-adapter.js.map +1 -0
- package/build/utils/self-format.d.ts +28 -0
- package/build/utils/self-format.js +79 -0
- package/build/utils/self-format.js.map +1 -0
- package/build/utils/self-signing.d.ts +4 -0
- package/build/utils/self-signing.js +38 -0
- package/build/utils/self-signing.js.map +1 -0
- package/package.json +16 -2
- package/tests/README.md +72 -0
- package/tests/catalog/domains/blockchain.ts +91 -0
- package/tests/catalog/domains/carbon.ts +409 -0
- package/tests/catalog/domains/chain-ext.ts +219 -0
- package/tests/catalog/domains/defi.ts +264 -0
- package/tests/catalog/domains/self.ts +220 -0
- package/tests/catalog/domains/token.ts +74 -0
- package/tests/catalog/domains/transaction.ts +111 -0
- package/tests/catalog/index.ts +7 -0
- package/tests/catalog/operations.ts +48 -0
- package/tests/catalog/types.ts +27 -0
- package/tests/fixtures/mainnet.ts +93 -0
- package/tests/helpers/assert.ts +30 -0
- package/tests/helpers/env.ts +38 -0
- package/tests/helpers/gating.ts +36 -0
- package/tests/testing-entry.ts +22 -0
package/build/index.js
CHANGED
|
@@ -20,6 +20,9 @@ import { NftService } from "./services/nft.service.js";
|
|
|
20
20
|
import { StakingService } from "./services/staking.service.js";
|
|
21
21
|
import { TokenService } from "./services/token.service.js";
|
|
22
22
|
import { TransactionService } from "./services/transaction.service.js";
|
|
23
|
+
import { CarbonService } from "./services/carbon.service.js";
|
|
24
|
+
import { SelfService } from "./services/self.service.js";
|
|
25
|
+
import { wrapServiceForAnalytics } from "./analytics/wrap-service.js";
|
|
23
26
|
/**
|
|
24
27
|
* Create a Celina client for Celo mainnet reads and unsigned tx preparation.
|
|
25
28
|
* No private keys — pass prepared `steps` to wagmi/viem for wallet signing.
|
|
@@ -28,23 +31,34 @@ export function createCelinaClient(opts) {
|
|
|
28
31
|
const config = resolveSdkConfig(opts);
|
|
29
32
|
const clientFactory = new CeloClientFactory(config);
|
|
30
33
|
const ensClientFactory = new EnsClientFactory(config);
|
|
34
|
+
const tokenService = new TokenService(clientFactory);
|
|
35
|
+
const wrap = (key, service) => wrapServiceForAnalytics(key, service, config);
|
|
31
36
|
return {
|
|
32
|
-
blockchain: new BlockchainService(clientFactory),
|
|
33
|
-
account: new AccountService(clientFactory),
|
|
34
|
-
token:
|
|
35
|
-
transaction: new TransactionService(clientFactory),
|
|
36
|
-
mentoFx: new MentoFxService(clientFactory),
|
|
37
|
-
uniswap: new UniswapService(clientFactory),
|
|
38
|
-
aave: new AaveService(clientFactory),
|
|
39
|
-
gooddollar: new GoodDollarService(clientFactory),
|
|
40
|
-
ens: new EnsService(ensClientFactory),
|
|
41
|
-
governance: new GovernanceService(clientFactory),
|
|
42
|
-
staking: new StakingService(clientFactory),
|
|
43
|
-
nft: new NftService(clientFactory),
|
|
44
|
-
contract: new ContractService(clientFactory),
|
|
37
|
+
blockchain: wrap("blockchain", new BlockchainService(clientFactory)),
|
|
38
|
+
account: wrap("account", new AccountService(clientFactory)),
|
|
39
|
+
token: wrap("token", tokenService),
|
|
40
|
+
transaction: wrap("transaction", new TransactionService(clientFactory)),
|
|
41
|
+
mentoFx: wrap("mentoFx", new MentoFxService(clientFactory)),
|
|
42
|
+
uniswap: wrap("uniswap", new UniswapService(clientFactory)),
|
|
43
|
+
aave: wrap("aave", new AaveService(clientFactory)),
|
|
44
|
+
gooddollar: wrap("gooddollar", new GoodDollarService(clientFactory)),
|
|
45
|
+
ens: wrap("ens", new EnsService(ensClientFactory)),
|
|
46
|
+
governance: wrap("governance", new GovernanceService(clientFactory)),
|
|
47
|
+
staking: wrap("staking", new StakingService(clientFactory)),
|
|
48
|
+
nft: wrap("nft", new NftService(clientFactory)),
|
|
49
|
+
contract: wrap("contract", new ContractService(clientFactory)),
|
|
50
|
+
carbon: wrap("carbon", new CarbonService(config, tokenService)),
|
|
51
|
+
self: wrap("self", new SelfService(clientFactory, config)),
|
|
45
52
|
};
|
|
46
53
|
}
|
|
47
54
|
export { serializePreparedFlow } from "./types/prepared.js";
|
|
48
55
|
/** Aave V3 Celo pool address and supported asset symbols. */
|
|
49
56
|
export { AAVE_POOL, AAVE_SUPPORTED_SYMBOLS, resolveAaveAsset, } from "./config/aave.js";
|
|
57
|
+
export { CARBON_CHAIN, CELO_CARBON_CONTRACTS, DEFAULT_CARBON_REST_BASE_URL, } from "./config/carbon.js";
|
|
58
|
+
export { CarbonRestError } from "./clients/carbon-rest.js";
|
|
59
|
+
export { SelfService, } from "./services/self.service.js";
|
|
60
|
+
export { SelfApiError, SelfExpiredSessionError, } from "./clients/self-api.js";
|
|
61
|
+
export { selfDemoUrl, SELF_DEMO_NETWORK, SELF_HEADERS, } from "./config/self.js";
|
|
62
|
+
export { resolveSelfSessionLinks, formatSelfSessionLinksDisplay, } from "./utils/self-format.js";
|
|
63
|
+
export { clearSelfSessionsForTests } from "./services/self-session-store.js";
|
|
50
64
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,iBAAiB,E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X,iBAAiB,EACjB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAE9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carbon DeFi on Celo — hybrid @bancor/carbon-sdk + Carbon REST (mcp.carbondefi.xyz).
|
|
3
|
+
* REST is primary for all 25 MCP tools; SDK is fallback for quotes/trades when REST fails.
|
|
4
|
+
*/
|
|
5
|
+
import type { SdkConfig } from "../config/sdk-config.js";
|
|
6
|
+
import type { CarbonPrepareResult, CarbonRestSuccess } from "../types/carbon.js";
|
|
7
|
+
import type { TokenService } from "./token.service.js";
|
|
8
|
+
export type CarbonWriteBody = Record<string, unknown> & {
|
|
9
|
+
wallet_address: `0x${string}`;
|
|
10
|
+
};
|
|
11
|
+
export declare class CarbonService {
|
|
12
|
+
private readonly tokenService;
|
|
13
|
+
private readonly rest;
|
|
14
|
+
private readonly sdk;
|
|
15
|
+
constructor(config: SdkConfig, tokenService: TokenService);
|
|
16
|
+
private restRead;
|
|
17
|
+
private restPrepare;
|
|
18
|
+
private withSdkFallback;
|
|
19
|
+
getStrategies(walletAddress: `0x${string}`): Promise<CarbonRestSuccess & {
|
|
20
|
+
warnings: string[];
|
|
21
|
+
}>;
|
|
22
|
+
getStrategy(strategyId: string): Promise<CarbonRestSuccess & {
|
|
23
|
+
warnings: string[];
|
|
24
|
+
}>;
|
|
25
|
+
prepareLimitOrder(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
26
|
+
prepareRangeOrder(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
27
|
+
prepareRecurringStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
28
|
+
prepareConcentratedStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
29
|
+
prepareFullRangeStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
30
|
+
prepareRepriceStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
31
|
+
prepareEditStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
32
|
+
prepareDepositBudget(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
33
|
+
prepareWithdrawBudget(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
34
|
+
preparePauseStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
35
|
+
prepareResumeStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
36
|
+
prepareDeleteStrategy(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
37
|
+
getTradeQuote(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}>;
|
|
40
|
+
prepareTrade(body: CarbonWriteBody): Promise<CarbonPrepareResult>;
|
|
41
|
+
explorePair(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
42
|
+
warnings: string[];
|
|
43
|
+
}>;
|
|
44
|
+
resolveToken(symbolOrName: string): Promise<CarbonRestSuccess & {
|
|
45
|
+
warnings: string[];
|
|
46
|
+
}>;
|
|
47
|
+
getActivity(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
48
|
+
warnings: string[];
|
|
49
|
+
}>;
|
|
50
|
+
findOpportunities(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
51
|
+
warnings: string[];
|
|
52
|
+
}>;
|
|
53
|
+
getProtocolStats(body?: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
54
|
+
warnings: string[];
|
|
55
|
+
}>;
|
|
56
|
+
getPriceHistory(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
57
|
+
warnings: string[];
|
|
58
|
+
}>;
|
|
59
|
+
simulateStrategy(body: Record<string, unknown>): Promise<CarbonRestSuccess & {
|
|
60
|
+
warnings: string[];
|
|
61
|
+
}>;
|
|
62
|
+
help(topic?: string): Promise<CarbonRestSuccess & {
|
|
63
|
+
warnings: string[];
|
|
64
|
+
}>;
|
|
65
|
+
learn(topic?: string): Promise<CarbonRestSuccess & {
|
|
66
|
+
warnings: string[];
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CarbonRestClient } from "../clients/carbon-rest.js";
|
|
2
|
+
import { CarbonSdkClient } from "../clients/carbon-sdk.js";
|
|
3
|
+
import { extractWarnings, normalizeCarbonPrepareResult, } from "../utils/carbon-rest-adapter.js";
|
|
4
|
+
function walletAddress(value) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export class CarbonService {
|
|
8
|
+
tokenService;
|
|
9
|
+
rest;
|
|
10
|
+
sdk;
|
|
11
|
+
constructor(config, tokenService) {
|
|
12
|
+
this.tokenService = tokenService;
|
|
13
|
+
this.rest = new CarbonRestClient(config.carbonRestBaseUrl);
|
|
14
|
+
this.sdk =
|
|
15
|
+
config.carbonSdkFallback !== false
|
|
16
|
+
? new CarbonSdkClient(config.rpcUrl)
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
async restRead(tool, body = {}) {
|
|
20
|
+
const result = await this.rest.postTool(tool, body);
|
|
21
|
+
return { ...result, warnings: extractWarnings(result) };
|
|
22
|
+
}
|
|
23
|
+
async restPrepare(tool, body, summary) {
|
|
24
|
+
const from = walletAddress(body.wallet_address);
|
|
25
|
+
const result = await this.rest.postTool(tool, body);
|
|
26
|
+
return normalizeCarbonPrepareResult(from, result, summary);
|
|
27
|
+
}
|
|
28
|
+
async withSdkFallback(restFn, fallbackFn) {
|
|
29
|
+
try {
|
|
30
|
+
return await restFn();
|
|
31
|
+
}
|
|
32
|
+
catch (primary) {
|
|
33
|
+
if (!this.sdk)
|
|
34
|
+
throw primary;
|
|
35
|
+
return fallbackFn();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// --- Read (2) ---
|
|
39
|
+
async getStrategies(walletAddress) {
|
|
40
|
+
return this.restRead("get_strategies", { wallet_address: walletAddress });
|
|
41
|
+
}
|
|
42
|
+
async getStrategy(strategyId) {
|
|
43
|
+
return this.restRead("get_strategy", { strategy_id: strategyId });
|
|
44
|
+
}
|
|
45
|
+
// --- Create (5) ---
|
|
46
|
+
async prepareLimitOrder(body) {
|
|
47
|
+
return this.restPrepare("create_limit_order", body, "Carbon limit order");
|
|
48
|
+
}
|
|
49
|
+
async prepareRangeOrder(body) {
|
|
50
|
+
return this.restPrepare("create_range_order", body, "Carbon range order");
|
|
51
|
+
}
|
|
52
|
+
async prepareRecurringStrategy(body) {
|
|
53
|
+
return this.restPrepare("create_recurring_strategy", body, "Carbon recurring strategy");
|
|
54
|
+
}
|
|
55
|
+
async prepareConcentratedStrategy(body) {
|
|
56
|
+
return this.restPrepare("create_concentrated_strategy", body, "Carbon concentrated strategy");
|
|
57
|
+
}
|
|
58
|
+
async prepareFullRangeStrategy(body) {
|
|
59
|
+
return this.restPrepare("create_full_range_strategy", body, "Carbon full-range strategy");
|
|
60
|
+
}
|
|
61
|
+
// --- Manage (7) ---
|
|
62
|
+
async prepareRepriceStrategy(body) {
|
|
63
|
+
return this.restPrepare("reprice_strategy", body, "Carbon reprice strategy");
|
|
64
|
+
}
|
|
65
|
+
async prepareEditStrategy(body) {
|
|
66
|
+
return this.restPrepare("edit_strategy", body, "Carbon edit strategy");
|
|
67
|
+
}
|
|
68
|
+
async prepareDepositBudget(body) {
|
|
69
|
+
return this.restPrepare("deposit_budget", body, "Carbon deposit budget");
|
|
70
|
+
}
|
|
71
|
+
async prepareWithdrawBudget(body) {
|
|
72
|
+
return this.restPrepare("withdraw_budget", body, "Carbon withdraw budget");
|
|
73
|
+
}
|
|
74
|
+
async preparePauseStrategy(body) {
|
|
75
|
+
return this.restPrepare("pause_strategy", body, "Carbon pause strategy");
|
|
76
|
+
}
|
|
77
|
+
async prepareResumeStrategy(body) {
|
|
78
|
+
return this.restPrepare("resume_strategy", body, "Carbon resume strategy");
|
|
79
|
+
}
|
|
80
|
+
async prepareDeleteStrategy(body) {
|
|
81
|
+
return this.restPrepare("delete_strategy", body, "Carbon delete strategy");
|
|
82
|
+
}
|
|
83
|
+
// --- Trade (2) ---
|
|
84
|
+
async getTradeQuote(body) {
|
|
85
|
+
const amount = typeof body.amount === "string" ? Number(body.amount) : body.amount;
|
|
86
|
+
const normalized = {
|
|
87
|
+
...body,
|
|
88
|
+
amount,
|
|
89
|
+
...(body.is_trade_by_target !== undefined
|
|
90
|
+
? { by_target: body.is_trade_by_target }
|
|
91
|
+
: {}),
|
|
92
|
+
};
|
|
93
|
+
return this.withSdkFallback(() => this.restRead("get_trade_quote", normalized), async () => {
|
|
94
|
+
if (!this.sdk)
|
|
95
|
+
throw new Error("Carbon SDK fallback unavailable");
|
|
96
|
+
const sourceToken = String(body.source_token ?? body.token_in);
|
|
97
|
+
const targetToken = String(body.target_token ?? body.token_out);
|
|
98
|
+
const amountStr = String(amount);
|
|
99
|
+
const isTradeByTarget = Boolean(body.is_trade_by_target ?? body.by_target);
|
|
100
|
+
const { tradeData } = await this.sdk.getTradeQuoteFallback(sourceToken, targetToken, amountStr, isTradeByTarget);
|
|
101
|
+
return {
|
|
102
|
+
status: "ok",
|
|
103
|
+
warnings: [],
|
|
104
|
+
source: "sdk_fallback",
|
|
105
|
+
...tradeData,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async prepareTrade(body) {
|
|
110
|
+
try {
|
|
111
|
+
return await this.restPrepare("execute_trade", body, "Carbon taker swap");
|
|
112
|
+
}
|
|
113
|
+
catch (primary) {
|
|
114
|
+
if (!this.sdk)
|
|
115
|
+
throw primary;
|
|
116
|
+
const sourceToken = String(body.source_token ?? body.token_in);
|
|
117
|
+
const targetToken = String(body.target_token ?? body.token_out);
|
|
118
|
+
const amount = String(body.amount);
|
|
119
|
+
const minReturn = String(body.min_return ?? "0");
|
|
120
|
+
const preparedFlow = await this.sdk.prepareTradeFallback(walletAddress(body.wallet_address), sourceToken, targetToken, amount, false, minReturn);
|
|
121
|
+
return {
|
|
122
|
+
status: "ok",
|
|
123
|
+
warnings: [],
|
|
124
|
+
preparedFlow,
|
|
125
|
+
source: "sdk_fallback",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// --- Explore (8) ---
|
|
130
|
+
async explorePair(body) {
|
|
131
|
+
return this.restRead("explore_pair", body);
|
|
132
|
+
}
|
|
133
|
+
async resolveToken(symbolOrName) {
|
|
134
|
+
try {
|
|
135
|
+
return await this.restRead("resolve_token", {
|
|
136
|
+
token: symbolOrName,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
const resolved = this.tokenService.resolveToken(symbolOrName);
|
|
141
|
+
return {
|
|
142
|
+
status: "ok",
|
|
143
|
+
warnings: [],
|
|
144
|
+
symbol: resolved.symbol,
|
|
145
|
+
address: resolved.address,
|
|
146
|
+
decimals: resolved.decimals,
|
|
147
|
+
source: "celina_registry",
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async getActivity(body) {
|
|
152
|
+
return this.restRead("get_activity", body);
|
|
153
|
+
}
|
|
154
|
+
async findOpportunities(body) {
|
|
155
|
+
return this.restRead("find_opportunities", body);
|
|
156
|
+
}
|
|
157
|
+
async getProtocolStats(body = {}) {
|
|
158
|
+
const { period_days, ...rest } = body;
|
|
159
|
+
return this.restRead("get_protocol_stats", {
|
|
160
|
+
...rest,
|
|
161
|
+
...(period_days !== undefined ? { days: period_days } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async getPriceHistory(body) {
|
|
165
|
+
const { period_days, days, ...rest } = body;
|
|
166
|
+
const lookback = days ?? period_days;
|
|
167
|
+
return this.restRead("get_price_history", {
|
|
168
|
+
...rest,
|
|
169
|
+
...(lookback !== undefined ? { days: lookback } : {}),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async simulateStrategy(body) {
|
|
173
|
+
const { days, ...rest } = body;
|
|
174
|
+
if (rest.start === undefined && rest.end === undefined && days !== undefined) {
|
|
175
|
+
const end = Math.floor(Date.now() / 1000);
|
|
176
|
+
const start = end - Number(days) * 86_400;
|
|
177
|
+
return this.restRead("simulate_strategy", { ...rest, start, end });
|
|
178
|
+
}
|
|
179
|
+
return this.restRead("simulate_strategy", body);
|
|
180
|
+
}
|
|
181
|
+
// --- Help (2) ---
|
|
182
|
+
async help(topic) {
|
|
183
|
+
return this.restRead("help", topic ? { topic } : {});
|
|
184
|
+
}
|
|
185
|
+
async learn(topic) {
|
|
186
|
+
return this.restRead("learn", topic ? { topic } : {});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=carbon.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carbon.service.js","sourceRoot":"","sources":["../../src/services/carbon.service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EACL,eAAe,EACf,4BAA4B,GAC7B,MAAM,iCAAiC,CAAC;AAOzC,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAsB,CAAC;AAChC,CAAC;AAED,MAAM,OAAO,aAAa;IAML;IALF,IAAI,CAAmB;IACvB,GAAG,CAAyB;IAE7C,YACE,MAAiB,EACA,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAE3C,IAAI,CAAC,IAAI,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC3D,IAAI,CAAC,GAAG;YACN,MAAM,CAAC,iBAAiB,KAAK,KAAK;gBAChC,CAAC,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;gBACpC,CAAC,CAAC,IAAI,CAA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,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SelfDeregistrationSession, SelfRefreshSession, SelfRegistrationSession } from "../clients/self-api.js";
|
|
2
|
+
export type SelfSessionKind = "registration" | "refresh" | "deregistration";
|
|
3
|
+
export type StoredSelfSession = {
|
|
4
|
+
kind: "registration";
|
|
5
|
+
session: SelfRegistrationSession;
|
|
6
|
+
createdAt: number;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "refresh";
|
|
9
|
+
session: SelfRefreshSession;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "deregistration";
|
|
13
|
+
session: SelfDeregistrationSession;
|
|
14
|
+
createdAt: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function storeSelfSession(sessionToken: string, entry: StoredSelfSession): void;
|
|
17
|
+
export declare function getSelfSession(sessionToken: string): StoredSelfSession | undefined;
|
|
18
|
+
export declare function deleteSelfSession(sessionToken: string): void;
|
|
19
|
+
export declare function clearSelfSessionsForTests(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SELF_MAX_SESSIONS, SELF_SESSION_TTL_MS } from "../config/self.js";
|
|
2
|
+
const sessions = new Map();
|
|
3
|
+
function pruneExpiredSessions() {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
for (const [key, entry] of sessions) {
|
|
6
|
+
if (now - entry.createdAt > SELF_SESSION_TTL_MS) {
|
|
7
|
+
sessions.delete(key);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function storeSelfSession(sessionToken, entry) {
|
|
12
|
+
pruneExpiredSessions();
|
|
13
|
+
if (sessions.size >= SELF_MAX_SESSIONS) {
|
|
14
|
+
throw new Error("Too many active Self sessions. Wait for existing sessions to expire (10 minutes) or restart the server.");
|
|
15
|
+
}
|
|
16
|
+
sessions.set(sessionToken, entry);
|
|
17
|
+
}
|
|
18
|
+
export function getSelfSession(sessionToken) {
|
|
19
|
+
pruneExpiredSessions();
|
|
20
|
+
return sessions.get(sessionToken);
|
|
21
|
+
}
|
|
22
|
+
export function deleteSelfSession(sessionToken) {
|
|
23
|
+
sessions.delete(sessionToken);
|
|
24
|
+
}
|
|
25
|
+
export function clearSelfSessionsForTests() {
|
|
26
|
+
sessions.clear();
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=self-session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-session-store.js","sourceRoot":"","sources":["../../src/services/self-session-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA0B3E,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEtD,SAAS,oBAAoB;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;QACpC,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,mBAAmB,EAAE,CAAC;YAChD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,YAAoB,EACpB,KAAwB;IAExB,oBAAoB,EAAE,CAAC;IAEvB,IAAI,QAAQ,CAAC,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,YAAoB;IACjD,oBAAoB,EAAE,CAAC;IACvB,OAAO,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
import type { SelfRegistrationMode } from "../config/self.js";
|
|
3
|
+
import type { SdkConfig } from "../config/sdk-config.js";
|
|
4
|
+
import type { CeloClientFactory } from "../clients/celo-client.js";
|
|
5
|
+
export interface VerifySelfAgentParams {
|
|
6
|
+
agentAddress: `0x${string}`;
|
|
7
|
+
requireAge?: 0 | 18 | 21;
|
|
8
|
+
requireOfac?: boolean;
|
|
9
|
+
requireSelfProvider?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface VerifySelfRequestParams {
|
|
12
|
+
agentSignature: Hex;
|
|
13
|
+
agentTimestamp: string;
|
|
14
|
+
method: string;
|
|
15
|
+
path: string;
|
|
16
|
+
body?: string;
|
|
17
|
+
keytype?: string;
|
|
18
|
+
agentKey?: Hex;
|
|
19
|
+
}
|
|
20
|
+
export interface RegisterSelfAgentParams {
|
|
21
|
+
mode?: SelfRegistrationMode;
|
|
22
|
+
minimumAge?: 0 | 18 | 21;
|
|
23
|
+
ofac?: boolean;
|
|
24
|
+
humanAddress?: `0x${string}`;
|
|
25
|
+
agentName?: string;
|
|
26
|
+
agentDescription?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class SelfService {
|
|
29
|
+
private readonly clientFactory;
|
|
30
|
+
private readonly config;
|
|
31
|
+
constructor(clientFactory: CeloClientFactory, config: Pick<SdkConfig, "selfAgentPrivateKey" | "selfApiBase">);
|
|
32
|
+
private get apiBase();
|
|
33
|
+
private resolveAgentPrivateKey;
|
|
34
|
+
private registryClient;
|
|
35
|
+
private assertProofRefreshEligible;
|
|
36
|
+
verifyAgent(params: VerifySelfAgentParams): Promise<{
|
|
37
|
+
verified: boolean;
|
|
38
|
+
agent_address: `0x${string}`;
|
|
39
|
+
reason: string;
|
|
40
|
+
network: "mainnet";
|
|
41
|
+
} | {
|
|
42
|
+
verification_strength: string;
|
|
43
|
+
network: "mainnet";
|
|
44
|
+
sibling_agent_ids: number[];
|
|
45
|
+
proof_expires_at: string | null;
|
|
46
|
+
days_until_expiry: number;
|
|
47
|
+
is_expiring_soon: boolean;
|
|
48
|
+
verified: boolean;
|
|
49
|
+
agent_address: `0x${string}`;
|
|
50
|
+
agent_id: number;
|
|
51
|
+
reason: string;
|
|
52
|
+
credentials: {
|
|
53
|
+
nationality: string | undefined;
|
|
54
|
+
older_than: number;
|
|
55
|
+
ofac_clear: boolean;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
verification_strength: string;
|
|
59
|
+
registered_at: number;
|
|
60
|
+
agent_count: number;
|
|
61
|
+
is_proof_fresh: boolean;
|
|
62
|
+
network: "mainnet";
|
|
63
|
+
sibling_agent_ids: number[];
|
|
64
|
+
proof_expires_at: string | null;
|
|
65
|
+
days_until_expiry: number;
|
|
66
|
+
is_expiring_soon: boolean;
|
|
67
|
+
verified: boolean;
|
|
68
|
+
agent_address: `0x${string}`;
|
|
69
|
+
agent_id: number;
|
|
70
|
+
credentials: {
|
|
71
|
+
nationality: string | undefined;
|
|
72
|
+
older_than: number;
|
|
73
|
+
ofac_clear: boolean;
|
|
74
|
+
};
|
|
75
|
+
reason?: undefined;
|
|
76
|
+
}>;
|
|
77
|
+
lookupAgent(agentId: number): Promise<{
|
|
78
|
+
is_expired: boolean;
|
|
79
|
+
network: "mainnet";
|
|
80
|
+
proof_expires_at: string | null;
|
|
81
|
+
days_until_expiry: number;
|
|
82
|
+
is_expiring_soon: boolean;
|
|
83
|
+
credentialsSummary: string;
|
|
84
|
+
}>;
|
|
85
|
+
verifyRequest(params: VerifySelfRequestParams): Promise<{
|
|
86
|
+
valid: boolean;
|
|
87
|
+
reason: string;
|
|
88
|
+
agent_address?: undefined;
|
|
89
|
+
agent_id?: undefined;
|
|
90
|
+
agent_count?: undefined;
|
|
91
|
+
nullifier?: undefined;
|
|
92
|
+
credentials?: undefined;
|
|
93
|
+
note?: undefined;
|
|
94
|
+
} | {
|
|
95
|
+
valid: boolean;
|
|
96
|
+
agent_address: `0x${string}`;
|
|
97
|
+
reason: string;
|
|
98
|
+
agent_id?: undefined;
|
|
99
|
+
agent_count?: undefined;
|
|
100
|
+
nullifier?: undefined;
|
|
101
|
+
credentials?: undefined;
|
|
102
|
+
note?: undefined;
|
|
103
|
+
} | {
|
|
104
|
+
valid: boolean;
|
|
105
|
+
agent_address: `0x${string}`;
|
|
106
|
+
agent_id: number;
|
|
107
|
+
reason: string;
|
|
108
|
+
agent_count?: undefined;
|
|
109
|
+
nullifier?: undefined;
|
|
110
|
+
credentials?: undefined;
|
|
111
|
+
note?: undefined;
|
|
112
|
+
} | {
|
|
113
|
+
valid: boolean;
|
|
114
|
+
agent_address: `0x${string}`;
|
|
115
|
+
agent_id: number;
|
|
116
|
+
agent_count: number;
|
|
117
|
+
nullifier: number;
|
|
118
|
+
credentials: {
|
|
119
|
+
nationality: string | undefined;
|
|
120
|
+
older_than: number;
|
|
121
|
+
ofac_clear: boolean;
|
|
122
|
+
};
|
|
123
|
+
note: string;
|
|
124
|
+
reason?: undefined;
|
|
125
|
+
}>;
|
|
126
|
+
private getAgentInfoFromKey;
|
|
127
|
+
getIdentity(): Promise<{
|
|
128
|
+
expiry_warning?: string | undefined;
|
|
129
|
+
is_expired: boolean;
|
|
130
|
+
sibling_agent_ids: number[];
|
|
131
|
+
network: "mainnet";
|
|
132
|
+
proof_expires_at: string | null;
|
|
133
|
+
days_until_expiry: number;
|
|
134
|
+
is_expiring_soon: boolean;
|
|
135
|
+
registered: true;
|
|
136
|
+
address: `0x${string}`;
|
|
137
|
+
agentKey: `0x${string}`;
|
|
138
|
+
agentId: number;
|
|
139
|
+
isVerified: boolean;
|
|
140
|
+
nullifier: number;
|
|
141
|
+
agentCount: number;
|
|
142
|
+
verificationStrength: string;
|
|
143
|
+
credentials_summary: string;
|
|
144
|
+
} | {
|
|
145
|
+
message: string;
|
|
146
|
+
registered: false;
|
|
147
|
+
address: `0x${string}`;
|
|
148
|
+
network: "mainnet";
|
|
149
|
+
}>;
|
|
150
|
+
registerAgent(params?: RegisterSelfAgentParams): Promise<{
|
|
151
|
+
session_id: string;
|
|
152
|
+
qr_code_url: string;
|
|
153
|
+
qr_url: string;
|
|
154
|
+
deep_link: string;
|
|
155
|
+
expires_at: string;
|
|
156
|
+
instructions: string;
|
|
157
|
+
}>;
|
|
158
|
+
checkRegistration(sessionId: string): Promise<{
|
|
159
|
+
status: "deregistered";
|
|
160
|
+
message: string;
|
|
161
|
+
proof_expires_at?: undefined;
|
|
162
|
+
agent_id?: undefined;
|
|
163
|
+
agent_address?: undefined;
|
|
164
|
+
private_key_hex?: undefined;
|
|
165
|
+
tx_hash?: undefined;
|
|
166
|
+
} | {
|
|
167
|
+
status: "refreshed";
|
|
168
|
+
proof_expires_at: string;
|
|
169
|
+
message: string;
|
|
170
|
+
agent_id?: undefined;
|
|
171
|
+
agent_address?: undefined;
|
|
172
|
+
private_key_hex?: undefined;
|
|
173
|
+
tx_hash?: undefined;
|
|
174
|
+
} | {
|
|
175
|
+
status: "verified";
|
|
176
|
+
agent_id: number;
|
|
177
|
+
agent_address: string;
|
|
178
|
+
private_key_hex: string;
|
|
179
|
+
tx_hash: string | undefined;
|
|
180
|
+
message: string;
|
|
181
|
+
proof_expires_at?: undefined;
|
|
182
|
+
} | {
|
|
183
|
+
status: "pending";
|
|
184
|
+
message: string;
|
|
185
|
+
proof_expires_at?: undefined;
|
|
186
|
+
agent_id?: undefined;
|
|
187
|
+
agent_address?: undefined;
|
|
188
|
+
private_key_hex?: undefined;
|
|
189
|
+
tx_hash?: undefined;
|
|
190
|
+
} | {
|
|
191
|
+
status: "expired";
|
|
192
|
+
message: string;
|
|
193
|
+
proof_expires_at?: undefined;
|
|
194
|
+
agent_id?: undefined;
|
|
195
|
+
agent_address?: undefined;
|
|
196
|
+
private_key_hex?: undefined;
|
|
197
|
+
tx_hash?: undefined;
|
|
198
|
+
}>;
|
|
199
|
+
refreshProof(params?: {
|
|
200
|
+
agentId?: number;
|
|
201
|
+
}): Promise<{
|
|
202
|
+
session_id: string;
|
|
203
|
+
qr_code_url: string;
|
|
204
|
+
qr_url: string;
|
|
205
|
+
deep_link: string;
|
|
206
|
+
expires_at: string;
|
|
207
|
+
instructions: string;
|
|
208
|
+
}>;
|
|
209
|
+
deregisterAgent(): Promise<{
|
|
210
|
+
session_id: string;
|
|
211
|
+
qr_code_url: string;
|
|
212
|
+
qr_url: string;
|
|
213
|
+
deep_link: string;
|
|
214
|
+
expires_at: string;
|
|
215
|
+
instructions: string;
|
|
216
|
+
}>;
|
|
217
|
+
signRequest(params: {
|
|
218
|
+
method: string;
|
|
219
|
+
url: string;
|
|
220
|
+
body?: string;
|
|
221
|
+
}): Promise<{
|
|
222
|
+
headers: {
|
|
223
|
+
"x-self-agent-address": `0x${string}`;
|
|
224
|
+
"x-self-agent-signature": `0x${string}`;
|
|
225
|
+
"x-self-agent-timestamp": string;
|
|
226
|
+
};
|
|
227
|
+
instructions: string;
|
|
228
|
+
}>;
|
|
229
|
+
authenticatedFetch(params: {
|
|
230
|
+
method: string;
|
|
231
|
+
url: string;
|
|
232
|
+
body?: string;
|
|
233
|
+
contentType?: string;
|
|
234
|
+
}): Promise<{
|
|
235
|
+
status: number;
|
|
236
|
+
body: string;
|
|
237
|
+
truncated: boolean;
|
|
238
|
+
}>;
|
|
239
|
+
/** Reserved for future on-chain Self writes (e.g. metadata updates). */
|
|
240
|
+
protected taggedCalldata(data: Hex): Hex;
|
|
241
|
+
}
|