@andrewkimjoseph/celina 0.4.0 → 0.4.2
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/bin/wrapper.js +2 -0
- package/package.json +5 -44
- package/LICENSE +0 -21
- package/README.md +0 -292
- package/assets/logo-black.png +0 -0
- package/assets/logo-yellow.png +0 -0
- package/assets/logo.png +0 -0
- package/bin/cli.js +0 -2
- package/build/abis/aave-pool.d.ts +0 -37
- package/build/abis/aave-pool.js +0 -26
- package/build/abis/aave-pool.js.map +0 -1
- package/build/abis/gooddollar-identity.d.ts +0 -61
- package/build/abis/gooddollar-identity.js +0 -38
- package/build/abis/gooddollar-identity.js.map +0 -1
- package/build/abis/self-registry.d.ts +0 -194
- package/build/abis/self-registry.js +0 -120
- package/build/abis/self-registry.js.map +0 -1
- package/build/clients/celo-client.d.ts +0 -13
- package/build/clients/celo-client.js +0 -39
- package/build/clients/celo-client.js.map +0 -1
- package/build/clients/ens-client.d.ts +0 -10
- package/build/clients/ens-client.js +0 -23
- package/build/clients/ens-client.js.map +0 -1
- package/build/clients/mento-sdk.d.ts +0 -2
- package/build/clients/mento-sdk.js +0 -9
- package/build/clients/mento-sdk.js.map +0 -1
- package/build/clients/self-api.d.ts +0 -82
- package/build/clients/self-api.js +0 -242
- package/build/clients/self-api.js.map +0 -1
- package/build/config/aave.d.ts +0 -11
- package/build/config/aave.js +0 -55
- package/build/config/aave.js.map +0 -1
- package/build/config/celina-tag.d.ts +0 -1
- package/build/config/celina-tag.js +0 -3
- package/build/config/celina-tag.js.map +0 -1
- package/build/config/chains.d.ts +0 -935
- package/build/config/chains.js +0 -251
- package/build/config/chains.js.map +0 -1
- package/build/config/env.d.ts +0 -7
- package/build/config/env.js +0 -9
- package/build/config/env.js.map +0 -1
- package/build/config/gooddollar.d.ts +0 -1
- package/build/config/gooddollar.js +0 -2
- package/build/config/gooddollar.js.map +0 -1
- package/build/config/load-env.d.ts +0 -1
- package/build/config/load-env.js +0 -4
- package/build/config/load-env.js.map +0 -1
- package/build/config/self.d.ts +0 -22
- package/build/config/self.js +0 -27
- package/build/config/self.js.map +0 -1
- package/build/context/app-context.d.ts +0 -28
- package/build/context/app-context.js +0 -28
- package/build/context/app-context.js.map +0 -1
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -17
- package/build/index.js.map +0 -1
- package/build/schemas/common.d.ts +0 -6
- package/build/schemas/common.js +0 -24
- package/build/schemas/common.js.map +0 -1
- package/build/server/create-server.d.ts +0 -2
- package/build/server/create-server.js +0 -23
- package/build/server/create-server.js.map +0 -1
- package/build/server/instructions.d.ts +0 -1
- package/build/server/instructions.js +0 -22
- package/build/server/instructions.js.map +0 -1
- package/build/services/aave.service.d.ts +0 -29
- package/build/services/aave.service.js +0 -166
- package/build/services/aave.service.js.map +0 -1
- package/build/services/account.service.d.ts +0 -13
- package/build/services/account.service.js +0 -23
- package/build/services/account.service.js.map +0 -1
- package/build/services/blockchain.service.d.ts +0 -40
- package/build/services/blockchain.service.js +0 -81
- package/build/services/blockchain.service.js.map +0 -1
- package/build/services/ens.service.d.ts +0 -30
- package/build/services/ens.service.js +0 -78
- package/build/services/ens.service.js.map +0 -1
- package/build/services/gooddollar.service.d.ts +0 -38
- package/build/services/gooddollar.service.js +0 -127
- package/build/services/gooddollar.service.js.map +0 -1
- package/build/services/mento-fx.service.d.ts +0 -71
- package/build/services/mento-fx.service.js +0 -261
- package/build/services/mento-fx.service.js.map +0 -1
- package/build/services/self-session-store.d.ts +0 -19
- package/build/services/self-session-store.js +0 -28
- package/build/services/self-session-store.js.map +0 -1
- package/build/services/self.service.d.ts +0 -247
- package/build/services/self.service.js +0 -685
- package/build/services/self.service.js.map +0 -1
- package/build/services/token.service.d.ts +0 -54
- package/build/services/token.service.js +0 -147
- package/build/services/token.service.js.map +0 -1
- package/build/services/transaction.service.d.ts +0 -24
- package/build/services/transaction.service.js +0 -112
- package/build/services/transaction.service.js.map +0 -1
- package/build/tools/aave.tools.d.ts +0 -2
- package/build/tools/aave.tools.js +0 -55
- package/build/tools/aave.tools.js.map +0 -1
- package/build/tools/blockchain.tools.d.ts +0 -3
- package/build/tools/blockchain.tools.js +0 -88
- package/build/tools/blockchain.tools.js.map +0 -1
- package/build/tools/ens.tools.d.ts +0 -2
- package/build/tools/ens.tools.js +0 -27
- package/build/tools/ens.tools.js.map +0 -1
- package/build/tools/gooddollar.tools.d.ts +0 -2
- package/build/tools/gooddollar.tools.js +0 -23
- package/build/tools/gooddollar.tools.js.map +0 -1
- package/build/tools/helpers.d.ts +0 -3
- package/build/tools/helpers.js +0 -16
- package/build/tools/helpers.js.map +0 -1
- package/build/tools/index.d.ts +0 -5
- package/build/tools/index.js +0 -25
- package/build/tools/index.js.map +0 -1
- package/build/tools/mento-fx.tools.d.ts +0 -2
- package/build/tools/mento-fx.tools.js +0 -80
- package/build/tools/mento-fx.tools.js.map +0 -1
- package/build/tools/self.tools.d.ts +0 -2
- package/build/tools/self.tools.js +0 -242
- package/build/tools/self.tools.js.map +0 -1
- package/build/tools/token.tools.d.ts +0 -2
- package/build/tools/token.tools.js +0 -62
- package/build/tools/token.tools.js.map +0 -1
- package/build/tools/transaction.tools.d.ts +0 -2
- package/build/tools/transaction.tools.js +0 -49
- package/build/tools/transaction.tools.js.map +0 -1
- package/build/tools/types.d.ts +0 -5
- package/build/tools/types.js +0 -2
- package/build/tools/types.js.map +0 -1
- package/build/utils/erc20-allowance-storage.d.ts +0 -7
- package/build/utils/erc20-allowance-storage.js +0 -44
- package/build/utils/erc20-allowance-storage.js.map +0 -1
- package/build/utils/format-date.d.ts +0 -1
- package/build/utils/format-date.js +0 -12
- package/build/utils/format-date.js.map +0 -1
- package/build/utils/self-format.d.ts +0 -16
- package/build/utils/self-format.js +0 -59
- package/build/utils/self-format.js.map +0 -1
- package/build/utils/self-signing.d.ts +0 -4
- package/build/utils/self-signing.js +0 -38
- package/build/utils/self-signing.js.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { CeloClientFactory } from "../clients/celo-client.js";
|
|
2
|
-
export interface MentoFxParams {
|
|
3
|
-
slippageTolerance?: number;
|
|
4
|
-
deadlineMinutes?: number;
|
|
5
|
-
recipient?: `0x${string}`;
|
|
6
|
-
}
|
|
7
|
-
export declare class MentoFxService {
|
|
8
|
-
private readonly clientFactory;
|
|
9
|
-
private readonly tokenService;
|
|
10
|
-
constructor(clientFactory: CeloClientFactory);
|
|
11
|
-
private requireClients;
|
|
12
|
-
private getMentoClient;
|
|
13
|
-
private resolveMentoPair;
|
|
14
|
-
private fxOptions;
|
|
15
|
-
private formatFxError;
|
|
16
|
-
private toSendParams;
|
|
17
|
-
private estimateCallGas;
|
|
18
|
-
/**
|
|
19
|
-
* Swap gas estimation runs transferFrom; without on-chain approval that reverts.
|
|
20
|
-
* Simulate sufficient allowance via eth_estimateGas stateOverride.
|
|
21
|
-
*/
|
|
22
|
-
private estimateSwapGasWithAllowance;
|
|
23
|
-
private executeCall;
|
|
24
|
-
private baseQuoteFields;
|
|
25
|
-
getFxQuote(tokenIn: string, tokenOut: string, amount: string): Promise<{
|
|
26
|
-
protocol: "mento_fx";
|
|
27
|
-
network: "mainnet";
|
|
28
|
-
tokenIn: string;
|
|
29
|
-
tokenOut: string;
|
|
30
|
-
amountIn: string;
|
|
31
|
-
expectedOut: string;
|
|
32
|
-
routeHops: number;
|
|
33
|
-
}>;
|
|
34
|
-
estimateFx(tokenIn: string, tokenOut: string, amount: string, params?: MentoFxParams): Promise<{
|
|
35
|
-
from: `0x${string}`;
|
|
36
|
-
recipient: `0x${string}`;
|
|
37
|
-
amountOutMin: string;
|
|
38
|
-
approvalNeeded: boolean;
|
|
39
|
-
approvalGas: string | undefined;
|
|
40
|
-
fxGas: string;
|
|
41
|
-
slippageTolerance: number;
|
|
42
|
-
deadline: string;
|
|
43
|
-
deadlineMinutes: number;
|
|
44
|
-
protocol: "mento_fx";
|
|
45
|
-
network: "mainnet";
|
|
46
|
-
tokenIn: string;
|
|
47
|
-
tokenOut: string;
|
|
48
|
-
amountIn: string;
|
|
49
|
-
expectedOut: string;
|
|
50
|
-
routeHops: number;
|
|
51
|
-
}>;
|
|
52
|
-
executeFx(tokenIn: string, tokenOut: string, amount: string, params?: MentoFxParams): Promise<{
|
|
53
|
-
from: `0x${string}`;
|
|
54
|
-
recipient: `0x${string}`;
|
|
55
|
-
amountOutMin: string;
|
|
56
|
-
approvalNeeded: boolean;
|
|
57
|
-
approvalHash: `0x${string}` | undefined;
|
|
58
|
-
hash: `0x${string}`;
|
|
59
|
-
status: "success" | "reverted";
|
|
60
|
-
slippageTolerance: number;
|
|
61
|
-
deadline: string;
|
|
62
|
-
deadlineMinutes: number;
|
|
63
|
-
protocol: "mento_fx";
|
|
64
|
-
network: "mainnet";
|
|
65
|
-
tokenIn: string;
|
|
66
|
-
tokenOut: string;
|
|
67
|
-
amountIn: string;
|
|
68
|
-
expectedOut: string;
|
|
69
|
-
routeHops: number;
|
|
70
|
-
}>;
|
|
71
|
-
}
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { concat, decodeFunctionData, erc20Abi, formatUnits } from "viem";
|
|
2
|
-
import { ChainId, deadlineFromMinutes, Mento, RouteNotFoundError, FXMarketClosedError, } from "../clients/mento-sdk.js";
|
|
3
|
-
import { CELINA_DATA_SUFFIX } from "../config/celina-tag.js";
|
|
4
|
-
import { toMentoTokenAddress } from "../config/chains.js";
|
|
5
|
-
import { ALLOWANCE_MAPPING_SLOTS, erc20AllowanceStateOverride, isLikelyTransferFailed, } from "../utils/erc20-allowance-storage.js";
|
|
6
|
-
import { TokenService } from "./token.service.js";
|
|
7
|
-
const DEFAULT_SLIPPAGE = 0.5;
|
|
8
|
-
const DEFAULT_DEADLINE_MINUTES = 5;
|
|
9
|
-
function parseErc20Approve(params) {
|
|
10
|
-
try {
|
|
11
|
-
const decoded = decodeFunctionData({
|
|
12
|
-
abi: erc20Abi,
|
|
13
|
-
data: params.data,
|
|
14
|
-
});
|
|
15
|
-
if (decoded.functionName !== "approve") {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
token: params.to,
|
|
20
|
-
spender: decoded.args[0],
|
|
21
|
-
amount: decoded.args[1],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function taggedCalldata(data) {
|
|
29
|
-
return concat([data, CELINA_DATA_SUFFIX]);
|
|
30
|
-
}
|
|
31
|
-
export class MentoFxService {
|
|
32
|
-
clientFactory;
|
|
33
|
-
tokenService;
|
|
34
|
-
constructor(clientFactory) {
|
|
35
|
-
this.clientFactory = clientFactory;
|
|
36
|
-
this.tokenService = new TokenService(clientFactory);
|
|
37
|
-
}
|
|
38
|
-
requireClients() {
|
|
39
|
-
const clients = this.clientFactory.getClients();
|
|
40
|
-
if (!clients.wallet || !clients.accountAddress) {
|
|
41
|
-
throw new Error("No wallet configured. Set CELO_PRIVATE_KEY in the MCP server env.");
|
|
42
|
-
}
|
|
43
|
-
return clients;
|
|
44
|
-
}
|
|
45
|
-
async getMentoClient(publicClient) {
|
|
46
|
-
return Mento.create(ChainId.CELO, publicClient);
|
|
47
|
-
}
|
|
48
|
-
resolveMentoPair(tokenIn, tokenOut) {
|
|
49
|
-
const resolvedIn = this.tokenService.resolveToken(tokenIn);
|
|
50
|
-
const resolvedOut = this.tokenService.resolveToken(tokenOut);
|
|
51
|
-
return {
|
|
52
|
-
resolvedIn,
|
|
53
|
-
resolvedOut,
|
|
54
|
-
mentoIn: toMentoTokenAddress(resolvedIn.address),
|
|
55
|
-
mentoOut: toMentoTokenAddress(resolvedOut.address),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
fxOptions(params) {
|
|
59
|
-
const slippageTolerance = params?.slippageTolerance ?? DEFAULT_SLIPPAGE;
|
|
60
|
-
const deadlineMinutes = params?.deadlineMinutes ?? DEFAULT_DEADLINE_MINUTES;
|
|
61
|
-
return {
|
|
62
|
-
slippageTolerance,
|
|
63
|
-
deadlineMinutes,
|
|
64
|
-
deadline: deadlineFromMinutes(deadlineMinutes),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
formatFxError(error, tokenIn, tokenOut) {
|
|
68
|
-
if (error instanceof RouteNotFoundError) {
|
|
69
|
-
throw new Error(`No Mento FX route for ${tokenIn} → ${tokenOut}.`);
|
|
70
|
-
}
|
|
71
|
-
if (error instanceof FXMarketClosedError) {
|
|
72
|
-
throw new Error("Mento FX market is currently closed. FX quotes and execution are unavailable until the market reopens.");
|
|
73
|
-
}
|
|
74
|
-
if (error instanceof Error && /FXMarketClosed/i.test(error.message)) {
|
|
75
|
-
throw new Error("Mento FX market is currently closed. FX quotes and execution are unavailable until the market reopens.");
|
|
76
|
-
}
|
|
77
|
-
throw error instanceof Error ? error : new Error(String(error));
|
|
78
|
-
}
|
|
79
|
-
toSendParams(params) {
|
|
80
|
-
return {
|
|
81
|
-
to: params.to,
|
|
82
|
-
data: taggedCalldata(params.data),
|
|
83
|
-
value: BigInt(params.value),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
async estimateCallGas(client, from, params) {
|
|
87
|
-
const approve = parseErc20Approve(params);
|
|
88
|
-
if (approve) {
|
|
89
|
-
const gas = await client.estimateContractGas({
|
|
90
|
-
account: from,
|
|
91
|
-
address: approve.token,
|
|
92
|
-
abi: erc20Abi,
|
|
93
|
-
functionName: "approve",
|
|
94
|
-
args: [approve.spender, approve.amount],
|
|
95
|
-
});
|
|
96
|
-
return gas.toString();
|
|
97
|
-
}
|
|
98
|
-
const gas = await client.estimateGas({
|
|
99
|
-
account: from,
|
|
100
|
-
to: params.to,
|
|
101
|
-
data: params.data,
|
|
102
|
-
value: BigInt(params.value),
|
|
103
|
-
});
|
|
104
|
-
return gas.toString();
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Swap gas estimation runs transferFrom; without on-chain approval that reverts.
|
|
108
|
-
* Simulate sufficient allowance via eth_estimateGas stateOverride.
|
|
109
|
-
*/
|
|
110
|
-
async estimateSwapGasWithAllowance(client, from, params, approve) {
|
|
111
|
-
const request = {
|
|
112
|
-
account: from,
|
|
113
|
-
to: params.to,
|
|
114
|
-
data: params.data,
|
|
115
|
-
value: BigInt(params.value),
|
|
116
|
-
};
|
|
117
|
-
for (const mappingSlot of ALLOWANCE_MAPPING_SLOTS) {
|
|
118
|
-
try {
|
|
119
|
-
const gas = await client.estimateGas({
|
|
120
|
-
...request,
|
|
121
|
-
stateOverride: erc20AllowanceStateOverride(approve.token, from, approve.spender, approve.amount, mappingSlot),
|
|
122
|
-
});
|
|
123
|
-
return gas.toString();
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
if (!isLikelyTransferFailed(error)) {
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
throw new Error("Could not estimate Mento FX swap gas: failed to simulate ERC-20 allowance for this token.");
|
|
132
|
-
}
|
|
133
|
-
async executeCall(wallet, publicClient, params) {
|
|
134
|
-
const account = wallet.account;
|
|
135
|
-
if (!account) {
|
|
136
|
-
throw new Error("Wallet account unavailable.");
|
|
137
|
-
}
|
|
138
|
-
const chain = publicClient.chain;
|
|
139
|
-
if (!chain) {
|
|
140
|
-
throw new Error("Chain configuration missing.");
|
|
141
|
-
}
|
|
142
|
-
const approve = parseErc20Approve(params);
|
|
143
|
-
if (approve) {
|
|
144
|
-
return wallet.writeContract({
|
|
145
|
-
chain,
|
|
146
|
-
account,
|
|
147
|
-
address: approve.token,
|
|
148
|
-
abi: erc20Abi,
|
|
149
|
-
functionName: "approve",
|
|
150
|
-
args: [approve.spender, approve.amount],
|
|
151
|
-
dataSuffix: CELINA_DATA_SUFFIX,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return wallet.sendTransaction({
|
|
155
|
-
chain,
|
|
156
|
-
account,
|
|
157
|
-
...this.toSendParams(params),
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
baseQuoteFields(resolvedIn, resolvedOut, amount, expectedOutWei, routeHops) {
|
|
161
|
-
return {
|
|
162
|
-
protocol: "mento_fx",
|
|
163
|
-
network: "mainnet",
|
|
164
|
-
tokenIn: resolvedIn.symbol,
|
|
165
|
-
tokenOut: resolvedOut.symbol,
|
|
166
|
-
amountIn: amount,
|
|
167
|
-
expectedOut: formatUnits(expectedOutWei, resolvedOut.decimals),
|
|
168
|
-
routeHops,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async getFxQuote(tokenIn, tokenOut, amount) {
|
|
172
|
-
const { public: client } = this.clientFactory.getClients();
|
|
173
|
-
const { resolvedIn, resolvedOut, mentoIn, mentoOut } = this.resolveMentoPair(tokenIn, tokenOut);
|
|
174
|
-
const amountInWei = this.tokenService.parseAmount(amount, resolvedIn.decimals);
|
|
175
|
-
try {
|
|
176
|
-
const mento = await this.getMentoClient(client);
|
|
177
|
-
const [expectedOutWei, route] = await Promise.all([
|
|
178
|
-
mento.quotes.getAmountOut(mentoIn, mentoOut, amountInWei),
|
|
179
|
-
mento.routes.findRoute(mentoIn, mentoOut),
|
|
180
|
-
]);
|
|
181
|
-
return this.baseQuoteFields(resolvedIn, resolvedOut, amount, expectedOutWei, route.path.length);
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
this.formatFxError(error, resolvedIn.symbol, resolvedOut.symbol);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async estimateFx(tokenIn, tokenOut, amount, params) {
|
|
188
|
-
const { public: client, accountAddress: from } = this.requireClients();
|
|
189
|
-
if (!from) {
|
|
190
|
-
throw new Error("Wallet address unavailable.");
|
|
191
|
-
}
|
|
192
|
-
const { resolvedIn, resolvedOut, mentoIn, mentoOut } = this.resolveMentoPair(tokenIn, tokenOut);
|
|
193
|
-
const recipient = params?.recipient ?? from;
|
|
194
|
-
const amountInWei = this.tokenService.parseAmount(amount, resolvedIn.decimals);
|
|
195
|
-
const { slippageTolerance, deadlineMinutes, deadline } = this.fxOptions(params);
|
|
196
|
-
try {
|
|
197
|
-
const mento = await this.getMentoClient(client);
|
|
198
|
-
const { approval, swap } = await mento.swap.buildSwapTransaction(mentoIn, mentoOut, amountInWei, recipient, from, { slippageTolerance, deadline });
|
|
199
|
-
const approvalParsed = approval ? parseErc20Approve(approval) : null;
|
|
200
|
-
const approvalGas = approval
|
|
201
|
-
? await this.estimateCallGas(client, from, approval)
|
|
202
|
-
: undefined;
|
|
203
|
-
const fxGas = approvalParsed !== null
|
|
204
|
-
? await this.estimateSwapGasWithAllowance(client, from, swap.params, approvalParsed)
|
|
205
|
-
: await this.estimateCallGas(client, from, swap.params);
|
|
206
|
-
return {
|
|
207
|
-
...this.baseQuoteFields(resolvedIn, resolvedOut, amount, swap.expectedAmountOut, swap.route.path.length),
|
|
208
|
-
from,
|
|
209
|
-
recipient,
|
|
210
|
-
amountOutMin: formatUnits(swap.amountOutMin, resolvedOut.decimals),
|
|
211
|
-
approvalNeeded: approval !== null,
|
|
212
|
-
approvalGas,
|
|
213
|
-
fxGas,
|
|
214
|
-
slippageTolerance,
|
|
215
|
-
deadline: deadline.toString(),
|
|
216
|
-
deadlineMinutes,
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
this.formatFxError(error, resolvedIn.symbol, resolvedOut.symbol);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
async executeFx(tokenIn, tokenOut, amount, params) {
|
|
224
|
-
const { public: client, wallet, accountAddress: from } = this.requireClients();
|
|
225
|
-
if (!wallet || !from) {
|
|
226
|
-
throw new Error("Wallet client unavailable. Set CELO_PRIVATE_KEY in the MCP server env.");
|
|
227
|
-
}
|
|
228
|
-
const { resolvedIn, resolvedOut, mentoIn, mentoOut } = this.resolveMentoPair(tokenIn, tokenOut);
|
|
229
|
-
const recipient = params?.recipient ?? from;
|
|
230
|
-
const amountInWei = this.tokenService.parseAmount(amount, resolvedIn.decimals);
|
|
231
|
-
const { slippageTolerance, deadlineMinutes, deadline } = this.fxOptions(params);
|
|
232
|
-
try {
|
|
233
|
-
const mento = await this.getMentoClient(client);
|
|
234
|
-
const { approval, swap } = await mento.swap.buildSwapTransaction(mentoIn, mentoOut, amountInWei, recipient, from, { slippageTolerance, deadline });
|
|
235
|
-
let approvalHash;
|
|
236
|
-
if (approval) {
|
|
237
|
-
approvalHash = await this.executeCall(wallet, client, approval);
|
|
238
|
-
await client.waitForTransactionReceipt({ hash: approvalHash });
|
|
239
|
-
}
|
|
240
|
-
const hash = await this.executeCall(wallet, client, swap.params);
|
|
241
|
-
const receipt = await client.waitForTransactionReceipt({ hash });
|
|
242
|
-
return {
|
|
243
|
-
...this.baseQuoteFields(resolvedIn, resolvedOut, amount, swap.expectedAmountOut, swap.route.path.length),
|
|
244
|
-
from,
|
|
245
|
-
recipient,
|
|
246
|
-
amountOutMin: formatUnits(swap.amountOutMin, resolvedOut.decimals),
|
|
247
|
-
approvalNeeded: approval !== null,
|
|
248
|
-
approvalHash,
|
|
249
|
-
hash,
|
|
250
|
-
status: receipt.status,
|
|
251
|
-
slippageTolerance,
|
|
252
|
-
deadline: deadline.toString(),
|
|
253
|
-
deadlineMinutes,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
this.formatFxError(error, resolvedIn.symbol, resolvedOut.symbol);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
//# sourceMappingURL=mento-fx.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mento-fx.service.js","sourceRoot":"","sources":["../../src/services/mento-fx.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAY,MAAM,MAAM,CAAC;AACnF,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,KAAK,EACL,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM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AAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAChE,MAAM,MAAM,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YACjE,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACjE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;YAEjE,OAAO;gBACL,GAAG,IAAI,CAAC,eAAe,CACrB,UAAU,EACV,WAAW,EACX,MAAM,EACN,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CACvB;gBACD,IAAI;gBACJ,SAAS;gBACT,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,QAAQ,CAAC;gBAClE,cAAc,EAAE,QAAQ,KAAK,IAAI;gBACjC,YAAY;gBACZ,IAAI;gBACJ,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,iBAAiB;gBACjB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;gBAC7B,eAAe;aAChB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { type Hex } from "viem";
|
|
2
|
-
import type { SelfRegistrationMode } from "../config/self.js";
|
|
3
|
-
import type { CeloClientFactory } from "../clients/celo-client.js";
|
|
4
|
-
export interface VerifySelfAgentParams {
|
|
5
|
-
agentAddress: `0x${string}`;
|
|
6
|
-
requireAge?: 0 | 18 | 21;
|
|
7
|
-
requireOfac?: boolean;
|
|
8
|
-
requireSelfProvider?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface VerifySelfRequestParams {
|
|
11
|
-
agentSignature: Hex;
|
|
12
|
-
agentTimestamp: string;
|
|
13
|
-
method: string;
|
|
14
|
-
path: string;
|
|
15
|
-
body?: string;
|
|
16
|
-
keytype?: string;
|
|
17
|
-
agentKey?: Hex;
|
|
18
|
-
}
|
|
19
|
-
export interface RegisterSelfAgentParams {
|
|
20
|
-
mode?: SelfRegistrationMode;
|
|
21
|
-
minimumAge?: 0 | 18 | 21;
|
|
22
|
-
ofac?: boolean;
|
|
23
|
-
humanAddress?: `0x${string}`;
|
|
24
|
-
agentName?: string;
|
|
25
|
-
agentDescription?: string;
|
|
26
|
-
}
|
|
27
|
-
export declare class SelfService {
|
|
28
|
-
private readonly clientFactory;
|
|
29
|
-
private readonly envSelfAgentPrivateKey?;
|
|
30
|
-
constructor(clientFactory: CeloClientFactory, envSelfAgentPrivateKey?: `0x${string}` | undefined);
|
|
31
|
-
private resolveAgentPrivateKey;
|
|
32
|
-
private registryClient;
|
|
33
|
-
private assertProofRefreshEligible;
|
|
34
|
-
verifyAgent(params: VerifySelfAgentParams): Promise<{
|
|
35
|
-
verified: boolean;
|
|
36
|
-
agent_address: `0x${string}`;
|
|
37
|
-
reason: string;
|
|
38
|
-
network: "mainnet";
|
|
39
|
-
} | {
|
|
40
|
-
verification_strength: string;
|
|
41
|
-
network: "mainnet";
|
|
42
|
-
sibling_agent_ids: number[];
|
|
43
|
-
proof_expires_at: string | null;
|
|
44
|
-
days_until_expiry: number;
|
|
45
|
-
is_expiring_soon: boolean;
|
|
46
|
-
verified: boolean;
|
|
47
|
-
agent_address: `0x${string}`;
|
|
48
|
-
agent_id: number;
|
|
49
|
-
reason: string;
|
|
50
|
-
credentials: {
|
|
51
|
-
nationality: string | undefined;
|
|
52
|
-
older_than: number;
|
|
53
|
-
ofac_clear: boolean;
|
|
54
|
-
};
|
|
55
|
-
} | {
|
|
56
|
-
verification_strength: string;
|
|
57
|
-
registered_at: number;
|
|
58
|
-
agent_count: number;
|
|
59
|
-
is_proof_fresh: boolean;
|
|
60
|
-
network: "mainnet";
|
|
61
|
-
sibling_agent_ids: number[];
|
|
62
|
-
proof_expires_at: string | null;
|
|
63
|
-
days_until_expiry: number;
|
|
64
|
-
is_expiring_soon: boolean;
|
|
65
|
-
verified: boolean;
|
|
66
|
-
agent_address: `0x${string}`;
|
|
67
|
-
agent_id: number;
|
|
68
|
-
credentials: {
|
|
69
|
-
nationality: string | undefined;
|
|
70
|
-
older_than: number;
|
|
71
|
-
ofac_clear: boolean;
|
|
72
|
-
};
|
|
73
|
-
reason?: undefined;
|
|
74
|
-
}>;
|
|
75
|
-
lookupAgent(agentId: number): Promise<{
|
|
76
|
-
is_expired: boolean;
|
|
77
|
-
network: "mainnet";
|
|
78
|
-
proof_expires_at: string | null;
|
|
79
|
-
days_until_expiry: number;
|
|
80
|
-
is_expiring_soon: boolean;
|
|
81
|
-
credentialsSummary: string;
|
|
82
|
-
}>;
|
|
83
|
-
verifyRequest(params: VerifySelfRequestParams): Promise<{
|
|
84
|
-
valid: boolean;
|
|
85
|
-
reason: string;
|
|
86
|
-
agent_address?: undefined;
|
|
87
|
-
agent_id?: undefined;
|
|
88
|
-
agent_count?: undefined;
|
|
89
|
-
nullifier?: undefined;
|
|
90
|
-
credentials?: undefined;
|
|
91
|
-
note?: undefined;
|
|
92
|
-
} | {
|
|
93
|
-
valid: boolean;
|
|
94
|
-
agent_address: `0x${string}`;
|
|
95
|
-
reason: string;
|
|
96
|
-
agent_id?: undefined;
|
|
97
|
-
agent_count?: undefined;
|
|
98
|
-
nullifier?: undefined;
|
|
99
|
-
credentials?: undefined;
|
|
100
|
-
note?: undefined;
|
|
101
|
-
} | {
|
|
102
|
-
valid: boolean;
|
|
103
|
-
agent_address: `0x${string}`;
|
|
104
|
-
agent_id: number;
|
|
105
|
-
reason: string;
|
|
106
|
-
agent_count?: undefined;
|
|
107
|
-
nullifier?: undefined;
|
|
108
|
-
credentials?: undefined;
|
|
109
|
-
note?: undefined;
|
|
110
|
-
} | {
|
|
111
|
-
valid: boolean;
|
|
112
|
-
agent_address: `0x${string}`;
|
|
113
|
-
agent_id: number;
|
|
114
|
-
agent_count: number;
|
|
115
|
-
nullifier: number;
|
|
116
|
-
credentials: {
|
|
117
|
-
nationality: string | undefined;
|
|
118
|
-
older_than: number;
|
|
119
|
-
ofac_clear: boolean;
|
|
120
|
-
};
|
|
121
|
-
note: string;
|
|
122
|
-
reason?: undefined;
|
|
123
|
-
}>;
|
|
124
|
-
private getAgentInfoFromKey;
|
|
125
|
-
getIdentity(): Promise<{
|
|
126
|
-
expiry_warning?: string | undefined;
|
|
127
|
-
is_expired: boolean;
|
|
128
|
-
sibling_agent_ids: number[];
|
|
129
|
-
network: "mainnet";
|
|
130
|
-
proof_expires_at: string | null;
|
|
131
|
-
days_until_expiry: number;
|
|
132
|
-
is_expiring_soon: boolean;
|
|
133
|
-
registered: true;
|
|
134
|
-
address: `0x${string}`;
|
|
135
|
-
agentKey: `0x${string}`;
|
|
136
|
-
agentId: number;
|
|
137
|
-
isVerified: boolean;
|
|
138
|
-
nullifier: number;
|
|
139
|
-
agentCount: number;
|
|
140
|
-
verificationStrength: string;
|
|
141
|
-
credentials_summary: string;
|
|
142
|
-
} | {
|
|
143
|
-
message: string;
|
|
144
|
-
registered: false;
|
|
145
|
-
address: `0x${string}`;
|
|
146
|
-
network: "mainnet";
|
|
147
|
-
}>;
|
|
148
|
-
registerAgent(params?: RegisterSelfAgentParams): Promise<{
|
|
149
|
-
session_id: string;
|
|
150
|
-
agent_address: string;
|
|
151
|
-
qr_url: string;
|
|
152
|
-
deep_link: string;
|
|
153
|
-
expires_at: string;
|
|
154
|
-
instructions: string;
|
|
155
|
-
next_step: string;
|
|
156
|
-
}>;
|
|
157
|
-
checkRegistration(sessionId: string): Promise<{
|
|
158
|
-
status: "deregistered";
|
|
159
|
-
message: string;
|
|
160
|
-
proof_expires_at?: undefined;
|
|
161
|
-
agent_id?: undefined;
|
|
162
|
-
agent_address?: undefined;
|
|
163
|
-
private_key_hex?: undefined;
|
|
164
|
-
tx_hash?: undefined;
|
|
165
|
-
} | {
|
|
166
|
-
status: "refreshed";
|
|
167
|
-
proof_expires_at: string;
|
|
168
|
-
message: string;
|
|
169
|
-
agent_id?: undefined;
|
|
170
|
-
agent_address?: undefined;
|
|
171
|
-
private_key_hex?: undefined;
|
|
172
|
-
tx_hash?: undefined;
|
|
173
|
-
} | {
|
|
174
|
-
status: "verified";
|
|
175
|
-
agent_id: number;
|
|
176
|
-
agent_address: string;
|
|
177
|
-
private_key_hex: string;
|
|
178
|
-
tx_hash: string | undefined;
|
|
179
|
-
message: string;
|
|
180
|
-
proof_expires_at?: undefined;
|
|
181
|
-
} | {
|
|
182
|
-
status: "pending";
|
|
183
|
-
message: string;
|
|
184
|
-
proof_expires_at?: undefined;
|
|
185
|
-
agent_id?: undefined;
|
|
186
|
-
agent_address?: undefined;
|
|
187
|
-
private_key_hex?: undefined;
|
|
188
|
-
tx_hash?: undefined;
|
|
189
|
-
} | {
|
|
190
|
-
status: "expired";
|
|
191
|
-
message: string;
|
|
192
|
-
proof_expires_at?: undefined;
|
|
193
|
-
agent_id?: undefined;
|
|
194
|
-
agent_address?: undefined;
|
|
195
|
-
private_key_hex?: undefined;
|
|
196
|
-
tx_hash?: undefined;
|
|
197
|
-
}>;
|
|
198
|
-
refreshProof(params?: {
|
|
199
|
-
agentId?: number;
|
|
200
|
-
}): Promise<{
|
|
201
|
-
next_step: string;
|
|
202
|
-
is_expired: boolean;
|
|
203
|
-
is_proof_fresh: false;
|
|
204
|
-
proof_expires_at: string | null;
|
|
205
|
-
days_until_expiry: number;
|
|
206
|
-
is_expiring_soon: boolean;
|
|
207
|
-
session_id: string;
|
|
208
|
-
agent_id: number;
|
|
209
|
-
qr_url: string;
|
|
210
|
-
deep_link: string;
|
|
211
|
-
expires_at: string;
|
|
212
|
-
instructions: string;
|
|
213
|
-
}>;
|
|
214
|
-
deregisterAgent(): Promise<{
|
|
215
|
-
session_id: string;
|
|
216
|
-
qr_url: string;
|
|
217
|
-
deep_link: string;
|
|
218
|
-
expires_at: string;
|
|
219
|
-
instructions: string;
|
|
220
|
-
warning: string;
|
|
221
|
-
next_step: string;
|
|
222
|
-
}>;
|
|
223
|
-
signRequest(params: {
|
|
224
|
-
method: string;
|
|
225
|
-
url: string;
|
|
226
|
-
body?: string;
|
|
227
|
-
}): Promise<{
|
|
228
|
-
headers: {
|
|
229
|
-
"x-self-agent-address": `0x${string}`;
|
|
230
|
-
"x-self-agent-signature": `0x${string}`;
|
|
231
|
-
"x-self-agent-timestamp": string;
|
|
232
|
-
};
|
|
233
|
-
instructions: string;
|
|
234
|
-
}>;
|
|
235
|
-
authenticatedFetch(params: {
|
|
236
|
-
method: string;
|
|
237
|
-
url: string;
|
|
238
|
-
body?: string;
|
|
239
|
-
contentType?: string;
|
|
240
|
-
}): Promise<{
|
|
241
|
-
status: number;
|
|
242
|
-
body: string;
|
|
243
|
-
truncated: boolean;
|
|
244
|
-
}>;
|
|
245
|
-
/** Reserved for future on-chain Self writes (e.g. metadata updates). */
|
|
246
|
-
protected taggedCalldata(data: Hex): Hex;
|
|
247
|
-
}
|