@pendle/sdk-boros 0.0.7 → 0.0.8

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.
@@ -0,0 +1,2 @@
1
+ export declare let RPC_URL: string;
2
+ export declare function registerRpc(url: string): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RPC_URL = void 0;
4
+ exports.registerRpc = registerRpc;
5
+ exports.RPC_URL = 'https://base.llamarpc.com';
6
+ function registerRpc(url) {
7
+ exports.RPC_URL = url;
8
+ }
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAEA,kCAEC;AAJU,QAAA,OAAO,GAAG,2BAA2B,CAAC;AAEjD,SAAgB,WAAW,CAAC,GAAW;IACrC,eAAO,GAAG,GAAG,CAAC;AAChB,CAAC"}
@@ -1,5 +1,2 @@
1
1
  export declare const ROUTER_ADDRESS: "0xb18F37F4B37b6B4F56E15f2e9F3Fe78cf5c6FE9E";
2
2
  export declare const CHAIN_ID = 8453;
3
- export declare const AGENT_PRIVATE_KEY: "0xf7ab9af3ae8c4de18185e633e271622fa753e3d604b7c6454aefab7b0ec8d56a";
4
- export declare const AGENT_PUBLIC_ADDRESS: "0xc11305458070b1cf122C9fc64C33f6c8f85e9639";
5
- export declare const RPC_URL = "https://base.llamarpc.com";
package/dist/constants.js CHANGED
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RPC_URL = exports.AGENT_PUBLIC_ADDRESS = exports.AGENT_PRIVATE_KEY = exports.CHAIN_ID = exports.ROUTER_ADDRESS = void 0;
3
+ exports.CHAIN_ID = exports.ROUTER_ADDRESS = void 0;
4
4
  exports.ROUTER_ADDRESS = '0xb18F37F4B37b6B4F56E15f2e9F3Fe78cf5c6FE9E';
5
5
  exports.CHAIN_ID = 8453;
6
- exports.AGENT_PRIVATE_KEY = '0xf7ab9af3ae8c4de18185e633e271622fa753e3d604b7c6454aefab7b0ec8d56a';
7
- exports.AGENT_PUBLIC_ADDRESS = '0xc11305458070b1cf122C9fc64C33f6c8f85e9639';
8
- exports.RPC_URL = 'https://base.llamarpc.com';
9
6
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AACa,QAAA,cAAc,GAAG,4CAAqD,CAAC;AACvE,QAAA,QAAQ,GAAG,IAAI,CAAC;AAEhB,QAAA,iBAAiB,GAAG,oEAA6E,CAAC;AAClG,QAAA,oBAAoB,GAAG,4CAAqD,CAAC;AAC7E,QAAA,OAAO,GAAG,2BAA2B,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AACa,QAAA,cAAc,GAAG,4CAAqD,CAAC;AACvE,QAAA,QAAQ,GAAG,IAAI,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Address, Hex, WalletClient } from 'viem';
2
+ export declare function setInternalAgent(agent: Agent): void;
3
+ export declare function getInternalAgent(): Agent;
4
+ export declare class Agent {
5
+ private readonly privateKey;
6
+ walletClient: WalletClient;
7
+ private constructor();
8
+ private createApproveAgentStruct;
9
+ private getApproveAgentData;
10
+ static createFromPrivateKey(privateKey: Hex): Agent;
11
+ static create(userWalletClient: WalletClient): Promise<{
12
+ agent: Agent;
13
+ privateKey: Hex;
14
+ }>;
15
+ approveAgent(userWalletClient: WalletClient, expiry_s: number): Promise<void>;
16
+ getAddress(): Promise<Address>;
17
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Agent = void 0;
4
+ exports.setInternalAgent = setInternalAgent;
5
+ exports.getInternalAgent = getInternalAgent;
6
+ const viem_1 = require("viem");
7
+ const chains_1 = require("viem/chains");
8
+ const utils_1 = require("../../utils");
9
+ const viemAbis_1 = require("../../contracts/viemAbis");
10
+ const accounts_1 = require("viem/accounts");
11
+ const common_1 = require("../../utils/signing/common");
12
+ const common_2 = require("../../common");
13
+ let internalAgent;
14
+ function setInternalAgent(agent) {
15
+ internalAgent = agent;
16
+ }
17
+ function getInternalAgent() {
18
+ if (!internalAgent) {
19
+ throw new Error('Internal agent is not set');
20
+ }
21
+ return internalAgent;
22
+ }
23
+ class Agent {
24
+ privateKey;
25
+ walletClient;
26
+ constructor(privateKey) {
27
+ this.privateKey = privateKey;
28
+ const account = (0, accounts_1.privateKeyToAccount)(this.privateKey);
29
+ this.walletClient = (0, viem_1.createWalletClient)({ account, transport: (0, viem_1.http)(common_2.RPC_URL), chain: chains_1.base });
30
+ }
31
+ async createApproveAgentStruct(userAddress, expiry_s) {
32
+ const agentAddress = await this.getAddress();
33
+ const nonce = BigInt(Date.now());
34
+ return {
35
+ account: utils_1.AccountLib.pack(userAddress, 0),
36
+ agent: agentAddress,
37
+ expiry: BigInt(expiry_s),
38
+ nonce,
39
+ };
40
+ }
41
+ getApproveAgentData(approveAgentStruct, signature) {
42
+ const data = (0, viem_1.encodeFunctionData)({
43
+ abi: viemAbis_1.iAuthModuleAbi,
44
+ functionName: 'approveAgent',
45
+ args: [approveAgentStruct, signature, { version: 0, data: '0x' }],
46
+ });
47
+ return data;
48
+ }
49
+ static createFromPrivateKey(privateKey) {
50
+ return new Agent(privateKey);
51
+ }
52
+ static async create(userWalletClient) {
53
+ const message = (0, common_1.getWelcomeMessage)();
54
+ const [userAddress] = await userWalletClient.getAddresses();
55
+ const signature = await userWalletClient.signMessage({ account: userWalletClient.account ?? userAddress, message });
56
+ const privateKey = (0, viem_1.toHex)(BigInt(signature) & BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'));
57
+ const agent = new Agent(privateKey);
58
+ return { agent, privateKey };
59
+ }
60
+ async approveAgent(userWalletClient, expiry_s) {
61
+ const [userAddress] = await userWalletClient.getAddresses();
62
+ const approveAgentStruct = await this.createApproveAgentStruct(userAddress, expiry_s);
63
+ const approveSignature = await (0, utils_1.signApproveAgentMessage)(userWalletClient, approveAgentStruct);
64
+ const data = this.getApproveAgentData(approveAgentStruct, approveSignature);
65
+ await (0, utils_1.sendTx)(userWalletClient, (0, utils_1.getRouterDirectCallData)([data]));
66
+ }
67
+ async getAddress() {
68
+ const [agentAddress] = await this.walletClient.getAddresses();
69
+ return agentAddress;
70
+ }
71
+ }
72
+ exports.Agent = Agent;
73
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../src/entities/agent/agent.ts"],"names":[],"mappings":";;;AAUA,4CAEC;AAED,4CAKC;AAnBD,+BAAuG;AACvG,wCAAmC;AACnC,uCAAmG;AAEnG,uDAA0D;AAC1D,4CAAoD;AACpD,uDAA+D;AAC/D,yCAAuC;AAEvC,IAAI,aAAgC,CAAC;AACrC,SAAgB,gBAAgB,CAAC,KAAY;IAC3C,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC;AAED,SAAgB,gBAAgB;IAC9B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AACD,MAAa,KAAK;IAGqB;IAFrC,YAAY,CAAe;IAE3B,YAAqC,UAAe;QAAf,eAAU,GAAV,UAAU,CAAK;QAClD,MAAM,OAAO,GAAG,IAAA,8BAAmB,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,GAAG,IAAA,yBAAkB,EAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAA,WAAI,EAAC,gBAAO,CAAC,EAAE,KAAK,EAAE,aAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;IAEO,KAAK,CAAC,wBAAwB,CAAC,WAAoB,EAAE,QA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,UAAU,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,gBAA8B,EAAE,QAAgB;QACjE,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,gBAAgB,CAAC,YAAY,EAAE,CAAC;QAC5D,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACtF,MAAM,gBAAgB,GAAG,MAAM,IAAA,+BAAuB,EAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;QAC5E,MAAM,IAAA,cAAM,EAAC,gBAAgB,EAAE,IAAA,+BAAuB,EAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;QAC9D,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAzDD,sBAyDC"}
@@ -0,0 +1 @@
1
+ export * from './agent';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./agent"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entities/agent/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
@@ -0,0 +1 @@
1
+ export * from './agent';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./agent"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}