@andrewkimjoseph/celina-sdk 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +6 -1
  2. package/build/abis/gooddollar-broker.d.ts +77 -0
  3. package/build/abis/gooddollar-broker.js +44 -0
  4. package/build/abis/gooddollar-broker.js.map +1 -0
  5. package/build/analytics/mcp-tool-events.js +2 -0
  6. package/build/analytics/mcp-tool-events.js.map +1 -1
  7. package/build/config/gooddollar.d.ts +12 -0
  8. package/build/config/gooddollar.js +19 -0
  9. package/build/config/gooddollar.js.map +1 -1
  10. package/build/index.d.ts +3 -2
  11. package/build/index.js +1 -1
  12. package/build/index.js.map +1 -1
  13. package/build/services/ens.service.d.ts +1 -1
  14. package/build/services/ens.service.js +1 -1
  15. package/build/services/gooddollar.service.d.ts +32 -1
  16. package/build/services/gooddollar.service.js +214 -4
  17. package/build/services/gooddollar.service.js.map +1 -1
  18. package/build/services/transaction.service.d.ts +1 -1
  19. package/build/services/transaction.service.js +1 -1
  20. package/build/tools/catalog.d.ts +1 -1
  21. package/build/tools/catalog.js +2 -2
  22. package/build/tools/domains/aave.js +2 -2
  23. package/build/tools/domains/browser.d.ts +2 -0
  24. package/build/tools/domains/{celeste.js → browser.js} +7 -7
  25. package/build/tools/domains/browser.js.map +1 -0
  26. package/build/tools/domains/gooddollar.js +32 -2
  27. package/build/tools/domains/gooddollar.js.map +1 -1
  28. package/build/tools/domains/index.js +2 -2
  29. package/build/tools/domains/mento-fx.js +1 -1
  30. package/build/tools/domains/transaction.js +1 -1
  31. package/build/tools/domains/uniswap.js +1 -1
  32. package/build/tools/filter.js +1 -1
  33. package/build/tools/index.d.ts +1 -1
  34. package/build/tools/index.js +1 -1
  35. package/build/tools/schemas/common.d.ts +39 -0
  36. package/build/tools/schemas/common.js +11 -1
  37. package/build/tools/schemas/common.js.map +1 -1
  38. package/build/tools/swap-routing.d.ts +2 -2
  39. package/build/tools/swap-routing.js +68 -7
  40. package/build/tools/swap-routing.js.map +1 -1
  41. package/build/tools/types.d.ts +1 -1
  42. package/build/types/prepared.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/tests/catalog/domains/defi.ts +135 -0
  45. package/tests/testing-entry.ts +1 -1
  46. package/build/tools/domains/celeste.d.ts +0 -2
  47. package/build/tools/domains/celeste.js.map +0 -1
package/README.md CHANGED
@@ -28,11 +28,16 @@ npm i @andrewkimjoseph/celina-sdk
28
28
 
29
29
  Requires Node.js ≥ 20.
30
30
 
31
+ ### LLM tool catalog (v0.5+)
32
+
33
+ For MCP servers and chat APIs (Vercel AI SDK, etc.), import shared tool definitions from `@andrewkimjoseph/celina-sdk/tools` instead of redefining schemas. See [LLM tool catalog](docs/guides/tool-catalog.md) — includes the recommended **`dynamicTool`** pattern so TypeScript does not OOM on large tool sets.
34
+
31
35
  ## Documentation
32
36
 
33
37
  **Full docs:** [celina-sdk on GitBook](https://andrewkimjoseph.gitbook.io/celina-sdk)
34
38
 
35
39
  - [Quick start](https://andrewkimjoseph.gitbook.io/celina-sdk/getting-started/quick-start)
40
+ - [LLM tool catalog](docs/guides/tool-catalog.md) — `@andrewkimjoseph/celina-sdk/tools` for MCP and AI SDK hosts
36
41
  - [Architecture](docs/concepts/architecture.md) — client composition and stack
37
42
  - [Prepared flows](docs/concepts/prepared-flows.md) — `SerializedPreparedFlow`, CELINA calldata tag
38
43
  - [wagmi integration](https://andrewkimjoseph.gitbook.io/celina-sdk/guides/wagmi-integration)
@@ -54,7 +59,7 @@ const celina = createCelinaClient();
54
59
  await celina.token.getStablecoinBalances("0xYourAddress");
55
60
 
56
61
  const flow = await celina.transaction.prepareSend("0xFrom", "0xTo", "USDm", "10");
57
- // flow.steps → pass to wagmi sendTransaction (calldata includes CELINA attribution suffix)
62
+ // flow.steps → pass to wagmi sendTransactionAsync (calldata includes CELINA attribution suffix)
58
63
 
59
64
  // Carbon DeFi (reads + unsigned strategy/trade prep)
60
65
  const strategies = await celina.carbon.getStrategies("0xYourAddress");
@@ -0,0 +1,77 @@
1
+ /** GoodDollar MentoBroker on Celo — reserve swap quotes and execution. */
2
+ export declare const goodDollarBrokerAbi: readonly [{
3
+ readonly type: "function";
4
+ readonly name: "getAmountOut";
5
+ readonly inputs: readonly [{
6
+ readonly name: "exchangeProvider";
7
+ readonly type: "address";
8
+ }, {
9
+ readonly name: "exchangeId";
10
+ readonly type: "bytes32";
11
+ }, {
12
+ readonly name: "tokenIn";
13
+ readonly type: "address";
14
+ }, {
15
+ readonly name: "tokenOut";
16
+ readonly type: "address";
17
+ }, {
18
+ readonly name: "amountIn";
19
+ readonly type: "uint256";
20
+ }];
21
+ readonly outputs: readonly [{
22
+ readonly name: "";
23
+ readonly type: "uint256";
24
+ }];
25
+ readonly stateMutability: "view";
26
+ }, {
27
+ readonly type: "function";
28
+ readonly name: "getAmountIn";
29
+ readonly inputs: readonly [{
30
+ readonly name: "exchangeProvider";
31
+ readonly type: "address";
32
+ }, {
33
+ readonly name: "exchangeId";
34
+ readonly type: "bytes32";
35
+ }, {
36
+ readonly name: "tokenIn";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly name: "tokenOut";
40
+ readonly type: "address";
41
+ }, {
42
+ readonly name: "amountOut";
43
+ readonly type: "uint256";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly name: "";
47
+ readonly type: "uint256";
48
+ }];
49
+ readonly stateMutability: "view";
50
+ }, {
51
+ readonly type: "function";
52
+ readonly name: "swapIn";
53
+ readonly inputs: readonly [{
54
+ readonly name: "exchangeProvider";
55
+ readonly type: "address";
56
+ }, {
57
+ readonly name: "exchangeId";
58
+ readonly type: "bytes32";
59
+ }, {
60
+ readonly name: "tokenIn";
61
+ readonly type: "address";
62
+ }, {
63
+ readonly name: "tokenOut";
64
+ readonly type: "address";
65
+ }, {
66
+ readonly name: "amountIn";
67
+ readonly type: "uint256";
68
+ }, {
69
+ readonly name: "amountOutMin";
70
+ readonly type: "uint256";
71
+ }];
72
+ readonly outputs: readonly [{
73
+ readonly name: "amountOut";
74
+ readonly type: "uint256";
75
+ }];
76
+ readonly stateMutability: "nonpayable";
77
+ }];
@@ -0,0 +1,44 @@
1
+ /** GoodDollar MentoBroker on Celo — reserve swap quotes and execution. */
2
+ export const goodDollarBrokerAbi = [
3
+ {
4
+ type: "function",
5
+ name: "getAmountOut",
6
+ inputs: [
7
+ { name: "exchangeProvider", type: "address" },
8
+ { name: "exchangeId", type: "bytes32" },
9
+ { name: "tokenIn", type: "address" },
10
+ { name: "tokenOut", type: "address" },
11
+ { name: "amountIn", type: "uint256" },
12
+ ],
13
+ outputs: [{ name: "", type: "uint256" }],
14
+ stateMutability: "view",
15
+ },
16
+ {
17
+ type: "function",
18
+ name: "getAmountIn",
19
+ inputs: [
20
+ { name: "exchangeProvider", type: "address" },
21
+ { name: "exchangeId", type: "bytes32" },
22
+ { name: "tokenIn", type: "address" },
23
+ { name: "tokenOut", type: "address" },
24
+ { name: "amountOut", type: "uint256" },
25
+ ],
26
+ outputs: [{ name: "", type: "uint256" }],
27
+ stateMutability: "view",
28
+ },
29
+ {
30
+ type: "function",
31
+ name: "swapIn",
32
+ inputs: [
33
+ { name: "exchangeProvider", type: "address" },
34
+ { name: "exchangeId", type: "bytes32" },
35
+ { name: "tokenIn", type: "address" },
36
+ { name: "tokenOut", type: "address" },
37
+ { name: "amountIn", type: "uint256" },
38
+ { name: "amountOutMin", type: "uint256" },
39
+ ],
40
+ outputs: [{ name: "amountOut", type: "uint256" }],
41
+ stateMutability: "nonpayable",
42
+ },
43
+ ];
44
+ //# sourceMappingURL=gooddollar-broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gooddollar-broker.js","sourceRoot":"","sources":["../../src/abis/gooddollar-broker.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE;YAC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AAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;YACrC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE;SAC1C;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjD,eAAe,EAAE,YAAY;KAC9B;CACO,CAAC"}
@@ -25,6 +25,8 @@ export const MCP_TOOL_EVENT_BY_SDK_METHOD = {
25
25
  "contract.callFunction": "call_contract_function",
26
26
  "contract.estimateGas": "estimate_contract_gas",
27
27
  "ens.resolveEns": "resolve_ens",
28
+ "gooddollar.getReserveQuote.buy": "get_gooddollar_reserve_quote",
29
+ "gooddollar.getReserveQuote.sell": "get_gooddollar_reserve_quote",
28
30
  "gooddollar.getUbiClaimEligibility": "get_gooddollar_ubi_entitlement",
29
31
  "gooddollar.getWhitelistingInfo": "get_gooddollar_whitelisting_info",
30
32
  "governance.getGovernanceProposals": "get_governance_proposals",
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-tool-events.js","sourceRoot":"","sources":["../../src/analytics/mcp-tool-events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAqC;IAC5E,oBAAoB,EAAE,aAAa;IACnC,0BAA0B,EAAE,oBAAoB;IAChD,qBAAqB,EAAE,WAAW;IAClC,qCAAqC,EAAE,WAAW;IAClD,4BAA4B,EAAE,mBAAmB;IACjD,6BAA6B,EAAE,oBAAoB;IACnD,2BAA2B,EAAE,iBAAiB;IAC9C,oBAAoB,EAAE,qBAAqB;IAC3C,0BAA0B,EAAE,2BAA2B;IACvD,oBAAoB,EAAE,qBAAqB;IAC3C,wBAAwB,EAAE,0BAA0B;IACpD,yBAAyB,EAAE,2BAA2B;IACtD,sBAAsB,EAAE,uBAAuB;IAC/C,oBAAoB,EAAE,qBAAqB;IAC3C,sBAAsB,EAAE,wBAAwB;IAChD,aAAa,EAAE,aAAa;I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mB;IACxC,6BAA6B,EAAE,yBAAyB;IACxD,uBAAuB,EAAE,mBAAmB;IAC5C,oBAAoB,EAAE,gBAAgB;IACtC,0BAA0B,EAAE,eAAe;IAC3C,iCAAiC,EAAE,sBAAsB;IACzD,2BAA2B,EAAE,kBAAkB;IAC/C,sBAAsB,EAAE,uBAAuB;IAC/C,sBAAsB,EAAE,mBAAmB;CACnC,CAAC"}
@@ -2,3 +2,15 @@
2
2
  export declare const GOODDOLLAR_IDENTITY_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
3
3
  /** GoodDollar UBISchemeV2 contract on Celo mainnet. */
4
4
  export declare const GOODDOLLAR_UBI_SCHEME_ADDRESS: "0x43d72Ff17701B2DA814620735C39C620Ce0ea4A1";
5
+ /** GoodDollar G$ token on Celo mainnet (SuperGoodDollar). */
6
+ export declare const GOODDOLLAR_TOKEN_ADDRESS: "0x62B8B11039FcfE5aB0C56E502b1C372A3d2a9c7A";
7
+ /** MentoBroker proxy — user-facing entry for G$ reserve swaps on Celo. */
8
+ export declare const GOODDOLLAR_MENTO_BROKER: "0x88de45906D4F5a57315c133620cfa484cB297541";
9
+ /** GoodDollar MentoExchangeProvider on Celo mainnet. */
10
+ export declare const GOODDOLLAR_MENTO_EXCHANGE_PROVIDER: "0x2fFBB49055d487DdBBb0C052Cd7c2a02A7971e41";
11
+ /** Exchange pool id for G$ ↔ USDm (CUSD in GoodProtocol deployment). */
12
+ export declare const GOODDOLLAR_CUSD_EXCHANGE_ID: "0xba77f5c7bb3317643c6d81d1ef3f9913561741d92095f88efa402faf2cbe9124";
13
+ /** Reserve collateral token (USDm / cUSD) for the G$ pool on Celo. */
14
+ export declare const GOODDOLLAR_RESERVE_COLLATERAL: "0x765DE816845861e75A25fCA122bb6898B8B1282a";
15
+ /** Whether both tokens form a supported GoodDollar reserve pair (G$ ↔ USDm). */
16
+ export declare function isGoodDollarUsdReservePair(tokenIn: string, tokenOut: string): boolean;
@@ -2,4 +2,23 @@
2
2
  export const GOODDOLLAR_IDENTITY_ADDRESS = "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
3
3
  /** GoodDollar UBISchemeV2 contract on Celo mainnet. */
4
4
  export const GOODDOLLAR_UBI_SCHEME_ADDRESS = "0x43d72Ff17701B2DA814620735C39C620Ce0ea4A1";
5
+ /** GoodDollar G$ token on Celo mainnet (SuperGoodDollar). */
6
+ export const GOODDOLLAR_TOKEN_ADDRESS = "0x62B8B11039FcfE5aB0C56E502b1C372A3d2a9c7A";
7
+ /** MentoBroker proxy — user-facing entry for G$ reserve swaps on Celo. */
8
+ export const GOODDOLLAR_MENTO_BROKER = "0x88de45906D4F5a57315c133620cfa484cB297541";
9
+ /** GoodDollar MentoExchangeProvider on Celo mainnet. */
10
+ export const GOODDOLLAR_MENTO_EXCHANGE_PROVIDER = "0x2fFBB49055d487DdBBb0C052Cd7c2a02A7971e41";
11
+ /** Exchange pool id for G$ ↔ USDm (CUSD in GoodProtocol deployment). */
12
+ export const GOODDOLLAR_CUSD_EXCHANGE_ID = "0xba77f5c7bb3317643c6d81d1ef3f9913561741d92095f88efa402faf2cbe9124";
13
+ /** Reserve collateral token (USDm / cUSD) for the G$ pool on Celo. */
14
+ export const GOODDOLLAR_RESERVE_COLLATERAL = "0x765DE816845861e75A25fCA122bb6898B8B1282a";
15
+ const GOODDOLLAR_SYMBOLS = new Set(["gooddollar", "g$"]);
16
+ const RESERVE_COLLATERAL_SYMBOLS = new Set(["usdm", "cusd"]);
17
+ /** Whether both tokens form a supported GoodDollar reserve pair (G$ ↔ USDm). */
18
+ export function isGoodDollarUsdReservePair(tokenIn, tokenOut) {
19
+ const a = tokenIn.trim().toLowerCase();
20
+ const b = tokenOut.trim().toLowerCase();
21
+ return ((GOODDOLLAR_SYMBOLS.has(a) && RESERVE_COLLATERAL_SYMBOLS.has(b)) ||
22
+ (GOODDOLLAR_SYMBOLS.has(b) && RESERVE_COLLATERAL_SYMBOLS.has(a)));
23
+ }
5
24
  //# sourceMappingURL=gooddollar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gooddollar.js","sourceRoot":"","sources":["../../src/config/gooddollar.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,CAAC,MAAM,2BAA2B,GACtC,4CAAqD,CAAC;AAExD,uDAAuD;AACvD,MAAM,CAAC,MAAM,6BAA6B,GACxC,4CAAqD,CAAC"}
1
+ {"version":3,"file":"gooddollar.js","sourceRoot":"","sources":["../../src/config/gooddollar.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,CAAC,MAAM,2BAA2B,GACtC,4CAAqD,CAAC;AAExD,uDAAuD;AACvD,MAAM,CAAC,MAAM,6BAA6B,GACxC,4CAAqD,CAAC;AAExD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,wBAAwB,GACnC,4CAAqD,CAAC;AAExD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,uBAAuB,GAClC,4CAAqD,CAAC;AAExD,wDAAwD;AACxD,MAAM,CAAC,MAAM,kCAAkC,GAC7C,4CAAqD,CAAC;AAExD,wEAAwE;AACxE,MAAM,CAAC,MAAM,2BAA2B,GACtC,oEAA6E,CAAC;AAEhF,sEAAsE;AACtE,MAAM,CAAC,MAAM,6BAA6B,GACxC,4CAAqD,CAAC;AAExD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACzD,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7D,gFAAgF;AAChF,MAAM,UAAU,0BAA0B,CAAC,OAAe,EAAE,QAAgB;IAC1E,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvC,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,CACL,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACjE,CAAC;AACJ,CAAC"}
package/build/index.d.ts CHANGED
@@ -32,7 +32,7 @@ export interface CelinaClient {
32
32
  uniswap: UniswapService;
33
33
  /** Aave V3 `prepareSupply` and `prepareWithdraw` flows on Celo. */
34
34
  aave: AaveService;
35
- /** GoodDollar IdentityV4 whitelist status and daily UBI claim preparation. */
35
+ /** GoodDollar IdentityV4 whitelist, UBI claims, and G$ USDm reserve swaps. */
36
36
  gooddollar: GoodDollarService;
37
37
  /** Celo and Ethereum ENS resolution. */
38
38
  ens: EnsService;
@@ -81,7 +81,8 @@ export { AAVE_POOL, AAVE_SUPPORTED_SYMBOLS, resolveAaveAsset, } from "./config/a
81
81
  export { CHAIN, DEFAULT_RPC_URL } from "./config/chains.js";
82
82
  export { appendCelinaCalldataTag, CELINA_DATA_SUFFIX, } from "./config/celina-tag.js";
83
83
  export type { AaveAsset } from "./config/aave.js";
84
- export { GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, } from "./config/gooddollar.js";
84
+ export { GOODDOLLAR_CUSD_EXCHANGE_ID, GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_MENTO_BROKER, GOODDOLLAR_MENTO_EXCHANGE_PROVIDER, GOODDOLLAR_RESERVE_COLLATERAL, GOODDOLLAR_TOKEN_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, isGoodDollarUsdReservePair, } from "./config/gooddollar.js";
85
+ export type { GoodDollarReserveSwapParams } from "./services/gooddollar.service.js";
85
86
  export type { CarbonPrepareResult, CarbonRestSuccess, } from "./types/carbon.js";
86
87
  export type { CarbonWriteBody } from "./services/carbon.service.js";
87
88
  export { CARBON_APP_BASE_URL, CARBON_CHAIN, CELO_CARBON_CONTRACTS, DEFAULT_CARBON_REST_BASE_URL, carbonActivityDeepLink, } from "./config/carbon.js";
package/build/index.js CHANGED
@@ -56,7 +56,7 @@ export { serializePreparedFlow } from "./types/prepared.js";
56
56
  export { AAVE_POOL, AAVE_SUPPORTED_SYMBOLS, resolveAaveAsset, } from "./config/aave.js";
57
57
  export { CHAIN, DEFAULT_RPC_URL } from "./config/chains.js";
58
58
  export { appendCelinaCalldataTag, CELINA_DATA_SUFFIX, } from "./config/celina-tag.js";
59
- export { GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, } from "./config/gooddollar.js";
59
+ export { GOODDOLLAR_CUSD_EXCHANGE_ID, GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_MENTO_BROKER, GOODDOLLAR_MENTO_EXCHANGE_PROVIDER, GOODDOLLAR_RESERVE_COLLATERAL, GOODDOLLAR_TOKEN_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, isGoodDollarUsdReservePair, } from "./config/gooddollar.js";
60
60
  export { CARBON_APP_BASE_URL, CARBON_CHAIN, CELO_CARBON_CONTRACTS, DEFAULT_CARBON_REST_BASE_URL, carbonActivityDeepLink, } from "./config/carbon.js";
61
61
  export { resolveCarbonTokenAddress, normalizeCarbonWriteBody, CARBON_WRITE_TOKEN_FIELDS, } from "./utils/carbon-token.js";
62
62
  export { buildCarbonExecutionSteps } from "./utils/carbon-execution.js";
@@ -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,E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7 @@ export declare class EnsService {
17
17
  constructor(ensClientFactory: EnsClientFactory);
18
18
  /**
19
19
  * Resolve an ENS name on Celo or Ethereum to an address.
20
- * @param name - ENS name (e.g. `vitalik.eth`)
20
+ * @param name - ENS name (e.g. `andrewkimjoseph.celo.eth`)
21
21
  * @param chain - `"celo"` tries Celo coin type first, then Ethereum; `"ethereum"` uses ETH only
22
22
  * @throws When no address record exists for the name
23
23
  */
@@ -14,7 +14,7 @@ export class EnsService {
14
14
  }
15
15
  /**
16
16
  * Resolve an ENS name on Celo or Ethereum to an address.
17
- * @param name - ENS name (e.g. `vitalik.eth`)
17
+ * @param name - ENS name (e.g. `andrewkimjoseph.celo.eth`)
18
18
  * @param chain - `"celo"` tries Celo coin type first, then Ethereum; `"ethereum"` uses ETH only
19
19
  * @throws When no address record exists for the name
20
20
  */
@@ -1,8 +1,16 @@
1
1
  import type { CeloClientFactory } from "../clients/celo-client.js";
2
2
  import { type SerializedPreparedFlow } from "../types/prepared.js";
3
- /** GoodDollar IdentityV4 whitelist, reverification, and daily UBI claim preparation. */
3
+ /** Optional parameters for GoodDollar reserve swap prepares. */
4
+ export interface GoodDollarReserveSwapParams {
5
+ /** Max slippage tolerance in percent (default `0.5`). */
6
+ slippageTolerance?: number;
7
+ /** Address receiving output tokens (default: `from`). */
8
+ recipient?: `0x${string}`;
9
+ }
10
+ /** GoodDollar IdentityV4 whitelist, reverification, daily UBI claim, and reserve swap preparation. */
4
11
  export declare class GoodDollarService {
5
12
  private readonly clientFactory;
13
+ private readonly tokenService;
6
14
  constructor(clientFactory: CeloClientFactory);
7
15
  private getPublicClient;
8
16
  /**
@@ -86,6 +94,29 @@ export declare class GoodDollarService {
86
94
  * Validates whitelist, entitlement, and simulates gas before returning steps.
87
95
  */
88
96
  prepareClaimUbi(from: `0x${string}`): Promise<SerializedPreparedFlow>;
97
+ private resolveReservePair;
98
+ private reserveOptions;
99
+ private baseReserveQuoteFields;
100
+ /**
101
+ * Expected GoodDollar reserve output for G$ ↔ USDm — no wallet required.
102
+ */
103
+ getReserveQuote(tokenIn: string, tokenOut: string, amount: string, from?: `0x${string}`): Promise<{
104
+ protocol: "gooddollar_reserve";
105
+ network: "mainnet";
106
+ tokenIn: string;
107
+ tokenOut: string;
108
+ amountIn: string;
109
+ expectedOut: string;
110
+ routeHops: number;
111
+ broker: "0x88de45906D4F5a57315c133620cfa484cB297541";
112
+ exchangeProvider: "0x2fFBB49055d487DdBBb0C052Cd7c2a02A7971e41";
113
+ exchangeId: "0xba77f5c7bb3317643c6d81d1ef3f9913561741d92095f88efa402faf2cbe9124";
114
+ }>;
115
+ private buildReserveSwap;
116
+ /**
117
+ * Build unsigned GoodDollar reserve swap steps (approve + swapIn when needed).
118
+ */
119
+ prepareReserveSwap(from: `0x${string}`, tokenIn: string, tokenOut: string, amount: string, params?: GoodDollarReserveSwapParams): Promise<SerializedPreparedFlow>;
89
120
  private effectiveAuthCount;
90
121
  private fetchReverifyDaysOptions;
91
122
  private buildReverificationProgress;
@@ -1,12 +1,15 @@
1
1
  /**
2
- * GoodDollar IdentityV4 whitelist and reverification reads on Celo mainnet.
2
+ * GoodDollar IdentityV4 whitelist, reverification reads, UBI claims, and reserve swaps on Celo mainnet.
3
3
  */
4
- import { concat, encodeFunctionData, formatUnits } from "viem";
4
+ import { concat, encodeFunctionData, erc20Abi, formatUnits, maxUint256, } from "viem";
5
+ import { goodDollarBrokerAbi } from "../abis/gooddollar-broker.js";
5
6
  import { goodDollarIdentityAbi } from "../abis/gooddollar-identity.js";
6
7
  import { ubiSchemeAbi } from "../abis/ubi-scheme.js";
7
- import { GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, } from "../config/gooddollar.js";
8
+ import { GOODDOLLAR_CUSD_EXCHANGE_ID, GOODDOLLAR_IDENTITY_ADDRESS, GOODDOLLAR_MENTO_BROKER, GOODDOLLAR_MENTO_EXCHANGE_PROVIDER, GOODDOLLAR_RESERVE_COLLATERAL, GOODDOLLAR_TOKEN_ADDRESS, GOODDOLLAR_UBI_SCHEME_ADDRESS, isGoodDollarUsdReservePair, } from "../config/gooddollar.js";
8
9
  import { CELINA_DATA_SUFFIX } from "../config/celina-tag.js";
9
10
  import { serializePreparedFlow, } from "../types/prepared.js";
11
+ import { ALLOWANCE_MAPPING_SLOTS, erc20AllowanceStateOverride, } from "../utils/erc20-allowance-storage.js";
12
+ import { TokenService } from "./token.service.js";
10
13
  import { formatUnixDate } from "../utils/format-date.js";
11
14
  import { formatDuration } from "../utils/format-duration.js";
12
15
  import { formatUnixDateTimeUtc, formatUnixIso, } from "../utils/format-unix-datetime.js";
@@ -27,11 +30,37 @@ function statusLabel(status) {
27
30
  function taggedCalldata(data) {
28
31
  return concat([data, CELINA_DATA_SUFFIX]);
29
32
  }
30
- /** GoodDollar IdentityV4 whitelist, reverification, and daily UBI claim preparation. */
33
+ const DEFAULT_RESERVE_SLIPPAGE = 0.5;
34
+ function trimDisplayDecimals(value) {
35
+ const num = Number(value);
36
+ if (!Number.isFinite(num)) {
37
+ return value;
38
+ }
39
+ if (Math.abs(num) >= 1000) {
40
+ return num.toLocaleString(undefined, { maximumFractionDigits: 2 });
41
+ }
42
+ if (Math.abs(num) >= 1) {
43
+ return num.toLocaleString(undefined, { maximumFractionDigits: 4 });
44
+ }
45
+ return num.toLocaleString(undefined, { maximumSignificantDigits: 6 });
46
+ }
47
+ function applySlippage(amountOut, slippagePercent) {
48
+ const bps = BigInt(Math.round(slippagePercent * 100));
49
+ return (amountOut * (10000n - bps)) / 10000n;
50
+ }
51
+ function tokenAddress(token) {
52
+ if (token.address === "native") {
53
+ throw new Error(`${token.symbol} is native CELO; GoodDollar reserve swaps require ERC-20 tokens.`);
54
+ }
55
+ return token.address;
56
+ }
57
+ /** GoodDollar IdentityV4 whitelist, reverification, daily UBI claim, and reserve swap preparation. */
31
58
  export class GoodDollarService {
32
59
  clientFactory;
60
+ tokenService;
33
61
  constructor(clientFactory) {
34
62
  this.clientFactory = clientFactory;
63
+ this.tokenService = new TokenService(clientFactory);
35
64
  }
36
65
  getPublicClient() {
37
66
  return this.clientFactory.getClients().public;
@@ -287,6 +316,187 @@ export class GoodDollarService {
287
316
  };
288
317
  return serializePreparedFlow(flow);
289
318
  }
319
+ resolveReservePair(tokenIn, tokenOut) {
320
+ if (!isGoodDollarUsdReservePair(tokenIn, tokenOut)) {
321
+ throw new Error(`No GoodDollar reserve route for ${tokenIn} → ${tokenOut}. Supported: GoodDollar ↔ USDm.`);
322
+ }
323
+ const resolvedIn = this.tokenService.resolveToken(tokenIn);
324
+ const resolvedOut = this.tokenService.resolveToken(tokenOut);
325
+ const tokenInAddr = tokenAddress(resolvedIn);
326
+ const tokenOutAddr = tokenAddress(resolvedOut);
327
+ const gdAddr = GOODDOLLAR_TOKEN_ADDRESS.toLowerCase();
328
+ const collateralAddr = GOODDOLLAR_RESERVE_COLLATERAL.toLowerCase();
329
+ const inLower = tokenInAddr.toLowerCase();
330
+ const outLower = tokenOutAddr.toLowerCase();
331
+ if (!((inLower === gdAddr && outLower === collateralAddr) ||
332
+ (inLower === collateralAddr && outLower === gdAddr))) {
333
+ throw new Error(`No GoodDollar reserve route for ${resolvedIn.symbol} → ${resolvedOut.symbol}.`);
334
+ }
335
+ return { resolvedIn, resolvedOut, tokenInAddr, tokenOutAddr };
336
+ }
337
+ reserveOptions(params) {
338
+ return {
339
+ slippageTolerance: params?.slippageTolerance ?? DEFAULT_RESERVE_SLIPPAGE,
340
+ };
341
+ }
342
+ baseReserveQuoteFields(resolvedIn, resolvedOut, amount, expectedOutWei) {
343
+ return {
344
+ protocol: "gooddollar_reserve",
345
+ network: "mainnet",
346
+ tokenIn: resolvedIn.symbol,
347
+ tokenOut: resolvedOut.symbol,
348
+ amountIn: amount,
349
+ expectedOut: formatUnits(expectedOutWei, resolvedOut.decimals),
350
+ routeHops: 1,
351
+ broker: GOODDOLLAR_MENTO_BROKER,
352
+ exchangeProvider: GOODDOLLAR_MENTO_EXCHANGE_PROVIDER,
353
+ exchangeId: GOODDOLLAR_CUSD_EXCHANGE_ID,
354
+ };
355
+ }
356
+ /**
357
+ * Expected GoodDollar reserve output for G$ ↔ USDm — no wallet required.
358
+ */
359
+ async getReserveQuote(tokenIn, tokenOut, amount, from) {
360
+ const { public: client } = this.clientFactory.getClients();
361
+ const { resolvedIn, resolvedOut, tokenInAddr, tokenOutAddr } = this.resolveReservePair(tokenIn, tokenOut);
362
+ const amountInWei = this.tokenService.parseAmount(amount, resolvedIn.decimals);
363
+ if (from) {
364
+ await this.tokenService.assertSpendableBalance(from, resolvedIn, amount, {
365
+ spendToken: tokenInAddr,
366
+ });
367
+ }
368
+ const expectedOutWei = await client.readContract({
369
+ address: GOODDOLLAR_MENTO_BROKER,
370
+ abi: goodDollarBrokerAbi,
371
+ functionName: "getAmountOut",
372
+ args: [
373
+ GOODDOLLAR_MENTO_EXCHANGE_PROVIDER,
374
+ GOODDOLLAR_CUSD_EXCHANGE_ID,
375
+ tokenInAddr,
376
+ tokenOutAddr,
377
+ amountInWei,
378
+ ],
379
+ });
380
+ return this.baseReserveQuoteFields(resolvedIn, resolvedOut, amount, expectedOutWei);
381
+ }
382
+ async buildReserveSwap(from, tokenIn, tokenOut, amount, params) {
383
+ const { public: client } = this.clientFactory.getClients();
384
+ const { resolvedIn, resolvedOut, tokenInAddr, tokenOutAddr } = this.resolveReservePair(tokenIn, tokenOut);
385
+ const recipient = params?.recipient ?? from;
386
+ const amountInWei = this.tokenService.parseAmount(amount, resolvedIn.decimals);
387
+ const { slippageTolerance } = this.reserveOptions(params);
388
+ await this.tokenService.assertSpendableBalance(from, resolvedIn, amount, {
389
+ spendToken: tokenInAddr,
390
+ });
391
+ const expectedOutWei = await client.readContract({
392
+ address: GOODDOLLAR_MENTO_BROKER,
393
+ abi: goodDollarBrokerAbi,
394
+ functionName: "getAmountOut",
395
+ args: [
396
+ GOODDOLLAR_MENTO_EXCHANGE_PROVIDER,
397
+ GOODDOLLAR_CUSD_EXCHANGE_ID,
398
+ tokenInAddr,
399
+ tokenOutAddr,
400
+ amountInWei,
401
+ ],
402
+ });
403
+ const amountOutMin = applySlippage(expectedOutWei, slippageTolerance);
404
+ const swapData = taggedCalldata(encodeFunctionData({
405
+ abi: goodDollarBrokerAbi,
406
+ functionName: "swapIn",
407
+ args: [
408
+ GOODDOLLAR_MENTO_EXCHANGE_PROVIDER,
409
+ GOODDOLLAR_CUSD_EXCHANGE_ID,
410
+ tokenInAddr,
411
+ tokenOutAddr,
412
+ amountInWei,
413
+ amountOutMin,
414
+ ],
415
+ }));
416
+ return {
417
+ client,
418
+ from,
419
+ recipient,
420
+ resolvedIn,
421
+ resolvedOut,
422
+ tokenInAddr,
423
+ tokenOutAddr,
424
+ amount,
425
+ amountInWei,
426
+ expectedOutWei,
427
+ amountOutMin,
428
+ swapData,
429
+ };
430
+ }
431
+ /**
432
+ * Build unsigned GoodDollar reserve swap steps (approve + swapIn when needed).
433
+ */
434
+ async prepareReserveSwap(from, tokenIn, tokenOut, amount, params) {
435
+ const built = await this.buildReserveSwap(from, tokenIn, tokenOut, amount, params);
436
+ const { client, resolvedIn, resolvedOut, tokenInAddr, amountInWei, expectedOutWei, swapData, recipient, } = built;
437
+ const displayIn = trimDisplayDecimals(built.amount);
438
+ const displayOut = trimDisplayDecimals(formatUnits(expectedOutWei, resolvedOut.decimals));
439
+ const steps = [];
440
+ const allowance = await client.readContract({
441
+ address: tokenInAddr,
442
+ abi: erc20Abi,
443
+ functionName: "allowance",
444
+ args: [from, GOODDOLLAR_MENTO_BROKER],
445
+ });
446
+ if (allowance < amountInWei) {
447
+ steps.push({
448
+ kind: "erc20",
449
+ to: tokenInAddr,
450
+ data: taggedCalldata(encodeFunctionData({
451
+ abi: erc20Abi,
452
+ functionName: "approve",
453
+ args: [GOODDOLLAR_MENTO_BROKER, maxUint256],
454
+ })),
455
+ value: "0",
456
+ description: `Approve ${resolvedIn.symbol} for GoodDollar reserve`,
457
+ });
458
+ }
459
+ steps.push({
460
+ kind: "contract",
461
+ to: GOODDOLLAR_MENTO_BROKER,
462
+ data: swapData,
463
+ value: "0",
464
+ description: `Swap ${displayIn} ${resolvedIn.symbol} → ~${displayOut} ${resolvedOut.symbol} via GoodDollar reserve`,
465
+ });
466
+ const swapEstimateRequest = {
467
+ account: from,
468
+ to: GOODDOLLAR_MENTO_BROKER,
469
+ data: swapData,
470
+ value: 0n,
471
+ };
472
+ if (allowance < amountInWei) {
473
+ for (const mappingSlot of ALLOWANCE_MAPPING_SLOTS) {
474
+ try {
475
+ await client.estimateGas({
476
+ ...swapEstimateRequest,
477
+ stateOverride: erc20AllowanceStateOverride(tokenInAddr, from, GOODDOLLAR_MENTO_BROKER, maxUint256, mappingSlot),
478
+ });
479
+ break;
480
+ }
481
+ catch (error) {
482
+ const isLast = mappingSlot === ALLOWANCE_MAPPING_SLOTS.at(-1);
483
+ if (isLast) {
484
+ throw error;
485
+ }
486
+ }
487
+ }
488
+ }
489
+ else {
490
+ await client.estimateGas(swapEstimateRequest);
491
+ }
492
+ const flow = {
493
+ network: "mainnet",
494
+ from,
495
+ summary: `GoodDollar reserve: ${displayIn} ${resolvedIn.symbol} → ${displayOut} ${resolvedOut.symbol}${recipient !== from ? ` (recipient ${recipient})` : ""}`,
496
+ steps,
497
+ };
498
+ return serializePreparedFlow(flow);
499
+ }
290
500
  effectiveAuthCount(dateAuthenticated, authCount, optionsLength) {
291
501
  if (dateAuthenticated < LEGACY_AUTH_CUTOFF) {
292
502
  return optionsLength - 1;