@odisea-labs/pan 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +159 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.js +149 -0
- package/dist/index.mjs +118 -0
- package/package.json +45 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
interface Wallet {
|
|
2
|
+
id: string;
|
|
3
|
+
address: string;
|
|
4
|
+
chains: string[];
|
|
5
|
+
createdAt: string;
|
|
6
|
+
}
|
|
7
|
+
interface CreateWalletParams {
|
|
8
|
+
userId: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface PanConfig {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PanError$1 {
|
|
18
|
+
error: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
interface RateLimitError extends PanError$1 {
|
|
22
|
+
current: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
}
|
|
25
|
+
type ExecutionStepType = "deposit" | "swap" | "bridge" | "consolidate";
|
|
26
|
+
interface ExecutionStep {
|
|
27
|
+
type: ExecutionStepType;
|
|
28
|
+
}
|
|
29
|
+
interface DepositStep extends ExecutionStep {
|
|
30
|
+
type: "deposit";
|
|
31
|
+
protocol: "aave" | "compound" | "morpho";
|
|
32
|
+
asset: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
chain: string;
|
|
35
|
+
}
|
|
36
|
+
interface SwapStep extends ExecutionStep {
|
|
37
|
+
type: "swap";
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
amount: number;
|
|
41
|
+
chain: string;
|
|
42
|
+
maxSlippage?: number;
|
|
43
|
+
dex?: "1inch" | "uniswap" | "best";
|
|
44
|
+
}
|
|
45
|
+
interface BridgeStep extends ExecutionStep {
|
|
46
|
+
type: "bridge";
|
|
47
|
+
fromChain: string;
|
|
48
|
+
toChain: string;
|
|
49
|
+
asset: string;
|
|
50
|
+
amount: number;
|
|
51
|
+
bridge?: "across" | "stargate" | "best";
|
|
52
|
+
}
|
|
53
|
+
interface ConsolidateStep extends ExecutionStep {
|
|
54
|
+
type: "consolidate";
|
|
55
|
+
assets: string[];
|
|
56
|
+
target: string;
|
|
57
|
+
chain: string;
|
|
58
|
+
}
|
|
59
|
+
type AnyExecutionStep = DepositStep | SwapStep | BridgeStep | ConsolidateStep;
|
|
60
|
+
interface ExecutionPlan {
|
|
61
|
+
steps: AnyExecutionStep[];
|
|
62
|
+
estimatedGas?: number;
|
|
63
|
+
estimatedTime?: number;
|
|
64
|
+
strategy: "simple" | "swap" | "multi-asset" | "consolidate";
|
|
65
|
+
reasoning: string;
|
|
66
|
+
}
|
|
67
|
+
interface ExecutionResult {
|
|
68
|
+
status: "completed" | "failed";
|
|
69
|
+
txHash?: string;
|
|
70
|
+
gasUsed?: number;
|
|
71
|
+
outputData?: Record<string, unknown>;
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
interface Intent {
|
|
75
|
+
id: string;
|
|
76
|
+
developerId: string;
|
|
77
|
+
walletId: string;
|
|
78
|
+
action: string;
|
|
79
|
+
status: "pending" | "planning" | "executing" | "completed" | "failed";
|
|
80
|
+
amount: number;
|
|
81
|
+
executionPlan?: ExecutionPlan;
|
|
82
|
+
results?: ExecutionResult[];
|
|
83
|
+
totalGasUsed?: number;
|
|
84
|
+
totalGasCostUsd?: number;
|
|
85
|
+
errorMessage?: string;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
completedAt?: string;
|
|
89
|
+
}
|
|
90
|
+
interface CreateIntentParams {
|
|
91
|
+
walletId: string;
|
|
92
|
+
action: "lend" | "swap" | "bridge";
|
|
93
|
+
amount: number;
|
|
94
|
+
}
|
|
95
|
+
interface CreateIntentResponse {
|
|
96
|
+
id: string;
|
|
97
|
+
status: string;
|
|
98
|
+
executionPlan: ExecutionPlan;
|
|
99
|
+
estimatedGas?: number;
|
|
100
|
+
}
|
|
101
|
+
interface LendIntentParams {
|
|
102
|
+
walletId: string;
|
|
103
|
+
amount: number;
|
|
104
|
+
}
|
|
105
|
+
interface TokenBalance {
|
|
106
|
+
asset: string;
|
|
107
|
+
balance: string;
|
|
108
|
+
balanceFormatted: string;
|
|
109
|
+
decimals: number;
|
|
110
|
+
valueUsd?: number;
|
|
111
|
+
}
|
|
112
|
+
interface ChainBalance {
|
|
113
|
+
chain: string;
|
|
114
|
+
tokens: TokenBalance[];
|
|
115
|
+
}
|
|
116
|
+
interface WalletBalances {
|
|
117
|
+
walletId: string;
|
|
118
|
+
address: string;
|
|
119
|
+
chains: ChainBalance[];
|
|
120
|
+
totalValueUsd?: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class PanClient {
|
|
124
|
+
private apiKey;
|
|
125
|
+
private baseURL;
|
|
126
|
+
private debug;
|
|
127
|
+
constructor(config: PanConfig);
|
|
128
|
+
request<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
129
|
+
}
|
|
130
|
+
declare class PanError extends Error {
|
|
131
|
+
code: string;
|
|
132
|
+
statusCode: number;
|
|
133
|
+
details?: unknown;
|
|
134
|
+
constructor(errorData: any, statusCode?: number);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare class IntentManager {
|
|
138
|
+
private client;
|
|
139
|
+
constructor(client: PanClient);
|
|
140
|
+
lend(params: LendIntentParams): Promise<CreateIntentResponse>;
|
|
141
|
+
getIntent(intentId: string): Promise<Intent>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class WalletManager {
|
|
145
|
+
private client;
|
|
146
|
+
constructor(client: PanClient);
|
|
147
|
+
create(params: CreateWalletParams): Promise<Wallet>;
|
|
148
|
+
get(userId: string): Promise<Wallet>;
|
|
149
|
+
getBalances(walletId: string): Promise<WalletBalances>;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
declare class Pan {
|
|
153
|
+
private client;
|
|
154
|
+
wallet: WalletManager;
|
|
155
|
+
intent: IntentManager;
|
|
156
|
+
constructor(config: PanConfig);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { type AnyExecutionStep, type BridgeStep, type ChainBalance, type ConsolidateStep, type CreateIntentParams, type CreateIntentResponse, type CreateWalletParams, type DepositStep, type ExecutionPlan, type ExecutionResult, type ExecutionStep, type ExecutionStepType, type Intent, IntentManager, type LendIntentParams, Pan, PanClient, type PanConfig, PanError, type RateLimitError, type SwapStep, type TokenBalance, type Wallet, type WalletBalances, WalletManager };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
interface Wallet {
|
|
2
|
+
id: string;
|
|
3
|
+
address: string;
|
|
4
|
+
chains: string[];
|
|
5
|
+
createdAt: string;
|
|
6
|
+
}
|
|
7
|
+
interface CreateWalletParams {
|
|
8
|
+
userId: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface PanConfig {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PanError$1 {
|
|
18
|
+
error: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
interface RateLimitError extends PanError$1 {
|
|
22
|
+
current: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
}
|
|
25
|
+
type ExecutionStepType = "deposit" | "swap" | "bridge" | "consolidate";
|
|
26
|
+
interface ExecutionStep {
|
|
27
|
+
type: ExecutionStepType;
|
|
28
|
+
}
|
|
29
|
+
interface DepositStep extends ExecutionStep {
|
|
30
|
+
type: "deposit";
|
|
31
|
+
protocol: "aave" | "compound" | "morpho";
|
|
32
|
+
asset: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
chain: string;
|
|
35
|
+
}
|
|
36
|
+
interface SwapStep extends ExecutionStep {
|
|
37
|
+
type: "swap";
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
amount: number;
|
|
41
|
+
chain: string;
|
|
42
|
+
maxSlippage?: number;
|
|
43
|
+
dex?: "1inch" | "uniswap" | "best";
|
|
44
|
+
}
|
|
45
|
+
interface BridgeStep extends ExecutionStep {
|
|
46
|
+
type: "bridge";
|
|
47
|
+
fromChain: string;
|
|
48
|
+
toChain: string;
|
|
49
|
+
asset: string;
|
|
50
|
+
amount: number;
|
|
51
|
+
bridge?: "across" | "stargate" | "best";
|
|
52
|
+
}
|
|
53
|
+
interface ConsolidateStep extends ExecutionStep {
|
|
54
|
+
type: "consolidate";
|
|
55
|
+
assets: string[];
|
|
56
|
+
target: string;
|
|
57
|
+
chain: string;
|
|
58
|
+
}
|
|
59
|
+
type AnyExecutionStep = DepositStep | SwapStep | BridgeStep | ConsolidateStep;
|
|
60
|
+
interface ExecutionPlan {
|
|
61
|
+
steps: AnyExecutionStep[];
|
|
62
|
+
estimatedGas?: number;
|
|
63
|
+
estimatedTime?: number;
|
|
64
|
+
strategy: "simple" | "swap" | "multi-asset" | "consolidate";
|
|
65
|
+
reasoning: string;
|
|
66
|
+
}
|
|
67
|
+
interface ExecutionResult {
|
|
68
|
+
status: "completed" | "failed";
|
|
69
|
+
txHash?: string;
|
|
70
|
+
gasUsed?: number;
|
|
71
|
+
outputData?: Record<string, unknown>;
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
interface Intent {
|
|
75
|
+
id: string;
|
|
76
|
+
developerId: string;
|
|
77
|
+
walletId: string;
|
|
78
|
+
action: string;
|
|
79
|
+
status: "pending" | "planning" | "executing" | "completed" | "failed";
|
|
80
|
+
amount: number;
|
|
81
|
+
executionPlan?: ExecutionPlan;
|
|
82
|
+
results?: ExecutionResult[];
|
|
83
|
+
totalGasUsed?: number;
|
|
84
|
+
totalGasCostUsd?: number;
|
|
85
|
+
errorMessage?: string;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
completedAt?: string;
|
|
89
|
+
}
|
|
90
|
+
interface CreateIntentParams {
|
|
91
|
+
walletId: string;
|
|
92
|
+
action: "lend" | "swap" | "bridge";
|
|
93
|
+
amount: number;
|
|
94
|
+
}
|
|
95
|
+
interface CreateIntentResponse {
|
|
96
|
+
id: string;
|
|
97
|
+
status: string;
|
|
98
|
+
executionPlan: ExecutionPlan;
|
|
99
|
+
estimatedGas?: number;
|
|
100
|
+
}
|
|
101
|
+
interface LendIntentParams {
|
|
102
|
+
walletId: string;
|
|
103
|
+
amount: number;
|
|
104
|
+
}
|
|
105
|
+
interface TokenBalance {
|
|
106
|
+
asset: string;
|
|
107
|
+
balance: string;
|
|
108
|
+
balanceFormatted: string;
|
|
109
|
+
decimals: number;
|
|
110
|
+
valueUsd?: number;
|
|
111
|
+
}
|
|
112
|
+
interface ChainBalance {
|
|
113
|
+
chain: string;
|
|
114
|
+
tokens: TokenBalance[];
|
|
115
|
+
}
|
|
116
|
+
interface WalletBalances {
|
|
117
|
+
walletId: string;
|
|
118
|
+
address: string;
|
|
119
|
+
chains: ChainBalance[];
|
|
120
|
+
totalValueUsd?: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class PanClient {
|
|
124
|
+
private apiKey;
|
|
125
|
+
private baseURL;
|
|
126
|
+
private debug;
|
|
127
|
+
constructor(config: PanConfig);
|
|
128
|
+
request<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
129
|
+
}
|
|
130
|
+
declare class PanError extends Error {
|
|
131
|
+
code: string;
|
|
132
|
+
statusCode: number;
|
|
133
|
+
details?: unknown;
|
|
134
|
+
constructor(errorData: any, statusCode?: number);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare class IntentManager {
|
|
138
|
+
private client;
|
|
139
|
+
constructor(client: PanClient);
|
|
140
|
+
lend(params: LendIntentParams): Promise<CreateIntentResponse>;
|
|
141
|
+
getIntent(intentId: string): Promise<Intent>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class WalletManager {
|
|
145
|
+
private client;
|
|
146
|
+
constructor(client: PanClient);
|
|
147
|
+
create(params: CreateWalletParams): Promise<Wallet>;
|
|
148
|
+
get(userId: string): Promise<Wallet>;
|
|
149
|
+
getBalances(walletId: string): Promise<WalletBalances>;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
declare class Pan {
|
|
153
|
+
private client;
|
|
154
|
+
wallet: WalletManager;
|
|
155
|
+
intent: IntentManager;
|
|
156
|
+
constructor(config: PanConfig);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { type AnyExecutionStep, type BridgeStep, type ChainBalance, type ConsolidateStep, type CreateIntentParams, type CreateIntentResponse, type CreateWalletParams, type DepositStep, type ExecutionPlan, type ExecutionResult, type ExecutionStep, type ExecutionStepType, type Intent, IntentManager, type LendIntentParams, Pan, PanClient, type PanConfig, PanError, type RateLimitError, type SwapStep, type TokenBalance, type Wallet, type WalletBalances, WalletManager };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
IntentManager: () => IntentManager,
|
|
24
|
+
Pan: () => Pan,
|
|
25
|
+
PanClient: () => PanClient,
|
|
26
|
+
PanError: () => PanError,
|
|
27
|
+
WalletManager: () => WalletManager
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/client.ts
|
|
32
|
+
var PanClient = class {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseURL = config.baseURL || "https://api.pan.com";
|
|
36
|
+
this.debug = config.debug || false;
|
|
37
|
+
}
|
|
38
|
+
async request(endpoint, options = {}) {
|
|
39
|
+
const url = `${this.baseURL}${endpoint}`;
|
|
40
|
+
const headers = {
|
|
41
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
...options.headers
|
|
44
|
+
};
|
|
45
|
+
if (this.debug) {
|
|
46
|
+
console.log(`[pan SDK] ${options.method || "GET"} ${url}`);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch(url, {
|
|
50
|
+
...options,
|
|
51
|
+
headers
|
|
52
|
+
});
|
|
53
|
+
const contentType = response.headers.get("content-type");
|
|
54
|
+
if (!contentType?.includes("application/json")) {
|
|
55
|
+
const text = await response.text();
|
|
56
|
+
if (this.debug) {
|
|
57
|
+
console.log("[pan SDK] Non-JSON response:", text);
|
|
58
|
+
}
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Failed to parse JSON. Response: ${text.substring(0, 200)}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const data = await response.json();
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new PanError(data, response.status);
|
|
66
|
+
}
|
|
67
|
+
if (this.debug) {
|
|
68
|
+
console.log("[pan SDK] Response:", data);
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error instanceof PanError) throw error;
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Network error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var PanError = class extends Error {
|
|
80
|
+
constructor(errorData, statusCode) {
|
|
81
|
+
super(errorData.message || "An error occurred");
|
|
82
|
+
this.name = "PanError";
|
|
83
|
+
this.code = errorData.error || "UNKNOWN_ERROR";
|
|
84
|
+
this.statusCode = statusCode || errorData.statusCode || 500;
|
|
85
|
+
this.details = errorData;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/intent.ts
|
|
90
|
+
var IntentManager = class {
|
|
91
|
+
constructor(client) {
|
|
92
|
+
this.client = client;
|
|
93
|
+
}
|
|
94
|
+
async lend(params) {
|
|
95
|
+
return this.client.request("/api/v1/intents", {
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: JSON.stringify({
|
|
98
|
+
walletId: params.walletId,
|
|
99
|
+
action: "lend",
|
|
100
|
+
amount: params.amount
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async getIntent(intentId) {
|
|
105
|
+
return this.client.request(`/api/v1/intents/${intentId}`, {
|
|
106
|
+
method: "GET"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/wallet.ts
|
|
112
|
+
var WalletManager = class {
|
|
113
|
+
constructor(client) {
|
|
114
|
+
this.client = client;
|
|
115
|
+
}
|
|
116
|
+
async create(params) {
|
|
117
|
+
return this.client.request("/api/v1/wallets", {
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: JSON.stringify(params)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async get(userId) {
|
|
123
|
+
return this.client.request(`/api/v1/wallets/${userId}`, {
|
|
124
|
+
method: "GET"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async getBalances(walletId) {
|
|
128
|
+
return this.client.request(`/api/v1/balances/${walletId}`, {
|
|
129
|
+
method: "GET"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/index.ts
|
|
135
|
+
var Pan = class {
|
|
136
|
+
constructor(config) {
|
|
137
|
+
this.client = new PanClient(config);
|
|
138
|
+
this.wallet = new WalletManager(this.client);
|
|
139
|
+
this.intent = new IntentManager(this.client);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
IntentManager,
|
|
145
|
+
Pan,
|
|
146
|
+
PanClient,
|
|
147
|
+
PanError,
|
|
148
|
+
WalletManager
|
|
149
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var PanClient = class {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.apiKey = config.apiKey;
|
|
5
|
+
this.baseURL = config.baseURL || "https://api.pan.com";
|
|
6
|
+
this.debug = config.debug || false;
|
|
7
|
+
}
|
|
8
|
+
async request(endpoint, options = {}) {
|
|
9
|
+
const url = `${this.baseURL}${endpoint}`;
|
|
10
|
+
const headers = {
|
|
11
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
...options.headers
|
|
14
|
+
};
|
|
15
|
+
if (this.debug) {
|
|
16
|
+
console.log(`[pan SDK] ${options.method || "GET"} ${url}`);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
...options,
|
|
21
|
+
headers
|
|
22
|
+
});
|
|
23
|
+
const contentType = response.headers.get("content-type");
|
|
24
|
+
if (!contentType?.includes("application/json")) {
|
|
25
|
+
const text = await response.text();
|
|
26
|
+
if (this.debug) {
|
|
27
|
+
console.log("[pan SDK] Non-JSON response:", text);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Failed to parse JSON. Response: ${text.substring(0, 200)}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
throw new PanError(data, response.status);
|
|
36
|
+
}
|
|
37
|
+
if (this.debug) {
|
|
38
|
+
console.log("[pan SDK] Response:", data);
|
|
39
|
+
}
|
|
40
|
+
return data;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof PanError) throw error;
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Network error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var PanError = class extends Error {
|
|
50
|
+
constructor(errorData, statusCode) {
|
|
51
|
+
super(errorData.message || "An error occurred");
|
|
52
|
+
this.name = "PanError";
|
|
53
|
+
this.code = errorData.error || "UNKNOWN_ERROR";
|
|
54
|
+
this.statusCode = statusCode || errorData.statusCode || 500;
|
|
55
|
+
this.details = errorData;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/intent.ts
|
|
60
|
+
var IntentManager = class {
|
|
61
|
+
constructor(client) {
|
|
62
|
+
this.client = client;
|
|
63
|
+
}
|
|
64
|
+
async lend(params) {
|
|
65
|
+
return this.client.request("/api/v1/intents", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
walletId: params.walletId,
|
|
69
|
+
action: "lend",
|
|
70
|
+
amount: params.amount
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async getIntent(intentId) {
|
|
75
|
+
return this.client.request(`/api/v1/intents/${intentId}`, {
|
|
76
|
+
method: "GET"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/wallet.ts
|
|
82
|
+
var WalletManager = class {
|
|
83
|
+
constructor(client) {
|
|
84
|
+
this.client = client;
|
|
85
|
+
}
|
|
86
|
+
async create(params) {
|
|
87
|
+
return this.client.request("/api/v1/wallets", {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: JSON.stringify(params)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async get(userId) {
|
|
93
|
+
return this.client.request(`/api/v1/wallets/${userId}`, {
|
|
94
|
+
method: "GET"
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async getBalances(walletId) {
|
|
98
|
+
return this.client.request(`/api/v1/balances/${walletId}`, {
|
|
99
|
+
method: "GET"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/index.ts
|
|
105
|
+
var Pan = class {
|
|
106
|
+
constructor(config) {
|
|
107
|
+
this.client = new PanClient(config);
|
|
108
|
+
this.wallet = new WalletManager(this.client);
|
|
109
|
+
this.intent = new IntentManager(this.client);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
IntentManager,
|
|
114
|
+
Pan,
|
|
115
|
+
PanClient,
|
|
116
|
+
PanError,
|
|
117
|
+
WalletManager
|
|
118
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@odisea-labs/pan",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Intent-based DeFi API SDK",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
20
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"defi",
|
|
24
|
+
"intent",
|
|
25
|
+
"web3",
|
|
26
|
+
"sdk"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "0disea",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/0disea/pan.git",
|
|
33
|
+
"directory": "packages/sdk"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/0disea/pan#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/0disea/pan/issues"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"tsup": "^8.3.5"
|
|
44
|
+
}
|
|
45
|
+
}
|