@cann4n/actions-blend 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/blendActionProvider.d.ts +88 -0
- package/dist/blendActionProvider.d.ts.map +1 -0
- package/dist/blendActionProvider.js +152 -0
- package/dist/blendActionProvider.js.map +1 -0
- package/dist/blendActionProvider.test.d.ts +2 -0
- package/dist/blendActionProvider.test.d.ts.map +1 -0
- package/dist/blendActionProvider.test.js +83 -0
- package/dist/blendActionProvider.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/mockBlendPool.d.ts +12 -0
- package/dist/mockBlendPool.d.ts.map +1 -0
- package/dist/mockBlendPool.js +71 -0
- package/dist/mockBlendPool.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { WalletProvider, StellarNetwork } from "@cann4n/core";
|
|
3
|
+
import { ActionProvider } from "@cann4n/core";
|
|
4
|
+
declare const DepositCollateralSchema: z.ZodObject<{
|
|
5
|
+
poolId: z.ZodString;
|
|
6
|
+
asset: z.ZodString;
|
|
7
|
+
amount: z.ZodString;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
asset: string;
|
|
10
|
+
poolId: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
}, {
|
|
13
|
+
asset: string;
|
|
14
|
+
poolId: string;
|
|
15
|
+
amount: string;
|
|
16
|
+
}>;
|
|
17
|
+
declare const WithdrawCollateralSchema: z.ZodObject<{
|
|
18
|
+
poolId: z.ZodString;
|
|
19
|
+
asset: z.ZodString;
|
|
20
|
+
amount: z.ZodString;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
asset: string;
|
|
23
|
+
poolId: string;
|
|
24
|
+
amount: string;
|
|
25
|
+
}, {
|
|
26
|
+
asset: string;
|
|
27
|
+
poolId: string;
|
|
28
|
+
amount: string;
|
|
29
|
+
}>;
|
|
30
|
+
declare const BorrowSchema: z.ZodObject<{
|
|
31
|
+
poolId: z.ZodString;
|
|
32
|
+
asset: z.ZodString;
|
|
33
|
+
amount: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
asset: string;
|
|
36
|
+
poolId: string;
|
|
37
|
+
amount: string;
|
|
38
|
+
}, {
|
|
39
|
+
asset: string;
|
|
40
|
+
poolId: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
}>;
|
|
43
|
+
declare const RepaySchema: z.ZodObject<{
|
|
44
|
+
poolId: z.ZodString;
|
|
45
|
+
asset: z.ZodString;
|
|
46
|
+
amount: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
asset: string;
|
|
49
|
+
poolId: string;
|
|
50
|
+
amount: string;
|
|
51
|
+
}, {
|
|
52
|
+
asset: string;
|
|
53
|
+
poolId: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
}>;
|
|
56
|
+
declare const PoolInfoSchema: z.ZodObject<{
|
|
57
|
+
poolId: z.ZodString;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
poolId: string;
|
|
60
|
+
}, {
|
|
61
|
+
poolId: string;
|
|
62
|
+
}>;
|
|
63
|
+
declare const UserPositionsSchema: z.ZodObject<{
|
|
64
|
+
poolId: z.ZodString;
|
|
65
|
+
user: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
poolId: string;
|
|
68
|
+
user?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
poolId: string;
|
|
71
|
+
user?: string | undefined;
|
|
72
|
+
}>;
|
|
73
|
+
export declare class BlendProvider extends ActionProvider {
|
|
74
|
+
private pools;
|
|
75
|
+
constructor();
|
|
76
|
+
private getPool;
|
|
77
|
+
depositCollateral(_wallet: WalletProvider, args: z.infer<typeof DepositCollateralSchema>): Promise<string>;
|
|
78
|
+
withdrawCollateral(_wallet: WalletProvider, args: z.infer<typeof WithdrawCollateralSchema>): Promise<string>;
|
|
79
|
+
borrow(_wallet: WalletProvider, args: z.infer<typeof BorrowSchema>): Promise<string>;
|
|
80
|
+
repay(_wallet: WalletProvider, args: z.infer<typeof RepaySchema>): Promise<string>;
|
|
81
|
+
getPoolInfo(_wallet: WalletProvider, args: z.infer<typeof PoolInfoSchema>): Promise<string>;
|
|
82
|
+
getUserPositions(_wallet: WalletProvider, args: z.infer<typeof UserPositionsSchema>): Promise<string>;
|
|
83
|
+
supportsNetwork(network: StellarNetwork): boolean;
|
|
84
|
+
}
|
|
85
|
+
/** Create a Blend action provider for lending and borrowing. */
|
|
86
|
+
export declare const blendActions: () => BlendProvider;
|
|
87
|
+
export {};
|
|
88
|
+
//# sourceMappingURL=blendActionProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blendActionProvider.d.ts","sourceRoot":"","sources":["../src/blendActionProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAU,cAAc,EAAE,MAAM,cAAc,CAAC;AAGtD,QAAA,MAAM,uBAAuB;;;;;;;;;;;;EAI3B,CAAC;AAEH,QAAA,MAAM,wBAAwB;;;;;;;;;;;;EAI5B,CAAC;AAEH,QAAA,MAAM,YAAY;;;;;;;;;;;;EAIhB,CAAC;AAEH,QAAA,MAAM,WAAW;;;;;;;;;;;;EAIf,CAAC;AAEH,QAAA,MAAM,cAAc;;;;;;EAElB,CAAC;AAEH,QAAA,MAAM,mBAAmB;;;;;;;;;EAGvB,CAAC;AAEH,qBAAa,aAAc,SAAQ,cAAc;IAC/C,OAAO,CAAC,KAAK,CAAyC;;IAMtD,OAAO,CAAC,OAAO;IAeT,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAY1G,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAY5G,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAYpF,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAWlF,WAAW,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAW3F,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAK3G,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;CAGlD;AAED,gEAAgE;AAChE,eAAO,MAAM,YAAY,qBAA4B,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { Action, ActionProvider } from "@cann4n/core";
|
|
12
|
+
import { MockBlendPool } from "./mockBlendPool";
|
|
13
|
+
const DepositCollateralSchema = z.object({
|
|
14
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
15
|
+
asset: z.string().describe("Asset contract address to deposit"),
|
|
16
|
+
amount: z.string().describe("Amount to deposit (in asset's base units)"),
|
|
17
|
+
});
|
|
18
|
+
const WithdrawCollateralSchema = z.object({
|
|
19
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
20
|
+
asset: z.string().describe("Asset contract address to withdraw"),
|
|
21
|
+
amount: z.string().describe("Amount to withdraw"),
|
|
22
|
+
});
|
|
23
|
+
const BorrowSchema = z.object({
|
|
24
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
25
|
+
asset: z.string().describe("Asset contract address to borrow"),
|
|
26
|
+
amount: z.string().describe("Amount to borrow"),
|
|
27
|
+
});
|
|
28
|
+
const RepaySchema = z.object({
|
|
29
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
30
|
+
asset: z.string().describe("Asset contract address to repay"),
|
|
31
|
+
amount: z.string().describe("Amount to repay"),
|
|
32
|
+
});
|
|
33
|
+
const PoolInfoSchema = z.object({
|
|
34
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
35
|
+
});
|
|
36
|
+
const UserPositionsSchema = z.object({
|
|
37
|
+
poolId: z.string().describe("Blend pool contract ID"),
|
|
38
|
+
user: z.string().optional().describe("User address (defaults to wallet)"),
|
|
39
|
+
});
|
|
40
|
+
export class BlendProvider extends ActionProvider {
|
|
41
|
+
pools = new Map();
|
|
42
|
+
constructor() {
|
|
43
|
+
super("blend", []);
|
|
44
|
+
}
|
|
45
|
+
getPool(_poolId) {
|
|
46
|
+
if (!this.pools.has(_poolId)) {
|
|
47
|
+
this.pools.set(_poolId, new MockBlendPool());
|
|
48
|
+
}
|
|
49
|
+
return this.pools.get(_poolId);
|
|
50
|
+
}
|
|
51
|
+
async depositCollateral(_wallet, args) {
|
|
52
|
+
return this.getPool(args.poolId).depositCollateral(_wallet.getAddress(), args.asset, BigInt(args.amount));
|
|
53
|
+
}
|
|
54
|
+
async withdrawCollateral(_wallet, args) {
|
|
55
|
+
return this.getPool(args.poolId).withdrawCollateral(_wallet.getAddress(), args.asset, BigInt(args.amount));
|
|
56
|
+
}
|
|
57
|
+
async borrow(_wallet, args) {
|
|
58
|
+
return this.getPool(args.poolId).borrow(_wallet.getAddress(), args.asset, BigInt(args.amount));
|
|
59
|
+
}
|
|
60
|
+
async repay(_wallet, args) {
|
|
61
|
+
return this.getPool(args.poolId).repay(_wallet.getAddress(), args.asset, BigInt(args.amount));
|
|
62
|
+
}
|
|
63
|
+
async getPoolInfo(_wallet, args) {
|
|
64
|
+
return this.getPool(args.poolId).getPoolInfo();
|
|
65
|
+
}
|
|
66
|
+
async getUserPositions(_wallet, args) {
|
|
67
|
+
const user = args.user || _wallet.getAddress();
|
|
68
|
+
return this.getPool(args.poolId).getUserPositions(user);
|
|
69
|
+
}
|
|
70
|
+
supportsNetwork(network) {
|
|
71
|
+
return ["testnet", "pubnet"].includes(network.networkId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
__decorate([
|
|
75
|
+
Action({
|
|
76
|
+
name: "deposit_collateral",
|
|
77
|
+
description: "Deposit collateral into a Blend lending pool",
|
|
78
|
+
similes: ["lend", "supply", "deposit to blend"],
|
|
79
|
+
schema: DepositCollateralSchema,
|
|
80
|
+
returnDirect: true,
|
|
81
|
+
needsWallet: true,
|
|
82
|
+
}),
|
|
83
|
+
__metadata("design:type", Function),
|
|
84
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
85
|
+
__metadata("design:returntype", Promise)
|
|
86
|
+
], BlendProvider.prototype, "depositCollateral", null);
|
|
87
|
+
__decorate([
|
|
88
|
+
Action({
|
|
89
|
+
name: "withdraw_collateral",
|
|
90
|
+
description: "Withdraw collateral from a Blend lending pool",
|
|
91
|
+
similes: ["withdraw", "remove collateral", "withdraw from blend"],
|
|
92
|
+
schema: WithdrawCollateralSchema,
|
|
93
|
+
returnDirect: true,
|
|
94
|
+
needsWallet: true,
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], BlendProvider.prototype, "withdrawCollateral", null);
|
|
100
|
+
__decorate([
|
|
101
|
+
Action({
|
|
102
|
+
name: "borrow",
|
|
103
|
+
description: "Borrow assets from a Blend lending pool",
|
|
104
|
+
similes: ["borrow from blend"],
|
|
105
|
+
schema: BorrowSchema,
|
|
106
|
+
returnDirect: true,
|
|
107
|
+
needsWallet: true,
|
|
108
|
+
}),
|
|
109
|
+
__metadata("design:type", Function),
|
|
110
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
111
|
+
__metadata("design:returntype", Promise)
|
|
112
|
+
], BlendProvider.prototype, "borrow", null);
|
|
113
|
+
__decorate([
|
|
114
|
+
Action({
|
|
115
|
+
name: "repay",
|
|
116
|
+
description: "Repay borrowed assets to a Blend lending pool",
|
|
117
|
+
similes: ["repay blend"],
|
|
118
|
+
schema: RepaySchema,
|
|
119
|
+
returnDirect: true,
|
|
120
|
+
needsWallet: true,
|
|
121
|
+
}),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], BlendProvider.prototype, "repay", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
Action({
|
|
128
|
+
name: "get_pool_info",
|
|
129
|
+
description: "Get information about a Blend lending pool",
|
|
130
|
+
similes: ["blend pool details", "pool info"],
|
|
131
|
+
schema: PoolInfoSchema,
|
|
132
|
+
needsWallet: true,
|
|
133
|
+
}),
|
|
134
|
+
__metadata("design:type", Function),
|
|
135
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
136
|
+
__metadata("design:returntype", Promise)
|
|
137
|
+
], BlendProvider.prototype, "getPoolInfo", null);
|
|
138
|
+
__decorate([
|
|
139
|
+
Action({
|
|
140
|
+
name: "get_user_positions",
|
|
141
|
+
description: "Get a user's positions in a Blend pool",
|
|
142
|
+
similes: ["my blend positions", "blend portfolio"],
|
|
143
|
+
schema: UserPositionsSchema,
|
|
144
|
+
needsWallet: true,
|
|
145
|
+
}),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [Function, void 0]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], BlendProvider.prototype, "getUserPositions", null);
|
|
150
|
+
/** Create a Blend action provider for lending and borrowing. */
|
|
151
|
+
export const blendActions = () => new BlendProvider();
|
|
152
|
+
//# sourceMappingURL=blendActionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blendActionProvider.js","sourceRoot":"","sources":["../src/blendActionProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IACrD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IAC/D,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2CAA2C,C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,IAAI;QAClB,WAAW,EAAE,IAAI;KAClB,CAAC;;;;uDAGD;AAUK;IARL,MAAM,CAAC;QACN,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,yCAAyC;QACtD,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,MAAM,EAAE,YAAY;QACpB,YAAY,EAAE,IAAI;QAClB,WAAW,EAAE,IAAI;KAClB,CAAC;;;;2CAGD;AAUK;IARL,MAAM,CAAC;QACN,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,+CAA+C;QAC5D,OAAO,EAAE,CAAC,aAAa,CAAC;QACxB,MAAM,EAAE,WAAW;QACnB,YAAY,EAAE,IAAI;QAClB,WAAW,EAAE,IAAI;KAClB,CAAC;;;;0CAGD;AASK;IAPL,MAAM,CAAC;QACN,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,4CAA4C;QACzD,OAAO,EAAE,CAAC,oBAAoB,EAAE,WAAW,CAAC;QAC5C,MAAM,EAAE,cAAc;QACtB,WAAW,EAAE,IAAI;KAClB,CAAC;;;;gDAGD;AASK;IAPL,MAAM,CAAC;QACN,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,wCAAwC;QACrD,OAAO,EAAE,CAAC,oBAAoB,EAAE,iBAAiB,CAAC;QAClD,MAAM,EAAE,mBAAmB;QAC3B,WAAW,EAAE,IAAI;KAClB,CAAC;;;;qDAID;AAOH,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blendActionProvider.test.d.ts","sourceRoot":"","sources":["../src/blendActionProvider.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { MockWalletProvider } from "@cann4n/core";
|
|
3
|
+
import { BlendProvider } from "./blendActionProvider";
|
|
4
|
+
describe("BlendProvider", () => {
|
|
5
|
+
const wallet = new MockWalletProvider();
|
|
6
|
+
const provider = new BlendProvider();
|
|
7
|
+
it("should provide blend actions", () => {
|
|
8
|
+
const actions = provider.getActions(wallet);
|
|
9
|
+
const names = actions.map((a) => a.name);
|
|
10
|
+
expect(names).toContain("blend_deposit_collateral");
|
|
11
|
+
expect(names).toContain("blend_withdraw_collateral");
|
|
12
|
+
expect(names).toContain("blend_borrow");
|
|
13
|
+
expect(names).toContain("blend_repay");
|
|
14
|
+
expect(names).toContain("blend_get_pool_info");
|
|
15
|
+
expect(names).toContain("blend_get_user_positions");
|
|
16
|
+
});
|
|
17
|
+
it("should describe actions for LLM", () => {
|
|
18
|
+
const actions = provider.getActions(wallet);
|
|
19
|
+
const deposit = actions.find((a) => a.name === "blend_deposit_collateral");
|
|
20
|
+
expect(deposit.description).toContain("Deposit collateral");
|
|
21
|
+
expect(deposit.similes.length).toBeGreaterThan(0);
|
|
22
|
+
});
|
|
23
|
+
it("should deposit collateral", async () => {
|
|
24
|
+
const actions = provider.getActions(wallet);
|
|
25
|
+
const deposit = actions.find((a) => a.name === "blend_deposit_collateral");
|
|
26
|
+
const result = await deposit.invoke({
|
|
27
|
+
poolId: "test_pool",
|
|
28
|
+
asset: "USDC",
|
|
29
|
+
amount: "1000000",
|
|
30
|
+
});
|
|
31
|
+
expect(result).toContain("Deposited");
|
|
32
|
+
expect(result).toContain("USDC");
|
|
33
|
+
});
|
|
34
|
+
it("should borrow from pool", async () => {
|
|
35
|
+
const actions = provider.getActions(wallet);
|
|
36
|
+
const borrow = actions.find((a) => a.name === "blend_borrow");
|
|
37
|
+
const result = await borrow.invoke({
|
|
38
|
+
poolId: "test_pool",
|
|
39
|
+
asset: "XLM",
|
|
40
|
+
amount: "5000000",
|
|
41
|
+
});
|
|
42
|
+
expect(result).toContain("Borrowed");
|
|
43
|
+
expect(result).toContain("XLM");
|
|
44
|
+
});
|
|
45
|
+
it("should repay borrow", async () => {
|
|
46
|
+
const actions = provider.getActions(wallet);
|
|
47
|
+
const repay = actions.find((a) => a.name === "blend_repay");
|
|
48
|
+
const result = await repay.invoke({
|
|
49
|
+
poolId: "test_pool",
|
|
50
|
+
asset: "XLM",
|
|
51
|
+
amount: "5000000",
|
|
52
|
+
});
|
|
53
|
+
expect(result).toContain("Repaid");
|
|
54
|
+
});
|
|
55
|
+
it("should get pool info", async () => {
|
|
56
|
+
const actions = provider.getActions(wallet);
|
|
57
|
+
const info = actions.find((a) => a.name === "blend_get_pool_info");
|
|
58
|
+
const result = await info.invoke({ poolId: "test_pool" });
|
|
59
|
+
expect(result).toContain("Mock Blend Pool");
|
|
60
|
+
expect(result).toContain("USDC");
|
|
61
|
+
expect(result).toContain("XLM");
|
|
62
|
+
});
|
|
63
|
+
it("should get user positions", async () => {
|
|
64
|
+
const actions = provider.getActions(wallet);
|
|
65
|
+
const positions = actions.find((a) => a.name === "blend_get_user_positions");
|
|
66
|
+
const result = await positions.invoke({ poolId: "test_pool" });
|
|
67
|
+
expect(result).not.toBe("");
|
|
68
|
+
});
|
|
69
|
+
it("should withdraw collateral", async () => {
|
|
70
|
+
const actions = provider.getActions(wallet);
|
|
71
|
+
const withdraw = actions.find((a) => a.name === "blend_withdraw_collateral");
|
|
72
|
+
const result = await withdraw.invoke({
|
|
73
|
+
poolId: "test_pool",
|
|
74
|
+
asset: "USDC",
|
|
75
|
+
amount: "100000",
|
|
76
|
+
});
|
|
77
|
+
expect(result).toContain("Withdrew");
|
|
78
|
+
});
|
|
79
|
+
it("should reject unsupported network", () => {
|
|
80
|
+
expect(provider.supportsNetwork({ protocolFamily: "evm", networkId: "ethereum" })).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=blendActionProvider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blendActionProvider.test.js","sourceRoot":"","sources":["../src/blendActionProvider.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EA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AAC,IAAI,KAAK,0BAA0B,CAAE,CAAC;QAC9E,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,2BAA2B,CAAE,CAAC;QAC9E,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;YACnC,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class MockBlendPool {
|
|
2
|
+
private reserves;
|
|
3
|
+
private userPositions;
|
|
4
|
+
constructor();
|
|
5
|
+
getPoolInfo(): string;
|
|
6
|
+
depositCollateral(user: string, asset: string, amount: bigint): string;
|
|
7
|
+
withdrawCollateral(user: string, asset: string, amount: bigint): string;
|
|
8
|
+
borrow(user: string, asset: string, amount: bigint): string;
|
|
9
|
+
repay(user: string, asset: string, amount: bigint): string;
|
|
10
|
+
getUserPositions(user: string): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=mockBlendPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockBlendPool.d.ts","sourceRoot":"","sources":["../src/mockBlendPool.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAgH;IAChI,OAAO,CAAC,aAAa,CAA+E;;IAOpG,WAAW,IAAI,MAAM;IAOrB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAYtE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAUvE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAa3D,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAU1D,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAOvC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export class MockBlendPool {
|
|
2
|
+
reserves = new Map();
|
|
3
|
+
userPositions = new Map();
|
|
4
|
+
constructor() {
|
|
5
|
+
this.reserves.set("USDC", { totalSupply: 1000000000000n, totalBorrow: 500000000000n, supplyRate: 0.05, borrowRate: 0.08 });
|
|
6
|
+
this.reserves.set("XLM", { totalSupply: 100000000000n, totalBorrow: 50000000000n, supplyRate: 0.03, borrowRate: 0.06 });
|
|
7
|
+
}
|
|
8
|
+
getPoolInfo() {
|
|
9
|
+
const entries = Array.from(this.reserves.entries()).map(([asset, r]) => `${asset}: Supply=${r.totalSupply} Borrow=${r.totalBorrow} SupplyAPR=${(r.supplyRate * 100).toFixed(2)}% BorrowAPR=${(r.borrowRate * 100).toFixed(2)}%`);
|
|
10
|
+
return `Mock Blend Pool\n${entries.join("\n")}`;
|
|
11
|
+
}
|
|
12
|
+
depositCollateral(user, asset, amount) {
|
|
13
|
+
const reserve = this.reserves.get(asset);
|
|
14
|
+
if (!reserve)
|
|
15
|
+
return `Error: Unknown asset ${asset}`;
|
|
16
|
+
reserve.totalSupply += amount;
|
|
17
|
+
if (!this.userPositions.has(user))
|
|
18
|
+
this.userPositions.set(user, new Map());
|
|
19
|
+
const pos = this.userPositions.get(user);
|
|
20
|
+
const current = pos.get(asset) || { collateral: 0n, borrow: 0n };
|
|
21
|
+
current.collateral += amount;
|
|
22
|
+
pos.set(asset, current);
|
|
23
|
+
return `Deposited ${amount} ${asset} as collateral. Total collateral: ${current.collateral}`;
|
|
24
|
+
}
|
|
25
|
+
withdrawCollateral(user, asset, amount) {
|
|
26
|
+
const reserve = this.reserves.get(asset);
|
|
27
|
+
if (!reserve)
|
|
28
|
+
return `Error: Unknown asset ${asset}`;
|
|
29
|
+
const pos = this.userPositions.get(user)?.get(asset);
|
|
30
|
+
if (!pos || pos.collateral < amount)
|
|
31
|
+
return `Error: Insufficient collateral`;
|
|
32
|
+
reserve.totalSupply -= amount;
|
|
33
|
+
pos.collateral -= amount;
|
|
34
|
+
return `Withdrew ${amount} ${asset} collateral. Remaining collateral: ${pos.collateral}`;
|
|
35
|
+
}
|
|
36
|
+
borrow(user, asset, amount) {
|
|
37
|
+
const reserve = this.reserves.get(asset);
|
|
38
|
+
if (!reserve)
|
|
39
|
+
return `Error: Unknown asset ${asset}`;
|
|
40
|
+
if (reserve.totalSupply - reserve.totalBorrow < amount)
|
|
41
|
+
return `Error: Insufficient liquidity`;
|
|
42
|
+
reserve.totalBorrow += amount;
|
|
43
|
+
if (!this.userPositions.has(user))
|
|
44
|
+
this.userPositions.set(user, new Map());
|
|
45
|
+
const pos = this.userPositions.get(user);
|
|
46
|
+
const current = pos.get(asset) || { collateral: 0n, borrow: 0n };
|
|
47
|
+
current.borrow += amount;
|
|
48
|
+
pos.set(asset, current);
|
|
49
|
+
return `Borrowed ${amount} ${asset}. Total borrow: ${current.borrow}`;
|
|
50
|
+
}
|
|
51
|
+
repay(user, asset, amount) {
|
|
52
|
+
const reserve = this.reserves.get(asset);
|
|
53
|
+
if (!reserve)
|
|
54
|
+
return `Error: Unknown asset ${asset}`;
|
|
55
|
+
reserve.totalBorrow -= amount;
|
|
56
|
+
const pos = this.userPositions.get(user)?.get(asset);
|
|
57
|
+
if (!pos)
|
|
58
|
+
return `Error: No borrow position for ${asset}`;
|
|
59
|
+
pos.borrow -= amount;
|
|
60
|
+
return `Repaid ${amount} ${asset}. Remaining borrow: ${pos.borrow}`;
|
|
61
|
+
}
|
|
62
|
+
getUserPositions(user) {
|
|
63
|
+
const positions = this.userPositions.get(user);
|
|
64
|
+
if (!positions || positions.size === 0)
|
|
65
|
+
return `No positions found for ${user}`;
|
|
66
|
+
return Array.from(positions.entries())
|
|
67
|
+
.map(([asset, p]) => `${asset}: Collateral=${p.collateral} Borrow=${p.borrow}`)
|
|
68
|
+
.join("\n");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=mockBlendPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockBlendPool.js","sourceRoot":"","sources":["../src/mockBlendPool.ts"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C,MAAM,EAAE,CAAC;IACtE,CAAC;IAED,gBAAgB,CAAC,IAAY;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC;YAAE,OAAO,0BAA0B,IAAI,EAAE,CAAC;QAChF,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,gBAAgB,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC,MAAM,EAAE,CAAC;aAC9E,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cann4n/actions-blend",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Blend Protocol lending and borrowing actions for AgentKit Stellar",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@cann4n/core": "^0.1.0",
|
|
21
|
+
"zod": "^3.24.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.7.0",
|
|
25
|
+
"vitest": "^3.0.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/anomalyco/agentkit-stellar.git",
|
|
34
|
+
"directory": "packages/actions-blend"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"lint": "eslint src/",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"clean": "rm -rf dist"
|
|
42
|
+
}
|
|
43
|
+
}
|