@goodwidget/ai-credits-widget 0.1.2 → 0.1.3
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/dist/element.d.cts +25 -0
- package/dist/element.d.ts +25 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/mocked/index.d.cts +51 -0
- package/dist/mocked/index.d.ts +51 -0
- package/dist/register.d.cts +22 -0
- package/dist/register.d.ts +22 -0
- package/dist/widgetRuntimeContract-BPILUGC4.d.cts +342 -0
- package/dist/widgetRuntimeContract-BPILUGC4.d.ts +342 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as _goodwidget_embed from '@goodwidget/embed';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Custom Element class wrapping the AiCreditsWidget React component.
|
|
5
|
+
*
|
|
6
|
+
* Register it with any tag name:
|
|
7
|
+
* customElements.define('ai-credits-widget', AiCreditsWidgetElement)
|
|
8
|
+
*
|
|
9
|
+
* Then use in HTML:
|
|
10
|
+
* <ai-credits-widget></ai-credits-widget>
|
|
11
|
+
*
|
|
12
|
+
* Set the wallet provider and theme overrides via JS properties:
|
|
13
|
+
* const el = document.querySelector('ai-credits-widget')
|
|
14
|
+
* el.provider = window.ethereum
|
|
15
|
+
* el.backendUrl = 'https://api.antseed.xyz'
|
|
16
|
+
* el.fundingVaultAddress = '0xYourVaultAddress'
|
|
17
|
+
* el.themeOverrides = { tokens: { color: { primary: '#00AFFE' } } }
|
|
18
|
+
*/
|
|
19
|
+
declare const AiCreditsWidgetElementBase: _goodwidget_embed.MiniAppElementConstructor;
|
|
20
|
+
declare class AiCreditsWidgetElement extends AiCreditsWidgetElementBase {
|
|
21
|
+
backendUrl: string | undefined;
|
|
22
|
+
fundingVaultAddress: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { AiCreditsWidgetElement };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as _goodwidget_embed from '@goodwidget/embed';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Custom Element class wrapping the AiCreditsWidget React component.
|
|
5
|
+
*
|
|
6
|
+
* Register it with any tag name:
|
|
7
|
+
* customElements.define('ai-credits-widget', AiCreditsWidgetElement)
|
|
8
|
+
*
|
|
9
|
+
* Then use in HTML:
|
|
10
|
+
* <ai-credits-widget></ai-credits-widget>
|
|
11
|
+
*
|
|
12
|
+
* Set the wallet provider and theme overrides via JS properties:
|
|
13
|
+
* const el = document.querySelector('ai-credits-widget')
|
|
14
|
+
* el.provider = window.ethereum
|
|
15
|
+
* el.backendUrl = 'https://api.antseed.xyz'
|
|
16
|
+
* el.fundingVaultAddress = '0xYourVaultAddress'
|
|
17
|
+
* el.themeOverrides = { tokens: { color: { primary: '#00AFFE' } } }
|
|
18
|
+
*/
|
|
19
|
+
declare const AiCreditsWidgetElementBase: _goodwidget_embed.MiniAppElementConstructor;
|
|
20
|
+
declare class AiCreditsWidgetElement extends AiCreditsWidgetElementBase {
|
|
21
|
+
backendUrl: string | undefined;
|
|
22
|
+
fundingVaultAddress: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { AiCreditsWidgetElement };
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { A as AiCreditsWidgetEnvironment, a as AiCreditsPaySuccessDetail, b as AiCreditsPayErrorDetail, c as AiCreditsBackendClient, d as AiCreditsChainClient, e as AccountRef, f as AiCreditsWidgetAdapterResult, g as AiCreditsWidgetProps } from './widgetRuntimeContract-BPILUGC4.cjs';
|
|
2
|
+
export { h as AccountEnrichment, i as AccountStatusResponse, i as AccountView, j as AiCreditsQuote, k as AiCreditsWidgetAdapterActions, l as AiCreditsWidgetAdapterFactory, m as AiCreditsWidgetAdapterFactoryInput, n as AiCreditsWidgetAdapterState, o as AiCreditsWidgetStatus, p as AiCreditsWidgetTab, B as BuyerOperatorStatus, C as CELO_GOODID_ADDRESS, D as DEFAULT_BASE_RPC_URL, q as DEFAULT_CELO_RPC_URL, r as DEFAULT_DISCOUNT_CONFIG, s as DiscountConfig, E as Eip712SigningPayload, G as GdCreditEntry, P as ProductionAiCreditsBackendClient, U as UnavailableAiCreditsBackendClient, t as buildAccountView, u as createBackendClient, v as createChainClient, w as enrichAccountView, x as totalCreditUsdFromProfile, y as totalCreditUsdFromStatus } from './widgetRuntimeContract-BPILUGC4.cjs';
|
|
3
|
+
import { Address } from 'viem';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import '@goodwidget/ui';
|
|
6
|
+
|
|
7
|
+
declare const aiCreditsIntegration: {
|
|
8
|
+
readonly id: "ai-credits";
|
|
9
|
+
readonly chains: readonly [42220];
|
|
10
|
+
readonly settlementChains: readonly [8453];
|
|
11
|
+
readonly states: readonly ["disconnected", "connecting", "purchase_setup", "quote_ready", "payment_pending", "payment_confirmed", "insufficient_g_balance", "payment_failed", "backend_unavailable", "unsupported_chain"];
|
|
12
|
+
readonly events: readonly ["pay-success", "pay-error"];
|
|
13
|
+
};
|
|
14
|
+
type AiCreditsIntegration = typeof aiCreditsIntegration;
|
|
15
|
+
|
|
16
|
+
declare function usdToCredits(usd: string): string;
|
|
17
|
+
|
|
18
|
+
interface UseAiCreditsAdapterOptions {
|
|
19
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
20
|
+
backendUrl?: string;
|
|
21
|
+
baseRpcUrl?: string;
|
|
22
|
+
celoRpcUrl?: string;
|
|
23
|
+
fundingVaultAddress?: Address;
|
|
24
|
+
vaultAddress?: Address;
|
|
25
|
+
goodIdAddress?: Address;
|
|
26
|
+
goodIdReturnUrl?: string;
|
|
27
|
+
onPaySuccess?: (detail: AiCreditsPaySuccessDetail) => void;
|
|
28
|
+
onPayError?: (detail: AiCreditsPayErrorDetail) => void;
|
|
29
|
+
backendClient?: AiCreditsBackendClient;
|
|
30
|
+
chainClient?: AiCreditsChainClient;
|
|
31
|
+
skipVaultPaymentValidation?: boolean;
|
|
32
|
+
prepareSettlement?: (ref: AccountRef, creditUsd: bigint) => void;
|
|
33
|
+
}
|
|
34
|
+
declare function useAiCreditsAdapter({ environment, backendUrl, baseRpcUrl, celoRpcUrl, fundingVaultAddress, vaultAddress, goodIdAddress, goodIdReturnUrl, onPaySuccess, onPayError, backendClient: backendClientOverride, chainClient: chainClientOverride, skipVaultPaymentValidation, prepareSettlement, }: UseAiCreditsAdapterOptions): AiCreditsWidgetAdapterResult;
|
|
35
|
+
|
|
36
|
+
declare function AiCreditsWidget({ provider, connectOverride, environment, backendUrl, baseRpcUrl, celoRpcUrl, fundingVaultAddress, vaultAddress, goodIdAddress, themeOverrides, config, defaultTheme, onPaySuccess, onPayError, adapterFactory, adapterOptions, testId, }: AiCreditsWidgetProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { AccountRef, AiCreditsBackendClient, AiCreditsChainClient, type AiCreditsIntegration, AiCreditsPayErrorDetail, AiCreditsPaySuccessDetail, AiCreditsWidget, AiCreditsWidgetAdapterResult, AiCreditsWidgetEnvironment, AiCreditsWidgetProps, type UseAiCreditsAdapterOptions, aiCreditsIntegration, usdToCredits, useAiCreditsAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { A as AiCreditsWidgetEnvironment, a as AiCreditsPaySuccessDetail, b as AiCreditsPayErrorDetail, c as AiCreditsBackendClient, d as AiCreditsChainClient, e as AccountRef, f as AiCreditsWidgetAdapterResult, g as AiCreditsWidgetProps } from './widgetRuntimeContract-BPILUGC4.js';
|
|
2
|
+
export { h as AccountEnrichment, i as AccountStatusResponse, i as AccountView, j as AiCreditsQuote, k as AiCreditsWidgetAdapterActions, l as AiCreditsWidgetAdapterFactory, m as AiCreditsWidgetAdapterFactoryInput, n as AiCreditsWidgetAdapterState, o as AiCreditsWidgetStatus, p as AiCreditsWidgetTab, B as BuyerOperatorStatus, C as CELO_GOODID_ADDRESS, D as DEFAULT_BASE_RPC_URL, q as DEFAULT_CELO_RPC_URL, r as DEFAULT_DISCOUNT_CONFIG, s as DiscountConfig, E as Eip712SigningPayload, G as GdCreditEntry, P as ProductionAiCreditsBackendClient, U as UnavailableAiCreditsBackendClient, t as buildAccountView, u as createBackendClient, v as createChainClient, w as enrichAccountView, x as totalCreditUsdFromProfile, y as totalCreditUsdFromStatus } from './widgetRuntimeContract-BPILUGC4.js';
|
|
3
|
+
import { Address } from 'viem';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import '@goodwidget/ui';
|
|
6
|
+
|
|
7
|
+
declare const aiCreditsIntegration: {
|
|
8
|
+
readonly id: "ai-credits";
|
|
9
|
+
readonly chains: readonly [42220];
|
|
10
|
+
readonly settlementChains: readonly [8453];
|
|
11
|
+
readonly states: readonly ["disconnected", "connecting", "purchase_setup", "quote_ready", "payment_pending", "payment_confirmed", "insufficient_g_balance", "payment_failed", "backend_unavailable", "unsupported_chain"];
|
|
12
|
+
readonly events: readonly ["pay-success", "pay-error"];
|
|
13
|
+
};
|
|
14
|
+
type AiCreditsIntegration = typeof aiCreditsIntegration;
|
|
15
|
+
|
|
16
|
+
declare function usdToCredits(usd: string): string;
|
|
17
|
+
|
|
18
|
+
interface UseAiCreditsAdapterOptions {
|
|
19
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
20
|
+
backendUrl?: string;
|
|
21
|
+
baseRpcUrl?: string;
|
|
22
|
+
celoRpcUrl?: string;
|
|
23
|
+
fundingVaultAddress?: Address;
|
|
24
|
+
vaultAddress?: Address;
|
|
25
|
+
goodIdAddress?: Address;
|
|
26
|
+
goodIdReturnUrl?: string;
|
|
27
|
+
onPaySuccess?: (detail: AiCreditsPaySuccessDetail) => void;
|
|
28
|
+
onPayError?: (detail: AiCreditsPayErrorDetail) => void;
|
|
29
|
+
backendClient?: AiCreditsBackendClient;
|
|
30
|
+
chainClient?: AiCreditsChainClient;
|
|
31
|
+
skipVaultPaymentValidation?: boolean;
|
|
32
|
+
prepareSettlement?: (ref: AccountRef, creditUsd: bigint) => void;
|
|
33
|
+
}
|
|
34
|
+
declare function useAiCreditsAdapter({ environment, backendUrl, baseRpcUrl, celoRpcUrl, fundingVaultAddress, vaultAddress, goodIdAddress, goodIdReturnUrl, onPaySuccess, onPayError, backendClient: backendClientOverride, chainClient: chainClientOverride, skipVaultPaymentValidation, prepareSettlement, }: UseAiCreditsAdapterOptions): AiCreditsWidgetAdapterResult;
|
|
35
|
+
|
|
36
|
+
declare function AiCreditsWidget({ provider, connectOverride, environment, backendUrl, baseRpcUrl, celoRpcUrl, fundingVaultAddress, vaultAddress, goodIdAddress, themeOverrides, config, defaultTheme, onPaySuccess, onPayError, adapterFactory, adapterOptions, testId, }: AiCreditsWidgetProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { AccountRef, AiCreditsBackendClient, AiCreditsChainClient, type AiCreditsIntegration, AiCreditsPayErrorDetail, AiCreditsPaySuccessDetail, AiCreditsWidget, AiCreditsWidgetAdapterResult, AiCreditsWidgetEnvironment, AiCreditsWidgetProps, type UseAiCreditsAdapterOptions, aiCreditsIntegration, usdToCredits, useAiCreditsAdapter };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-BPILUGC4.cjs';
|
|
3
|
+
import 'viem';
|
|
4
|
+
import '@goodwidget/ui';
|
|
5
|
+
|
|
6
|
+
declare function MockAiCreditsWidget(props: Omit<AiCreditsWidgetProps, 'adapterOptions' | 'environment'>): react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
declare class MockAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
9
|
+
private activeRef;
|
|
10
|
+
private lastCreditUsd;
|
|
11
|
+
private readonly accountStates;
|
|
12
|
+
private getState;
|
|
13
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
14
|
+
private buildProfile;
|
|
15
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
16
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
17
|
+
getOutstanding(payer: string): Promise<{
|
|
18
|
+
outstandingFundingUsd: string;
|
|
19
|
+
count: number;
|
|
20
|
+
}>;
|
|
21
|
+
getTransactions(payer: string, options?: {
|
|
22
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
23
|
+
limit?: number;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
}): Promise<TransactionsResponse>;
|
|
26
|
+
prepareSettlement(ref: AccountRef, creditUsd: bigint): void;
|
|
27
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
28
|
+
waitForSettlement(ref: AccountRef): Promise<SettlementResult>;
|
|
29
|
+
closeChannel(channelId: string): Promise<ChannelOperationResponse>;
|
|
30
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
31
|
+
submitOperatorConsent(buyer: string): Promise<OperatorConsentResponse>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class MockAiCreditsChainClient implements AiCreditsChainClient {
|
|
35
|
+
private operatorAccepted;
|
|
36
|
+
private readonly gdUsdPerToken;
|
|
37
|
+
private readonly goodIdVerified;
|
|
38
|
+
constructor(options?: {
|
|
39
|
+
operatorAccepted?: boolean;
|
|
40
|
+
gdUsdPerToken?: number;
|
|
41
|
+
goodIdVerified?: boolean;
|
|
42
|
+
});
|
|
43
|
+
isGoodIdVerified(): Promise<boolean>;
|
|
44
|
+
fetchGdUsdPerToken(): Promise<number>;
|
|
45
|
+
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
46
|
+
getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
|
|
47
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
48
|
+
getWithdrawableUsd(): Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { MockAiCreditsBackendClient, MockAiCreditsChainClient, MockAiCreditsWidget };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-BPILUGC4.js';
|
|
3
|
+
import 'viem';
|
|
4
|
+
import '@goodwidget/ui';
|
|
5
|
+
|
|
6
|
+
declare function MockAiCreditsWidget(props: Omit<AiCreditsWidgetProps, 'adapterOptions' | 'environment'>): react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
declare class MockAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
9
|
+
private activeRef;
|
|
10
|
+
private lastCreditUsd;
|
|
11
|
+
private readonly accountStates;
|
|
12
|
+
private getState;
|
|
13
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
14
|
+
private buildProfile;
|
|
15
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
16
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
17
|
+
getOutstanding(payer: string): Promise<{
|
|
18
|
+
outstandingFundingUsd: string;
|
|
19
|
+
count: number;
|
|
20
|
+
}>;
|
|
21
|
+
getTransactions(payer: string, options?: {
|
|
22
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
23
|
+
limit?: number;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
}): Promise<TransactionsResponse>;
|
|
26
|
+
prepareSettlement(ref: AccountRef, creditUsd: bigint): void;
|
|
27
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
28
|
+
waitForSettlement(ref: AccountRef): Promise<SettlementResult>;
|
|
29
|
+
closeChannel(channelId: string): Promise<ChannelOperationResponse>;
|
|
30
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
31
|
+
submitOperatorConsent(buyer: string): Promise<OperatorConsentResponse>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class MockAiCreditsChainClient implements AiCreditsChainClient {
|
|
35
|
+
private operatorAccepted;
|
|
36
|
+
private readonly gdUsdPerToken;
|
|
37
|
+
private readonly goodIdVerified;
|
|
38
|
+
constructor(options?: {
|
|
39
|
+
operatorAccepted?: boolean;
|
|
40
|
+
gdUsdPerToken?: number;
|
|
41
|
+
goodIdVerified?: boolean;
|
|
42
|
+
});
|
|
43
|
+
isGoodIdVerified(): Promise<boolean>;
|
|
44
|
+
fetchGdUsdPerToken(): Promise<number>;
|
|
45
|
+
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
46
|
+
getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
|
|
47
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
48
|
+
getWithdrawableUsd(): Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { MockAiCreditsBackendClient, MockAiCreditsChainClient, MockAiCreditsWidget };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const goodWidgetMetadata: {
|
|
2
|
+
readonly packageName: "@goodwidget/ai-credits-widget";
|
|
3
|
+
readonly packageVersion: "0.1.0";
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Register the <ai-credits-widget> custom element.
|
|
7
|
+
*
|
|
8
|
+
* Call once at the top of your app or in a <script> tag:
|
|
9
|
+
* import '@goodwidget/ai-credits-widget/register'
|
|
10
|
+
*
|
|
11
|
+
* Then use in HTML:
|
|
12
|
+
* <ai-credits-widget></ai-credits-widget>
|
|
13
|
+
*
|
|
14
|
+
* Resolves to the tag name so you can use it programmatically:
|
|
15
|
+
* const tag = await register() // 'ai-credits-widget'
|
|
16
|
+
*
|
|
17
|
+
* Or register under a custom tag:
|
|
18
|
+
* const tag = await register('my-ai-credits-widget')
|
|
19
|
+
*/
|
|
20
|
+
declare function register(tagName?: string): Promise<string>;
|
|
21
|
+
|
|
22
|
+
export { goodWidgetMetadata, register };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const goodWidgetMetadata: {
|
|
2
|
+
readonly packageName: "@goodwidget/ai-credits-widget";
|
|
3
|
+
readonly packageVersion: "0.1.0";
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Register the <ai-credits-widget> custom element.
|
|
7
|
+
*
|
|
8
|
+
* Call once at the top of your app or in a <script> tag:
|
|
9
|
+
* import '@goodwidget/ai-credits-widget/register'
|
|
10
|
+
*
|
|
11
|
+
* Then use in HTML:
|
|
12
|
+
* <ai-credits-widget></ai-credits-widget>
|
|
13
|
+
*
|
|
14
|
+
* Resolves to the tag name so you can use it programmatically:
|
|
15
|
+
* const tag = await register() // 'ai-credits-widget'
|
|
16
|
+
*
|
|
17
|
+
* Or register under a custom tag:
|
|
18
|
+
* const tag = await register('my-ai-credits-widget')
|
|
19
|
+
*/
|
|
20
|
+
declare function register(tagName?: string): Promise<string>;
|
|
21
|
+
|
|
22
|
+
export { goodWidgetMetadata, register };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
|
|
3
|
+
|
|
4
|
+
type Eip712SigningPayload = {
|
|
5
|
+
primaryType: string;
|
|
6
|
+
domain: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
verifyingContract: string;
|
|
11
|
+
};
|
|
12
|
+
types: Record<string, Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}>>;
|
|
16
|
+
message: Record<string, string | number>;
|
|
17
|
+
};
|
|
18
|
+
type BuyerOperatorStatus = {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
account: string;
|
|
21
|
+
buyerAddress: string;
|
|
22
|
+
operatorAddress?: string;
|
|
23
|
+
currentOperator: string;
|
|
24
|
+
operatorAccepted: boolean;
|
|
25
|
+
consentNonce: string;
|
|
26
|
+
};
|
|
27
|
+
type OperatorConsentPayloadResponse = {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
account: string;
|
|
30
|
+
buyerAddress: string;
|
|
31
|
+
typedData?: Eip712SigningPayload;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type AccountRef = {
|
|
35
|
+
payer: string;
|
|
36
|
+
buyer: string;
|
|
37
|
+
};
|
|
38
|
+
type UserCreditProfile = {
|
|
39
|
+
account: string;
|
|
40
|
+
rootAccount: string;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
totalGdDepositedWei: string;
|
|
44
|
+
totalPrincipalUsd: string;
|
|
45
|
+
totalBonusUsd: string;
|
|
46
|
+
totalGDStreamedWei: string;
|
|
47
|
+
totalOutstandingFundingUsd: string;
|
|
48
|
+
streamFlowRateWeiPerSecond: string;
|
|
49
|
+
lastStreamCreditAt?: string;
|
|
50
|
+
};
|
|
51
|
+
type GdCreditEntry = {
|
|
52
|
+
id: string;
|
|
53
|
+
account: string;
|
|
54
|
+
rootAccount: string;
|
|
55
|
+
source: 'deposit' | 'streamUpdate' | 'streamRequest' | 'streamCron';
|
|
56
|
+
gdAmountWei: string;
|
|
57
|
+
principalUsd: string;
|
|
58
|
+
bonusUsd: string;
|
|
59
|
+
totalCreditUsd: string;
|
|
60
|
+
fundingStatus: 'pending' | 'funded' | 'failed';
|
|
61
|
+
fundingTxHash?: string;
|
|
62
|
+
fundingError?: string;
|
|
63
|
+
txHash?: string;
|
|
64
|
+
logIndex?: number;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
streamUpdateMonth: string;
|
|
67
|
+
buyerAddress?: string;
|
|
68
|
+
};
|
|
69
|
+
type AccountCreditResponse = {
|
|
70
|
+
account: string;
|
|
71
|
+
profile: UserCreditProfile;
|
|
72
|
+
};
|
|
73
|
+
type CreditHistoryResponse = {
|
|
74
|
+
account: string;
|
|
75
|
+
items: GdCreditEntry[];
|
|
76
|
+
total: number;
|
|
77
|
+
limit: number;
|
|
78
|
+
offset: number;
|
|
79
|
+
hasMore: boolean;
|
|
80
|
+
};
|
|
81
|
+
type CreditHistoryQuery = {
|
|
82
|
+
limit?: number;
|
|
83
|
+
offset?: number;
|
|
84
|
+
source?: GdCreditEntry['source'];
|
|
85
|
+
fundingStatus?: GdCreditEntry['fundingStatus'];
|
|
86
|
+
from?: string;
|
|
87
|
+
to?: string;
|
|
88
|
+
};
|
|
89
|
+
type AccountView = {
|
|
90
|
+
account: string;
|
|
91
|
+
buyer: string | null;
|
|
92
|
+
profile: UserCreditProfile;
|
|
93
|
+
operator: BuyerOperatorStatus;
|
|
94
|
+
withdrawableUsd: string;
|
|
95
|
+
outstandingFundingUsd: string;
|
|
96
|
+
outstandingFundingCount: number;
|
|
97
|
+
};
|
|
98
|
+
type TransactionsResponse = {
|
|
99
|
+
account: string;
|
|
100
|
+
transactions: GdCreditEntry[];
|
|
101
|
+
nextCursor?: string;
|
|
102
|
+
};
|
|
103
|
+
type CeloEventsRecordResponse = {
|
|
104
|
+
txHash?: string;
|
|
105
|
+
account?: string;
|
|
106
|
+
fromBlock?: string;
|
|
107
|
+
toBlock?: string;
|
|
108
|
+
events: GdCreditEntry[];
|
|
109
|
+
};
|
|
110
|
+
type SettlementResult = {
|
|
111
|
+
totalCreditUsd: string;
|
|
112
|
+
};
|
|
113
|
+
type DiscountConfig = {
|
|
114
|
+
depositBonusPercent: number;
|
|
115
|
+
streamBonusPercent: number;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
|
|
119
|
+
declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
|
|
120
|
+
declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
|
|
121
|
+
type AiCreditsChainClientOptions = {
|
|
122
|
+
baseRpcUrl?: string;
|
|
123
|
+
fundingVaultAddress?: Address;
|
|
124
|
+
celoRpcUrl?: string;
|
|
125
|
+
celoVaultAddress?: Address;
|
|
126
|
+
celoGoodIdAddress?: Address;
|
|
127
|
+
depositsAddress?: Address;
|
|
128
|
+
};
|
|
129
|
+
interface AiCreditsChainClient {
|
|
130
|
+
fetchGdUsdPerToken(): Promise<number>;
|
|
131
|
+
isGoodIdVerified(account: string): Promise<boolean>;
|
|
132
|
+
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
133
|
+
getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
|
|
134
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
135
|
+
getWithdrawableUsd(buyer: string): Promise<string>;
|
|
136
|
+
}
|
|
137
|
+
declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
|
|
138
|
+
|
|
139
|
+
type WithdrawPrincipalRequest = {
|
|
140
|
+
amount: string;
|
|
141
|
+
recipient: string;
|
|
142
|
+
timestamp: number;
|
|
143
|
+
signature: string;
|
|
144
|
+
};
|
|
145
|
+
type ChannelOperationRequest = {
|
|
146
|
+
timestamp?: number;
|
|
147
|
+
signature?: string;
|
|
148
|
+
};
|
|
149
|
+
type BridgeResponse = {
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
txHash?: string;
|
|
152
|
+
};
|
|
153
|
+
type ChannelOperationResponse = {
|
|
154
|
+
channelId: string;
|
|
155
|
+
action: 'close' | 'withdraw';
|
|
156
|
+
bridge: BridgeResponse;
|
|
157
|
+
};
|
|
158
|
+
type WithdrawPrincipalResponse = {
|
|
159
|
+
account: string;
|
|
160
|
+
amountUsd: string;
|
|
161
|
+
bridge: BridgeResponse;
|
|
162
|
+
};
|
|
163
|
+
type OperatorConsentRequest = {
|
|
164
|
+
nonce: string;
|
|
165
|
+
signature: string;
|
|
166
|
+
};
|
|
167
|
+
type OperatorConsentResponse = {
|
|
168
|
+
buyer: string;
|
|
169
|
+
bridge: BridgeResponse;
|
|
170
|
+
};
|
|
171
|
+
declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
|
|
172
|
+
declare function totalCreditUsdFromStatus(status: {
|
|
173
|
+
profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
|
|
174
|
+
}): string;
|
|
175
|
+
type AccountEnrichment = {
|
|
176
|
+
totalCreditUsd: string;
|
|
177
|
+
goodIdVerified: boolean;
|
|
178
|
+
totalGdDepositedG: string;
|
|
179
|
+
monthlyStreamG: string;
|
|
180
|
+
};
|
|
181
|
+
type BuildAccountViewOptions = {
|
|
182
|
+
buyerAddress?: string | null;
|
|
183
|
+
};
|
|
184
|
+
declare function enrichAccountView(view: AccountView, chain: AiCreditsChainClient): Promise<AccountEnrichment>;
|
|
185
|
+
interface AiCreditsBackendClient {
|
|
186
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
187
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
188
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
189
|
+
getOutstanding(payer: string): Promise<{
|
|
190
|
+
outstandingFundingUsd: string;
|
|
191
|
+
count: number;
|
|
192
|
+
}>;
|
|
193
|
+
getTransactions(payer: string, options?: {
|
|
194
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
195
|
+
limit?: number;
|
|
196
|
+
cursor?: string;
|
|
197
|
+
}): Promise<TransactionsResponse>;
|
|
198
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
199
|
+
waitForSettlement(ref: AccountRef, options?: {
|
|
200
|
+
txHashes?: string[];
|
|
201
|
+
previousBalance?: string;
|
|
202
|
+
}): Promise<SettlementResult>;
|
|
203
|
+
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
204
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
205
|
+
submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
206
|
+
}
|
|
207
|
+
declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
|
|
208
|
+
declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
209
|
+
private readonly backendUrl;
|
|
210
|
+
constructor(backendUrl: string);
|
|
211
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
212
|
+
private accountBase;
|
|
213
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
214
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
215
|
+
getOutstanding(payer: string): Promise<{
|
|
216
|
+
outstandingFundingUsd: string;
|
|
217
|
+
count: number;
|
|
218
|
+
}>;
|
|
219
|
+
getTransactions(payer: string, options?: {
|
|
220
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
221
|
+
limit?: number;
|
|
222
|
+
cursor?: string;
|
|
223
|
+
}): Promise<TransactionsResponse>;
|
|
224
|
+
getUsageLog(payer: string): Promise<GdCreditEntry[]>;
|
|
225
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
226
|
+
waitForSettlement(ref: AccountRef, options?: {
|
|
227
|
+
txHashes?: string[];
|
|
228
|
+
previousBalance?: string;
|
|
229
|
+
}): Promise<SettlementResult>;
|
|
230
|
+
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
231
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
232
|
+
submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
233
|
+
}
|
|
234
|
+
declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
235
|
+
private unavailable;
|
|
236
|
+
getDiscountConfig(): Promise<never>;
|
|
237
|
+
getAccountCredit(): Promise<never>;
|
|
238
|
+
getCreditHistory(): Promise<never>;
|
|
239
|
+
getOutstanding(): Promise<never>;
|
|
240
|
+
getTransactions(): Promise<never>;
|
|
241
|
+
notifyPayment(): Promise<never>;
|
|
242
|
+
waitForSettlement(): Promise<never>;
|
|
243
|
+
closeChannel(): Promise<never>;
|
|
244
|
+
withdrawCredits(): Promise<never>;
|
|
245
|
+
submitOperatorConsent(): Promise<never>;
|
|
246
|
+
}
|
|
247
|
+
declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
|
|
248
|
+
declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
|
|
249
|
+
|
|
250
|
+
type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
|
|
251
|
+
type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
|
|
252
|
+
type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
|
|
253
|
+
interface AiCreditsQuote {
|
|
254
|
+
depositAmountG: string;
|
|
255
|
+
streamAmountG: string;
|
|
256
|
+
}
|
|
257
|
+
interface AiCreditsWidgetAdapterState {
|
|
258
|
+
status: AiCreditsWidgetStatus;
|
|
259
|
+
address: string | null;
|
|
260
|
+
chainId: number | null;
|
|
261
|
+
gBalance: string | null;
|
|
262
|
+
gdUsdPerToken: number | null;
|
|
263
|
+
totalCreditUsd: string | null;
|
|
264
|
+
isGoodIdVerified: boolean;
|
|
265
|
+
buyerPubKey: string | null;
|
|
266
|
+
buyerPrvKey: string | null;
|
|
267
|
+
operatorConsented: boolean;
|
|
268
|
+
operatorAddress: string | null;
|
|
269
|
+
minDepositUsd: string | null;
|
|
270
|
+
minStreamUsd: string | null;
|
|
271
|
+
totalGdDepositedG: string | null;
|
|
272
|
+
monthlyStreamG: string | null;
|
|
273
|
+
withdrawableUsd: string | null;
|
|
274
|
+
depositBonusPercent: number;
|
|
275
|
+
streamBonusPercent: number;
|
|
276
|
+
error: string | null;
|
|
277
|
+
activeTab: AiCreditsWidgetTab;
|
|
278
|
+
}
|
|
279
|
+
interface AiCreditsWidgetAdapterActions {
|
|
280
|
+
connect: () => Promise<void>;
|
|
281
|
+
switchChain: () => Promise<void>;
|
|
282
|
+
generateBuyerKey: () => Promise<void>;
|
|
283
|
+
signOperatorConsent: () => Promise<void>;
|
|
284
|
+
syncOperatorConsentFromChain: () => Promise<void>;
|
|
285
|
+
buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
|
|
286
|
+
pay: (quote: AiCreditsQuote) => Promise<void>;
|
|
287
|
+
refresh: () => Promise<void>;
|
|
288
|
+
verifyGoodId: () => Promise<boolean>;
|
|
289
|
+
startPurchase: () => void;
|
|
290
|
+
setActiveTab: (tab: AiCreditsWidgetTab) => void;
|
|
291
|
+
closeChannel: (channelId: string) => Promise<void>;
|
|
292
|
+
withdrawCredits: (amount: string) => Promise<void>;
|
|
293
|
+
retry: () => Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
interface AiCreditsWidgetAdapterResult {
|
|
296
|
+
state: AiCreditsWidgetAdapterState;
|
|
297
|
+
actions: AiCreditsWidgetAdapterActions;
|
|
298
|
+
}
|
|
299
|
+
interface AiCreditsWidgetAdapterFactoryInput {
|
|
300
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
301
|
+
backendUrl?: string;
|
|
302
|
+
}
|
|
303
|
+
type AiCreditsWidgetAdapterFactory = (input: AiCreditsWidgetAdapterFactoryInput) => AiCreditsWidgetAdapterResult;
|
|
304
|
+
interface AiCreditsWidgetAdapterOptions {
|
|
305
|
+
backendClient?: AiCreditsBackendClient;
|
|
306
|
+
chainClient?: AiCreditsChainClient;
|
|
307
|
+
skipVaultPaymentValidation?: boolean;
|
|
308
|
+
prepareSettlement?: (ref: AccountRef, creditUsd: bigint) => void;
|
|
309
|
+
}
|
|
310
|
+
interface AiCreditsPaySuccessDetail {
|
|
311
|
+
address: string;
|
|
312
|
+
chainId: number;
|
|
313
|
+
transactionHash: string;
|
|
314
|
+
buyerPubKey: string;
|
|
315
|
+
creditUsdMicro: string;
|
|
316
|
+
}
|
|
317
|
+
interface AiCreditsPayErrorDetail {
|
|
318
|
+
address: string | null;
|
|
319
|
+
chainId: number | null;
|
|
320
|
+
message: string;
|
|
321
|
+
}
|
|
322
|
+
interface AiCreditsWidgetProps {
|
|
323
|
+
provider?: unknown;
|
|
324
|
+
connectOverride?: () => Promise<void>;
|
|
325
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
326
|
+
backendUrl?: string;
|
|
327
|
+
baseRpcUrl?: string;
|
|
328
|
+
celoRpcUrl?: string;
|
|
329
|
+
fundingVaultAddress?: Address;
|
|
330
|
+
vaultAddress?: Address;
|
|
331
|
+
goodIdAddress?: Address;
|
|
332
|
+
themeOverrides?: GoodWidgetThemeOverrides;
|
|
333
|
+
config?: GoodWidgetConfig;
|
|
334
|
+
defaultTheme?: 'light' | 'dark';
|
|
335
|
+
onPaySuccess?: (detail: AiCreditsPaySuccessDetail) => void;
|
|
336
|
+
onPayError?: (detail: AiCreditsPayErrorDetail) => void;
|
|
337
|
+
adapterFactory?: AiCreditsWidgetAdapterFactory;
|
|
338
|
+
adapterOptions?: AiCreditsWidgetAdapterOptions;
|
|
339
|
+
testId?: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export { type AiCreditsWidgetEnvironment as A, type BuyerOperatorStatus as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryQuery as F, type GdCreditEntry as G, type CreditHistoryResponse as H, type CeloEventsRecordResponse as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorConsentPayloadResponse as L, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SettlementResult as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
|
|
3
|
+
|
|
4
|
+
type Eip712SigningPayload = {
|
|
5
|
+
primaryType: string;
|
|
6
|
+
domain: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
verifyingContract: string;
|
|
11
|
+
};
|
|
12
|
+
types: Record<string, Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}>>;
|
|
16
|
+
message: Record<string, string | number>;
|
|
17
|
+
};
|
|
18
|
+
type BuyerOperatorStatus = {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
account: string;
|
|
21
|
+
buyerAddress: string;
|
|
22
|
+
operatorAddress?: string;
|
|
23
|
+
currentOperator: string;
|
|
24
|
+
operatorAccepted: boolean;
|
|
25
|
+
consentNonce: string;
|
|
26
|
+
};
|
|
27
|
+
type OperatorConsentPayloadResponse = {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
account: string;
|
|
30
|
+
buyerAddress: string;
|
|
31
|
+
typedData?: Eip712SigningPayload;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type AccountRef = {
|
|
35
|
+
payer: string;
|
|
36
|
+
buyer: string;
|
|
37
|
+
};
|
|
38
|
+
type UserCreditProfile = {
|
|
39
|
+
account: string;
|
|
40
|
+
rootAccount: string;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
totalGdDepositedWei: string;
|
|
44
|
+
totalPrincipalUsd: string;
|
|
45
|
+
totalBonusUsd: string;
|
|
46
|
+
totalGDStreamedWei: string;
|
|
47
|
+
totalOutstandingFundingUsd: string;
|
|
48
|
+
streamFlowRateWeiPerSecond: string;
|
|
49
|
+
lastStreamCreditAt?: string;
|
|
50
|
+
};
|
|
51
|
+
type GdCreditEntry = {
|
|
52
|
+
id: string;
|
|
53
|
+
account: string;
|
|
54
|
+
rootAccount: string;
|
|
55
|
+
source: 'deposit' | 'streamUpdate' | 'streamRequest' | 'streamCron';
|
|
56
|
+
gdAmountWei: string;
|
|
57
|
+
principalUsd: string;
|
|
58
|
+
bonusUsd: string;
|
|
59
|
+
totalCreditUsd: string;
|
|
60
|
+
fundingStatus: 'pending' | 'funded' | 'failed';
|
|
61
|
+
fundingTxHash?: string;
|
|
62
|
+
fundingError?: string;
|
|
63
|
+
txHash?: string;
|
|
64
|
+
logIndex?: number;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
streamUpdateMonth: string;
|
|
67
|
+
buyerAddress?: string;
|
|
68
|
+
};
|
|
69
|
+
type AccountCreditResponse = {
|
|
70
|
+
account: string;
|
|
71
|
+
profile: UserCreditProfile;
|
|
72
|
+
};
|
|
73
|
+
type CreditHistoryResponse = {
|
|
74
|
+
account: string;
|
|
75
|
+
items: GdCreditEntry[];
|
|
76
|
+
total: number;
|
|
77
|
+
limit: number;
|
|
78
|
+
offset: number;
|
|
79
|
+
hasMore: boolean;
|
|
80
|
+
};
|
|
81
|
+
type CreditHistoryQuery = {
|
|
82
|
+
limit?: number;
|
|
83
|
+
offset?: number;
|
|
84
|
+
source?: GdCreditEntry['source'];
|
|
85
|
+
fundingStatus?: GdCreditEntry['fundingStatus'];
|
|
86
|
+
from?: string;
|
|
87
|
+
to?: string;
|
|
88
|
+
};
|
|
89
|
+
type AccountView = {
|
|
90
|
+
account: string;
|
|
91
|
+
buyer: string | null;
|
|
92
|
+
profile: UserCreditProfile;
|
|
93
|
+
operator: BuyerOperatorStatus;
|
|
94
|
+
withdrawableUsd: string;
|
|
95
|
+
outstandingFundingUsd: string;
|
|
96
|
+
outstandingFundingCount: number;
|
|
97
|
+
};
|
|
98
|
+
type TransactionsResponse = {
|
|
99
|
+
account: string;
|
|
100
|
+
transactions: GdCreditEntry[];
|
|
101
|
+
nextCursor?: string;
|
|
102
|
+
};
|
|
103
|
+
type CeloEventsRecordResponse = {
|
|
104
|
+
txHash?: string;
|
|
105
|
+
account?: string;
|
|
106
|
+
fromBlock?: string;
|
|
107
|
+
toBlock?: string;
|
|
108
|
+
events: GdCreditEntry[];
|
|
109
|
+
};
|
|
110
|
+
type SettlementResult = {
|
|
111
|
+
totalCreditUsd: string;
|
|
112
|
+
};
|
|
113
|
+
type DiscountConfig = {
|
|
114
|
+
depositBonusPercent: number;
|
|
115
|
+
streamBonusPercent: number;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
|
|
119
|
+
declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
|
|
120
|
+
declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
|
|
121
|
+
type AiCreditsChainClientOptions = {
|
|
122
|
+
baseRpcUrl?: string;
|
|
123
|
+
fundingVaultAddress?: Address;
|
|
124
|
+
celoRpcUrl?: string;
|
|
125
|
+
celoVaultAddress?: Address;
|
|
126
|
+
celoGoodIdAddress?: Address;
|
|
127
|
+
depositsAddress?: Address;
|
|
128
|
+
};
|
|
129
|
+
interface AiCreditsChainClient {
|
|
130
|
+
fetchGdUsdPerToken(): Promise<number>;
|
|
131
|
+
isGoodIdVerified(account: string): Promise<boolean>;
|
|
132
|
+
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
133
|
+
getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
|
|
134
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
135
|
+
getWithdrawableUsd(buyer: string): Promise<string>;
|
|
136
|
+
}
|
|
137
|
+
declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
|
|
138
|
+
|
|
139
|
+
type WithdrawPrincipalRequest = {
|
|
140
|
+
amount: string;
|
|
141
|
+
recipient: string;
|
|
142
|
+
timestamp: number;
|
|
143
|
+
signature: string;
|
|
144
|
+
};
|
|
145
|
+
type ChannelOperationRequest = {
|
|
146
|
+
timestamp?: number;
|
|
147
|
+
signature?: string;
|
|
148
|
+
};
|
|
149
|
+
type BridgeResponse = {
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
txHash?: string;
|
|
152
|
+
};
|
|
153
|
+
type ChannelOperationResponse = {
|
|
154
|
+
channelId: string;
|
|
155
|
+
action: 'close' | 'withdraw';
|
|
156
|
+
bridge: BridgeResponse;
|
|
157
|
+
};
|
|
158
|
+
type WithdrawPrincipalResponse = {
|
|
159
|
+
account: string;
|
|
160
|
+
amountUsd: string;
|
|
161
|
+
bridge: BridgeResponse;
|
|
162
|
+
};
|
|
163
|
+
type OperatorConsentRequest = {
|
|
164
|
+
nonce: string;
|
|
165
|
+
signature: string;
|
|
166
|
+
};
|
|
167
|
+
type OperatorConsentResponse = {
|
|
168
|
+
buyer: string;
|
|
169
|
+
bridge: BridgeResponse;
|
|
170
|
+
};
|
|
171
|
+
declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
|
|
172
|
+
declare function totalCreditUsdFromStatus(status: {
|
|
173
|
+
profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
|
|
174
|
+
}): string;
|
|
175
|
+
type AccountEnrichment = {
|
|
176
|
+
totalCreditUsd: string;
|
|
177
|
+
goodIdVerified: boolean;
|
|
178
|
+
totalGdDepositedG: string;
|
|
179
|
+
monthlyStreamG: string;
|
|
180
|
+
};
|
|
181
|
+
type BuildAccountViewOptions = {
|
|
182
|
+
buyerAddress?: string | null;
|
|
183
|
+
};
|
|
184
|
+
declare function enrichAccountView(view: AccountView, chain: AiCreditsChainClient): Promise<AccountEnrichment>;
|
|
185
|
+
interface AiCreditsBackendClient {
|
|
186
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
187
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
188
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
189
|
+
getOutstanding(payer: string): Promise<{
|
|
190
|
+
outstandingFundingUsd: string;
|
|
191
|
+
count: number;
|
|
192
|
+
}>;
|
|
193
|
+
getTransactions(payer: string, options?: {
|
|
194
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
195
|
+
limit?: number;
|
|
196
|
+
cursor?: string;
|
|
197
|
+
}): Promise<TransactionsResponse>;
|
|
198
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
199
|
+
waitForSettlement(ref: AccountRef, options?: {
|
|
200
|
+
txHashes?: string[];
|
|
201
|
+
previousBalance?: string;
|
|
202
|
+
}): Promise<SettlementResult>;
|
|
203
|
+
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
204
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
205
|
+
submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
206
|
+
}
|
|
207
|
+
declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
|
|
208
|
+
declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
209
|
+
private readonly backendUrl;
|
|
210
|
+
constructor(backendUrl: string);
|
|
211
|
+
getDiscountConfig(): Promise<DiscountConfig>;
|
|
212
|
+
private accountBase;
|
|
213
|
+
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
214
|
+
getCreditHistory(payer: string, options?: CreditHistoryQuery): Promise<CreditHistoryResponse>;
|
|
215
|
+
getOutstanding(payer: string): Promise<{
|
|
216
|
+
outstandingFundingUsd: string;
|
|
217
|
+
count: number;
|
|
218
|
+
}>;
|
|
219
|
+
getTransactions(payer: string, options?: {
|
|
220
|
+
status?: 'pending' | 'funded' | 'failed';
|
|
221
|
+
limit?: number;
|
|
222
|
+
cursor?: string;
|
|
223
|
+
}): Promise<TransactionsResponse>;
|
|
224
|
+
getUsageLog(payer: string): Promise<GdCreditEntry[]>;
|
|
225
|
+
notifyPayment(txHash: string): Promise<CeloEventsRecordResponse>;
|
|
226
|
+
waitForSettlement(ref: AccountRef, options?: {
|
|
227
|
+
txHashes?: string[];
|
|
228
|
+
previousBalance?: string;
|
|
229
|
+
}): Promise<SettlementResult>;
|
|
230
|
+
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
231
|
+
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
232
|
+
submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
233
|
+
}
|
|
234
|
+
declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
235
|
+
private unavailable;
|
|
236
|
+
getDiscountConfig(): Promise<never>;
|
|
237
|
+
getAccountCredit(): Promise<never>;
|
|
238
|
+
getCreditHistory(): Promise<never>;
|
|
239
|
+
getOutstanding(): Promise<never>;
|
|
240
|
+
getTransactions(): Promise<never>;
|
|
241
|
+
notifyPayment(): Promise<never>;
|
|
242
|
+
waitForSettlement(): Promise<never>;
|
|
243
|
+
closeChannel(): Promise<never>;
|
|
244
|
+
withdrawCredits(): Promise<never>;
|
|
245
|
+
submitOperatorConsent(): Promise<never>;
|
|
246
|
+
}
|
|
247
|
+
declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
|
|
248
|
+
declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
|
|
249
|
+
|
|
250
|
+
type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
|
|
251
|
+
type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
|
|
252
|
+
type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
|
|
253
|
+
interface AiCreditsQuote {
|
|
254
|
+
depositAmountG: string;
|
|
255
|
+
streamAmountG: string;
|
|
256
|
+
}
|
|
257
|
+
interface AiCreditsWidgetAdapterState {
|
|
258
|
+
status: AiCreditsWidgetStatus;
|
|
259
|
+
address: string | null;
|
|
260
|
+
chainId: number | null;
|
|
261
|
+
gBalance: string | null;
|
|
262
|
+
gdUsdPerToken: number | null;
|
|
263
|
+
totalCreditUsd: string | null;
|
|
264
|
+
isGoodIdVerified: boolean;
|
|
265
|
+
buyerPubKey: string | null;
|
|
266
|
+
buyerPrvKey: string | null;
|
|
267
|
+
operatorConsented: boolean;
|
|
268
|
+
operatorAddress: string | null;
|
|
269
|
+
minDepositUsd: string | null;
|
|
270
|
+
minStreamUsd: string | null;
|
|
271
|
+
totalGdDepositedG: string | null;
|
|
272
|
+
monthlyStreamG: string | null;
|
|
273
|
+
withdrawableUsd: string | null;
|
|
274
|
+
depositBonusPercent: number;
|
|
275
|
+
streamBonusPercent: number;
|
|
276
|
+
error: string | null;
|
|
277
|
+
activeTab: AiCreditsWidgetTab;
|
|
278
|
+
}
|
|
279
|
+
interface AiCreditsWidgetAdapterActions {
|
|
280
|
+
connect: () => Promise<void>;
|
|
281
|
+
switchChain: () => Promise<void>;
|
|
282
|
+
generateBuyerKey: () => Promise<void>;
|
|
283
|
+
signOperatorConsent: () => Promise<void>;
|
|
284
|
+
syncOperatorConsentFromChain: () => Promise<void>;
|
|
285
|
+
buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
|
|
286
|
+
pay: (quote: AiCreditsQuote) => Promise<void>;
|
|
287
|
+
refresh: () => Promise<void>;
|
|
288
|
+
verifyGoodId: () => Promise<boolean>;
|
|
289
|
+
startPurchase: () => void;
|
|
290
|
+
setActiveTab: (tab: AiCreditsWidgetTab) => void;
|
|
291
|
+
closeChannel: (channelId: string) => Promise<void>;
|
|
292
|
+
withdrawCredits: (amount: string) => Promise<void>;
|
|
293
|
+
retry: () => Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
interface AiCreditsWidgetAdapterResult {
|
|
296
|
+
state: AiCreditsWidgetAdapterState;
|
|
297
|
+
actions: AiCreditsWidgetAdapterActions;
|
|
298
|
+
}
|
|
299
|
+
interface AiCreditsWidgetAdapterFactoryInput {
|
|
300
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
301
|
+
backendUrl?: string;
|
|
302
|
+
}
|
|
303
|
+
type AiCreditsWidgetAdapterFactory = (input: AiCreditsWidgetAdapterFactoryInput) => AiCreditsWidgetAdapterResult;
|
|
304
|
+
interface AiCreditsWidgetAdapterOptions {
|
|
305
|
+
backendClient?: AiCreditsBackendClient;
|
|
306
|
+
chainClient?: AiCreditsChainClient;
|
|
307
|
+
skipVaultPaymentValidation?: boolean;
|
|
308
|
+
prepareSettlement?: (ref: AccountRef, creditUsd: bigint) => void;
|
|
309
|
+
}
|
|
310
|
+
interface AiCreditsPaySuccessDetail {
|
|
311
|
+
address: string;
|
|
312
|
+
chainId: number;
|
|
313
|
+
transactionHash: string;
|
|
314
|
+
buyerPubKey: string;
|
|
315
|
+
creditUsdMicro: string;
|
|
316
|
+
}
|
|
317
|
+
interface AiCreditsPayErrorDetail {
|
|
318
|
+
address: string | null;
|
|
319
|
+
chainId: number | null;
|
|
320
|
+
message: string;
|
|
321
|
+
}
|
|
322
|
+
interface AiCreditsWidgetProps {
|
|
323
|
+
provider?: unknown;
|
|
324
|
+
connectOverride?: () => Promise<void>;
|
|
325
|
+
environment?: AiCreditsWidgetEnvironment;
|
|
326
|
+
backendUrl?: string;
|
|
327
|
+
baseRpcUrl?: string;
|
|
328
|
+
celoRpcUrl?: string;
|
|
329
|
+
fundingVaultAddress?: Address;
|
|
330
|
+
vaultAddress?: Address;
|
|
331
|
+
goodIdAddress?: Address;
|
|
332
|
+
themeOverrides?: GoodWidgetThemeOverrides;
|
|
333
|
+
config?: GoodWidgetConfig;
|
|
334
|
+
defaultTheme?: 'light' | 'dark';
|
|
335
|
+
onPaySuccess?: (detail: AiCreditsPaySuccessDetail) => void;
|
|
336
|
+
onPayError?: (detail: AiCreditsPayErrorDetail) => void;
|
|
337
|
+
adapterFactory?: AiCreditsWidgetAdapterFactory;
|
|
338
|
+
adapterOptions?: AiCreditsWidgetAdapterOptions;
|
|
339
|
+
testId?: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export { type AiCreditsWidgetEnvironment as A, type BuyerOperatorStatus as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryQuery as F, type GdCreditEntry as G, type CreditHistoryResponse as H, type CeloEventsRecordResponse as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorConsentPayloadResponse as L, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SettlementResult as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
|