@coinbase/agentkit 0.0.0-nightly-20250328174338
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/README.md +827 -0
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/actionDecorator.d.ts +69 -0
- package/dist/action-providers/actionDecorator.js +96 -0
- package/dist/action-providers/actionProvider.d.ts +48 -0
- package/dist/action-providers/actionProvider.js +62 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/allora/alloraActionProvider.d.ts +44 -0
- package/dist/action-providers/allora/alloraActionProvider.js +195 -0
- package/dist/action-providers/allora/alloraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/allora/alloraActionProvider.test.js +109 -0
- package/dist/action-providers/allora/index.d.ts +2 -0
- package/dist/action-providers/allora/index.js +18 -0
- package/dist/action-providers/allora/schemas.d.ts +28 -0
- package/dist/action-providers/allora/schemas.js +30 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
- package/dist/action-providers/basename/basenameActionProvider.js +109 -0
- package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
- package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
- package/dist/action-providers/basename/constants.d.ts +52 -0
- package/dist/action-providers/basename/constants.js +81 -0
- package/dist/action-providers/basename/index.d.ts +2 -0
- package/dist/action-providers/basename/index.js +18 -0
- package/dist/action-providers/basename/schemas.d.ts +14 -0
- package/dist/action-providers/basename/schemas.js +14 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.js +128 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +224 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +267 -0
- package/dist/action-providers/cdp/constants.d.ts +31 -0
- package/dist/action-providers/cdp/constants.js +34 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +19 -0
- package/dist/action-providers/cdp/schemas.d.ts +91 -0
- package/dist/action-providers/cdp/schemas.js +77 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/customActionProvider.d.ts +30 -0
- package/dist/action-providers/customActionProvider.js +66 -0
- package/dist/action-providers/defillama/constants.d.ts +8 -0
- package/dist/action-providers/defillama/constants.js +11 -0
- package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
- package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
- package/dist/action-providers/defillama/index.d.ts +1 -0
- package/dist/action-providers/defillama/index.js +17 -0
- package/dist/action-providers/defillama/schemas.d.ts +34 -0
- package/dist/action-providers/defillama/schemas.js +34 -0
- package/dist/action-providers/defillama/types.d.ts +73 -0
- package/dist/action-providers/defillama/types.js +2 -0
- package/dist/action-providers/defillama/utils.d.ts +10 -0
- package/dist/action-providers/defillama/utils.js +87 -0
- package/dist/action-providers/defillama/utils.test.d.ts +1 -0
- package/dist/action-providers/defillama/utils.test.js +124 -0
- package/dist/action-providers/erc20/constants.d.ts +137 -0
- package/dist/action-providers/erc20/constants.js +202 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +142 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +131 -0
- package/dist/action-providers/erc20/index.d.ts +1 -0
- package/dist/action-providers/erc20/index.js +17 -0
- package/dist/action-providers/erc20/schemas.d.ts +27 -0
- package/dist/action-providers/erc20/schemas.js +26 -0
- package/dist/action-providers/erc721/constants.d.ts +232 -0
- package/dist/action-providers/erc721/constants.js +298 -0
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
- package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
- package/dist/action-providers/erc721/index.d.ts +1 -0
- package/dist/action-providers/erc721/index.js +17 -0
- package/dist/action-providers/erc721/schemas.d.ts +46 -0
- package/dist/action-providers/erc721/schemas.js +44 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +151 -0
- package/dist/action-providers/farcaster/index.d.ts +2 -0
- package/dist/action-providers/farcaster/index.js +18 -0
- package/dist/action-providers/farcaster/schemas.d.ts +15 -0
- package/dist/action-providers/farcaster/schemas.js +20 -0
- package/dist/action-providers/index.d.ts +24 -0
- package/dist/action-providers/index.js +40 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/constants.d.ts +16 -0
- package/dist/action-providers/morpho/constants.js +27 -0
- package/dist/action-providers/morpho/index.d.ts +2 -0
- package/dist/action-providers/morpho/index.js +18 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.js +154 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.js +128 -0
- package/dist/action-providers/morpho/schemas.d.ts +36 -0
- package/dist/action-providers/morpho/schemas.js +47 -0
- package/dist/action-providers/opensea/index.d.ts +1 -0
- package/dist/action-providers/opensea/index.js +17 -0
- package/dist/action-providers/opensea/openseaActionProvider.d.ts +59 -0
- package/dist/action-providers/opensea/openseaActionProvider.js +146 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.js +201 -0
- package/dist/action-providers/opensea/schemas.d.ts +30 -0
- package/dist/action-providers/opensea/schemas.js +33 -0
- package/dist/action-providers/opensea/utils.d.ts +12 -0
- package/dist/action-providers/opensea/utils.js +47 -0
- package/dist/action-providers/pyth/index.d.ts +2 -0
- package/dist/action-providers/pyth/index.js +18 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
- package/dist/action-providers/pyth/pythActionProvider.js +121 -0
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/pyth/schemas.d.ts +21 -0
- package/dist/action-providers/pyth/schemas.js +20 -0
- package/dist/action-providers/spl/index.d.ts +1 -0
- package/dist/action-providers/spl/index.js +17 -0
- package/dist/action-providers/spl/schemas.d.ts +30 -0
- package/dist/action-providers/spl/schemas.js +26 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +45 -0
- package/dist/action-providers/spl/splActionProvider.js +173 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +300 -0
- package/dist/action-providers/twitter/index.d.ts +2 -0
- package/dist/action-providers/twitter/index.js +18 -0
- package/dist/action-providers/twitter/schemas.d.ts +38 -0
- package/dist/action-providers/twitter/schemas.js +44 -0
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
- package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
- package/dist/action-providers/wallet/index.d.ts +1 -0
- package/dist/action-providers/wallet/index.js +17 -0
- package/dist/action-providers/wallet/schemas.d.ts +19 -0
- package/dist/action-providers/wallet/schemas.js +19 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
- package/dist/action-providers/wallet/walletActionProvider.js +140 -0
- package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wallet/walletActionProvider.test.js +194 -0
- package/dist/action-providers/weth/constants.d.ts +19 -0
- package/dist/action-providers/weth/constants.js +29 -0
- package/dist/action-providers/weth/index.d.ts +1 -0
- package/dist/action-providers/weth/index.js +17 -0
- package/dist/action-providers/weth/schemas.d.ts +8 -0
- package/dist/action-providers/weth/schemas.js +10 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
- package/dist/action-providers/weth/wethActionProvider.js +89 -0
- package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
- package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
- package/dist/action-providers/wow/constants.d.ts +15 -0
- package/dist/action-providers/wow/constants.js +844 -0
- package/dist/action-providers/wow/index.d.ts +2 -0
- package/dist/action-providers/wow/index.js +18 -0
- package/dist/action-providers/wow/schemas.d.ts +43 -0
- package/dist/action-providers/wow/schemas.js +47 -0
- package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
- package/dist/action-providers/wow/uniswap/constants.js +100 -0
- package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
- package/dist/action-providers/wow/uniswap/utils.js +226 -0
- package/dist/action-providers/wow/utils.d.ts +27 -0
- package/dist/action-providers/wow/utils.js +63 -0
- package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
- package/dist/action-providers/wow/wowActionProvider.js +223 -0
- package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wow/wowActionProvider.test.js +291 -0
- package/dist/agentkit.d.ts +44 -0
- package/dist/agentkit.js +68 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +17 -0
- package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
- package/dist/analytics/sendAnalyticsEvent.js +52 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/network/index.d.ts +3 -0
- package/dist/network/index.js +19 -0
- package/dist/network/network.d.ts +20 -0
- package/dist/network/network.js +86 -0
- package/dist/network/svm.d.ts +15 -0
- package/dist/network/svm.js +38 -0
- package/dist/network/types.d.ts +17 -0
- package/dist/network/types.js +2 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +57 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +50 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +246 -0
- package/dist/wallet-providers/cdpWalletProvider.js +421 -0
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
- package/dist/wallet-providers/evmWalletProvider.js +14 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +10 -0
- package/dist/wallet-providers/index.js +26 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +35 -0
- package/dist/wallet-providers/privyWalletProvider.js +39 -0
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +143 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +280 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +218 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +103 -0
- package/dist/wallet-providers/viemWalletProvider.js +206 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.d.ts +48 -0
- package/dist/wallet-providers/walletProvider.js +41 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +83 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const opensea_js_1 = require("opensea-js");
|
|
4
|
+
const openseaActionProvider_1 = require("./openseaActionProvider");
|
|
5
|
+
jest.mock("opensea-js");
|
|
6
|
+
describe("OpenSea Action Provider", () => {
|
|
7
|
+
const MOCK_API_KEY = "test-api-key";
|
|
8
|
+
const MOCK_PRIVATE_KEY = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
9
|
+
const MOCK_CONTRACT = "0x1234567890123456789012345678901234567890";
|
|
10
|
+
const MOCK_TOKEN_ID = "1";
|
|
11
|
+
const MOCK_PRICE = 0.1;
|
|
12
|
+
const MOCK_EXPIRATION_DAYS = 90;
|
|
13
|
+
const MOCK_OPENSEA_BASE_URL = "https://testnets.opensea.io";
|
|
14
|
+
const MOCK_OPENSEA_CHAIN = "base_sepolia";
|
|
15
|
+
let actionProvider;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
// Mock OpenSeaSDK constructor
|
|
19
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
20
|
+
createListing: jest.fn(),
|
|
21
|
+
api: {
|
|
22
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
23
|
+
getNFTsByAccount: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
26
|
+
}));
|
|
27
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
28
|
+
apiKey: MOCK_API_KEY,
|
|
29
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
30
|
+
networkId: "base-sepolia",
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe("listNft", () => {
|
|
34
|
+
it("should successfully list an NFT", async () => {
|
|
35
|
+
const mockListing = {};
|
|
36
|
+
const mockCreateListing = jest.fn().mockResolvedValue(mockListing);
|
|
37
|
+
// Update the mock implementation with the mock function
|
|
38
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
39
|
+
createListing: mockCreateListing,
|
|
40
|
+
api: {
|
|
41
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
42
|
+
},
|
|
43
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
44
|
+
}));
|
|
45
|
+
// Re-create provider with new mock
|
|
46
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
47
|
+
apiKey: MOCK_API_KEY,
|
|
48
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
49
|
+
networkId: "base-sepolia",
|
|
50
|
+
});
|
|
51
|
+
const args = {
|
|
52
|
+
contractAddress: MOCK_CONTRACT,
|
|
53
|
+
tokenId: MOCK_TOKEN_ID,
|
|
54
|
+
price: MOCK_PRICE,
|
|
55
|
+
expirationDays: MOCK_EXPIRATION_DAYS,
|
|
56
|
+
};
|
|
57
|
+
const response = await actionProvider.listNft(args);
|
|
58
|
+
expect(mockCreateListing).toHaveBeenCalledWith(expect.objectContaining({
|
|
59
|
+
asset: {
|
|
60
|
+
tokenId: MOCK_TOKEN_ID,
|
|
61
|
+
tokenAddress: MOCK_CONTRACT,
|
|
62
|
+
},
|
|
63
|
+
startAmount: MOCK_PRICE,
|
|
64
|
+
quantity: 1,
|
|
65
|
+
}));
|
|
66
|
+
expect(response).toBe(`Successfully listed NFT ${MOCK_CONTRACT} token ${MOCK_TOKEN_ID} for ${MOCK_PRICE} ETH, expiring in ${MOCK_EXPIRATION_DAYS} days. Listing on OpenSea: ${MOCK_OPENSEA_BASE_URL}/assets/${MOCK_OPENSEA_CHAIN}/${MOCK_CONTRACT}/${MOCK_TOKEN_ID}.`);
|
|
67
|
+
});
|
|
68
|
+
it("should handle listing errors", async () => {
|
|
69
|
+
const error = new Error("Listing failed");
|
|
70
|
+
const mockCreateListing = jest.fn().mockRejectedValue(error);
|
|
71
|
+
// Update the mock implementation with the mock function
|
|
72
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
73
|
+
createListing: mockCreateListing,
|
|
74
|
+
api: {
|
|
75
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
76
|
+
},
|
|
77
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
78
|
+
}));
|
|
79
|
+
// Re-create provider with new mock
|
|
80
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
81
|
+
apiKey: MOCK_API_KEY,
|
|
82
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
83
|
+
networkId: "base-sepolia",
|
|
84
|
+
});
|
|
85
|
+
const args = {
|
|
86
|
+
contractAddress: MOCK_CONTRACT,
|
|
87
|
+
tokenId: MOCK_TOKEN_ID,
|
|
88
|
+
price: MOCK_PRICE,
|
|
89
|
+
expirationDays: MOCK_EXPIRATION_DAYS,
|
|
90
|
+
};
|
|
91
|
+
const response = await actionProvider.listNft(args);
|
|
92
|
+
expect(response).toContain(`Error listing NFT ${MOCK_CONTRACT} token ${MOCK_TOKEN_ID}`);
|
|
93
|
+
expect(response).toContain(error.message);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("getNftsByAccount", () => {
|
|
97
|
+
const MOCK_WALLET_ADDRESS = "0xabcdef1234567890abcdef1234567890abcdef12";
|
|
98
|
+
const MOCK_NFTS = [
|
|
99
|
+
{
|
|
100
|
+
identifier: "1",
|
|
101
|
+
contract: MOCK_CONTRACT,
|
|
102
|
+
name: "Test NFT 1",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
identifier: "2",
|
|
106
|
+
contract: MOCK_CONTRACT,
|
|
107
|
+
name: "Test NFT 2",
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
it("should successfully fetch NFTs for the specified account", async () => {
|
|
111
|
+
const mockGetNFTsByAccount = jest.fn().mockResolvedValue({ nfts: MOCK_NFTS });
|
|
112
|
+
// Update the mock implementation with the mock function
|
|
113
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
114
|
+
createListing: jest.fn(),
|
|
115
|
+
api: {
|
|
116
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
117
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
118
|
+
},
|
|
119
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
120
|
+
}));
|
|
121
|
+
// Re-create provider with new mock
|
|
122
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
123
|
+
apiKey: MOCK_API_KEY,
|
|
124
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
125
|
+
networkId: "base-sepolia",
|
|
126
|
+
});
|
|
127
|
+
const args = {
|
|
128
|
+
accountAddress: MOCK_WALLET_ADDRESS,
|
|
129
|
+
};
|
|
130
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
131
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalledWith(MOCK_WALLET_ADDRESS);
|
|
132
|
+
expect(response).toBe(JSON.stringify(MOCK_NFTS));
|
|
133
|
+
});
|
|
134
|
+
it("should use connected wallet address when no account is specified", async () => {
|
|
135
|
+
const mockGetNFTsByAccount = jest.fn().mockResolvedValue({ nfts: MOCK_NFTS });
|
|
136
|
+
// Update the mock implementation with the mock function
|
|
137
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
138
|
+
createListing: jest.fn(),
|
|
139
|
+
api: {
|
|
140
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
141
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
142
|
+
},
|
|
143
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
144
|
+
}));
|
|
145
|
+
// Re-create provider with new mock
|
|
146
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
147
|
+
apiKey: MOCK_API_KEY,
|
|
148
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
149
|
+
networkId: "base-sepolia",
|
|
150
|
+
});
|
|
151
|
+
const args = {}; // No accountAddress provided
|
|
152
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
153
|
+
// Should use the wallet address from the provider
|
|
154
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalled();
|
|
155
|
+
expect(response).toBe(JSON.stringify(MOCK_NFTS));
|
|
156
|
+
});
|
|
157
|
+
it("should handle errors when fetching NFTs", async () => {
|
|
158
|
+
const error = new Error("Failed to fetch NFTs");
|
|
159
|
+
const mockGetNFTsByAccount = jest.fn().mockRejectedValue(error);
|
|
160
|
+
// Update the mock implementation with the mock function
|
|
161
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
162
|
+
createListing: jest.fn(),
|
|
163
|
+
api: {
|
|
164
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
165
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
166
|
+
},
|
|
167
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
168
|
+
}));
|
|
169
|
+
// Re-create provider with new mock
|
|
170
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
171
|
+
apiKey: MOCK_API_KEY,
|
|
172
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
173
|
+
networkId: "base-sepolia",
|
|
174
|
+
});
|
|
175
|
+
const args = {
|
|
176
|
+
accountAddress: MOCK_WALLET_ADDRESS,
|
|
177
|
+
};
|
|
178
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
179
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalledWith(MOCK_WALLET_ADDRESS);
|
|
180
|
+
expect(response).toContain(`Error fetching NFTs for account ${MOCK_WALLET_ADDRESS}`);
|
|
181
|
+
expect(response).toContain(error.message);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe("supportsNetwork", () => {
|
|
185
|
+
it("should return true for supported networks", () => {
|
|
186
|
+
const baseSepoliaNetwork = {
|
|
187
|
+
protocolFamily: "evm",
|
|
188
|
+
networkId: "base-sepolia",
|
|
189
|
+
chainId: "84532",
|
|
190
|
+
};
|
|
191
|
+
expect(actionProvider.supportsNetwork(baseSepoliaNetwork)).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
it("should return false for unsupported networks", () => {
|
|
194
|
+
const fantomNetwork = {
|
|
195
|
+
protocolFamily: "bitcoin",
|
|
196
|
+
networkId: "any",
|
|
197
|
+
};
|
|
198
|
+
expect(actionProvider.supportsNetwork(fantomNetwork)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for listing an NFT on OpenSea.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ListNftSchema: z.ZodObject<{
|
|
6
|
+
contractAddress: z.ZodString;
|
|
7
|
+
tokenId: z.ZodString;
|
|
8
|
+
price: z.ZodNumber;
|
|
9
|
+
expirationDays: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
contractAddress: string;
|
|
12
|
+
price: number;
|
|
13
|
+
tokenId: string;
|
|
14
|
+
expirationDays: number;
|
|
15
|
+
}, {
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
price: number;
|
|
18
|
+
tokenId: string;
|
|
19
|
+
expirationDays?: number | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Input schema for getting NFTs from a specific wallet address.
|
|
23
|
+
*/
|
|
24
|
+
export declare const GetNftsByAccountSchema: z.ZodObject<{
|
|
25
|
+
accountAddress: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
accountAddress?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
accountAddress?: string | undefined;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetNftsByAccountSchema = exports.ListNftSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for listing an NFT on OpenSea.
|
|
7
|
+
*/
|
|
8
|
+
exports.ListNftSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
contractAddress: zod_1.z.string().nonempty().describe("The NFT contract address to list"),
|
|
11
|
+
tokenId: zod_1.z.string().nonempty().describe("The tokenID of the NFT to list"),
|
|
12
|
+
price: zod_1.z.number().positive().describe("The price in ETH to list the NFT for"),
|
|
13
|
+
expirationDays: zod_1.z
|
|
14
|
+
.number()
|
|
15
|
+
.positive()
|
|
16
|
+
.optional()
|
|
17
|
+
.default(90)
|
|
18
|
+
.describe("Number of days the listing should be active for (default: 90)"),
|
|
19
|
+
})
|
|
20
|
+
.strip()
|
|
21
|
+
.describe("Input schema for listing an NFT on OpenSea");
|
|
22
|
+
/**
|
|
23
|
+
* Input schema for getting NFTs from a specific wallet address.
|
|
24
|
+
*/
|
|
25
|
+
exports.GetNftsByAccountSchema = zod_1.z
|
|
26
|
+
.object({
|
|
27
|
+
accountAddress: zod_1.z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("The wallet address to fetch NFTs for (defaults to connected wallet if not provided)"),
|
|
31
|
+
})
|
|
32
|
+
.strip()
|
|
33
|
+
.describe("Input schema for fetching NFTs by account");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Chain } from "opensea-js";
|
|
2
|
+
/**
|
|
3
|
+
* Supported Opensea chains
|
|
4
|
+
*/
|
|
5
|
+
export declare const supportedChains: Record<string, Chain>;
|
|
6
|
+
/**
|
|
7
|
+
* Maps EVM chain IDs to Opensea chain
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The EVM chain ID to map
|
|
10
|
+
* @returns The corresponding OpenSea Chain enum value
|
|
11
|
+
*/
|
|
12
|
+
export declare const chainIdToOpenseaChain: (chainId: string) => Chain;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chainIdToOpenseaChain = exports.supportedChains = void 0;
|
|
4
|
+
const opensea_js_1 = require("opensea-js");
|
|
5
|
+
/**
|
|
6
|
+
* Supported Opensea chains
|
|
7
|
+
*/
|
|
8
|
+
exports.supportedChains = {
|
|
9
|
+
"1": opensea_js_1.Chain.Mainnet,
|
|
10
|
+
"137": opensea_js_1.Chain.Polygon,
|
|
11
|
+
"80002": opensea_js_1.Chain.Amoy,
|
|
12
|
+
"11155111": opensea_js_1.Chain.Sepolia,
|
|
13
|
+
"8217": opensea_js_1.Chain.Klaytn,
|
|
14
|
+
"1001": opensea_js_1.Chain.Baobab,
|
|
15
|
+
"43114": opensea_js_1.Chain.Avalanche,
|
|
16
|
+
"43113": opensea_js_1.Chain.Fuji,
|
|
17
|
+
"42161": opensea_js_1.Chain.Arbitrum,
|
|
18
|
+
"42170": opensea_js_1.Chain.ArbitrumNova,
|
|
19
|
+
"421614": opensea_js_1.Chain.ArbitrumSepolia,
|
|
20
|
+
"238": opensea_js_1.Chain.Blast,
|
|
21
|
+
"168587773": opensea_js_1.Chain.BlastSepolia,
|
|
22
|
+
"8453": opensea_js_1.Chain.Base,
|
|
23
|
+
"84532": opensea_js_1.Chain.BaseSepolia,
|
|
24
|
+
"10": opensea_js_1.Chain.Optimism,
|
|
25
|
+
"11155420": opensea_js_1.Chain.OptimismSepolia,
|
|
26
|
+
"7777777": opensea_js_1.Chain.Zora,
|
|
27
|
+
"999999999": opensea_js_1.Chain.ZoraSepolia,
|
|
28
|
+
"1329": opensea_js_1.Chain.Sei,
|
|
29
|
+
"1328": opensea_js_1.Chain.SeiTestnet,
|
|
30
|
+
"8333": opensea_js_1.Chain.B3,
|
|
31
|
+
"1993": opensea_js_1.Chain.B3Sepolia,
|
|
32
|
+
"80094": opensea_js_1.Chain.BeraChain,
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Maps EVM chain IDs to Opensea chain
|
|
36
|
+
*
|
|
37
|
+
* @param chainId - The EVM chain ID to map
|
|
38
|
+
* @returns The corresponding OpenSea Chain enum value
|
|
39
|
+
*/
|
|
40
|
+
const chainIdToOpenseaChain = (chainId) => {
|
|
41
|
+
const chain = exports.supportedChains[chainId];
|
|
42
|
+
if (!chain) {
|
|
43
|
+
throw new Error(`Unsupported chain ID on Opensea: ${chainId}`);
|
|
44
|
+
}
|
|
45
|
+
return chain;
|
|
46
|
+
};
|
|
47
|
+
exports.chainIdToOpenseaChain = chainIdToOpenseaChain;
|
|
@@ -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("./pythActionProvider"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { PythFetchPriceFeedIDSchema, PythFetchPriceSchema } from "./schemas";
|
|
4
|
+
/**
|
|
5
|
+
* PythActionProvider is an action provider for Pyth.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PythActionProvider extends ActionProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new PythActionProvider.
|
|
10
|
+
*/
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Fetch the price feed ID for a given token symbol from Pyth.
|
|
14
|
+
*
|
|
15
|
+
* @param args - The arguments for the action.
|
|
16
|
+
* @returns The price feed ID as a string.
|
|
17
|
+
*/
|
|
18
|
+
fetchPriceFeed(args: z.infer<typeof PythFetchPriceFeedIDSchema>): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the price from Pyth given a Pyth price feed ID.
|
|
21
|
+
*
|
|
22
|
+
* @param args - The arguments for the action.
|
|
23
|
+
* @returns The price as a string.
|
|
24
|
+
*/
|
|
25
|
+
fetchPrice(args: z.infer<typeof PythFetchPriceSchema>): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the Pyth action provider supports the given network.
|
|
28
|
+
*
|
|
29
|
+
* @returns True if the Pyth action provider supports the network, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
supportsNetwork: () => boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const pythActionProvider: () => PythActionProvider;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.pythActionProvider = exports.PythActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const actionProvider_1 = require("../actionProvider");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const schemas_1 = require("./schemas");
|
|
17
|
+
/**
|
|
18
|
+
* PythActionProvider is an action provider for Pyth.
|
|
19
|
+
*/
|
|
20
|
+
class PythActionProvider extends actionProvider_1.ActionProvider {
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a new PythActionProvider.
|
|
23
|
+
*/
|
|
24
|
+
constructor() {
|
|
25
|
+
super("pyth", []);
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the Pyth action provider supports the given network.
|
|
28
|
+
*
|
|
29
|
+
* @returns True if the Pyth action provider supports the network, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
this.supportsNetwork = () => true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Fetch the price feed ID for a given token symbol from Pyth.
|
|
35
|
+
*
|
|
36
|
+
* @param args - The arguments for the action.
|
|
37
|
+
* @returns The price feed ID as a string.
|
|
38
|
+
*/
|
|
39
|
+
async fetchPriceFeed(args) {
|
|
40
|
+
const url = `https://hermes.pyth.network/v2/price_feeds?query=${args.tokenSymbol}&asset_type=crypto`;
|
|
41
|
+
const response = await fetch(url);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
44
|
+
}
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
if (data.length === 0) {
|
|
47
|
+
throw new Error(`No price feed found for ${args.tokenSymbol}`);
|
|
48
|
+
}
|
|
49
|
+
const filteredData = data.filter(
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
(item) => item.attributes.base.toLowerCase() === args.tokenSymbol.toLowerCase());
|
|
52
|
+
if (filteredData.length === 0) {
|
|
53
|
+
throw new Error(`No price feed found for ${args.tokenSymbol}`);
|
|
54
|
+
}
|
|
55
|
+
return filteredData[0].id;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Fetches the price from Pyth given a Pyth price feed ID.
|
|
59
|
+
*
|
|
60
|
+
* @param args - The arguments for the action.
|
|
61
|
+
* @returns The price as a string.
|
|
62
|
+
*/
|
|
63
|
+
async fetchPrice(args) {
|
|
64
|
+
const url = `https://hermes.pyth.network/v2/updates/price/latest?ids[]=${args.priceFeedID}`;
|
|
65
|
+
const response = await fetch(url);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
68
|
+
}
|
|
69
|
+
const data = await response.json();
|
|
70
|
+
const parsedData = data.parsed;
|
|
71
|
+
if (parsedData.length === 0) {
|
|
72
|
+
throw new Error(`No price data found for ${args.priceFeedID}`);
|
|
73
|
+
}
|
|
74
|
+
const priceInfo = parsedData[0].price;
|
|
75
|
+
const price = BigInt(priceInfo.price);
|
|
76
|
+
const exponent = priceInfo.expo;
|
|
77
|
+
if (exponent < 0) {
|
|
78
|
+
const adjustedPrice = price * BigInt(100);
|
|
79
|
+
const divisor = BigInt(10) ** BigInt(-exponent);
|
|
80
|
+
const scaledPrice = adjustedPrice / BigInt(divisor);
|
|
81
|
+
const priceStr = scaledPrice.toString();
|
|
82
|
+
const formattedPrice = `${priceStr.slice(0, -2)}.${priceStr.slice(-2)}`;
|
|
83
|
+
return formattedPrice.startsWith(".") ? `0${formattedPrice}` : formattedPrice;
|
|
84
|
+
}
|
|
85
|
+
const scaledPrice = price / BigInt(10) ** BigInt(exponent);
|
|
86
|
+
return scaledPrice.toString();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.PythActionProvider = PythActionProvider;
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, actionDecorator_1.CreateAction)({
|
|
92
|
+
name: "fetch_price_feed",
|
|
93
|
+
description: "Fetch the price feed ID for a given token symbol from Pyth.",
|
|
94
|
+
schema: schemas_1.PythFetchPriceFeedIDSchema,
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", [void 0]),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], PythActionProvider.prototype, "fetchPriceFeed", null);
|
|
100
|
+
__decorate([
|
|
101
|
+
(0, actionDecorator_1.CreateAction)({
|
|
102
|
+
name: "fetch_price",
|
|
103
|
+
description: `Fetch the price of a given price feed from Pyth.
|
|
104
|
+
|
|
105
|
+
Inputs:
|
|
106
|
+
- Pyth price feed ID
|
|
107
|
+
|
|
108
|
+
Important notes:
|
|
109
|
+
- Do not assume that a random ID is a Pyth price feed ID. If you are confused, ask a clarifying question.
|
|
110
|
+
- This action only fetches price inputs from Pyth price feeds. No other source.
|
|
111
|
+
- If you are asked to fetch the price from Pyth for a ticker symbol such as BTC, you must first use the pyth_fetch_price_feed_id
|
|
112
|
+
action to retrieve the price feed ID before invoking the pyth_Fetch_price action
|
|
113
|
+
`,
|
|
114
|
+
schema: schemas_1.PythFetchPriceSchema,
|
|
115
|
+
}),
|
|
116
|
+
__metadata("design:type", Function),
|
|
117
|
+
__metadata("design:paramtypes", [void 0]),
|
|
118
|
+
__metadata("design:returntype", Promise)
|
|
119
|
+
], PythActionProvider.prototype, "fetchPrice", null);
|
|
120
|
+
const pythActionProvider = () => new PythActionProvider();
|
|
121
|
+
exports.pythActionProvider = pythActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pythActionProvider_1 = require("./pythActionProvider");
|
|
4
|
+
describe("PythActionProvider", () => {
|
|
5
|
+
const fetchMock = jest.fn();
|
|
6
|
+
global.fetch = fetchMock;
|
|
7
|
+
const provider = (0, pythActionProvider_1.pythActionProvider)();
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
jest.resetAllMocks().restoreAllMocks();
|
|
10
|
+
});
|
|
11
|
+
describe("fetchPriceFeed", () => {
|
|
12
|
+
it("should return the first price feed ID that matches the input token symbol", async () => {
|
|
13
|
+
fetchMock.mockResolvedValueOnce({
|
|
14
|
+
ok: true,
|
|
15
|
+
json: async () => [{ id: "some-price-feed-id", attributes: { base: "BTC" } }],
|
|
16
|
+
});
|
|
17
|
+
const priceFeedId = await provider.fetchPriceFeed({ tokenSymbol: "BTC" });
|
|
18
|
+
expect(priceFeedId).toEqual("some-price-feed-id");
|
|
19
|
+
});
|
|
20
|
+
it("should throw an error if no price feed is found", async () => {
|
|
21
|
+
fetchMock.mockResolvedValueOnce({
|
|
22
|
+
ok: true,
|
|
23
|
+
json: async () => [{ id: "some-price-feed-id", attributes: { base: "BTC" } }],
|
|
24
|
+
});
|
|
25
|
+
await expect(provider.fetchPriceFeed({ tokenSymbol: "ETH" })).rejects.toThrow("No price feed found for ETH");
|
|
26
|
+
});
|
|
27
|
+
it("should throw an error if the response is not ok", async () => {
|
|
28
|
+
fetchMock.mockResolvedValueOnce({
|
|
29
|
+
ok: false,
|
|
30
|
+
status: 404,
|
|
31
|
+
});
|
|
32
|
+
await expect(provider.fetchPriceFeed({ tokenSymbol: "BTC" })).rejects.toThrow("HTTP error! status: 404");
|
|
33
|
+
});
|
|
34
|
+
it("should throw an error if response is ok but no data is returned", async () => {
|
|
35
|
+
fetchMock.mockResolvedValueOnce({
|
|
36
|
+
ok: true,
|
|
37
|
+
json: async () => [],
|
|
38
|
+
});
|
|
39
|
+
const provider = (0, pythActionProvider_1.pythActionProvider)();
|
|
40
|
+
await expect(provider.fetchPriceFeed({ tokenSymbol: "BTC" })).rejects.toThrow("No price feed found for BTC");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe("fetchPrice", () => {
|
|
44
|
+
it("should return the price for a given price feed ID", async () => {
|
|
45
|
+
fetchMock.mockResolvedValueOnce({
|
|
46
|
+
ok: true,
|
|
47
|
+
json: async () => ({
|
|
48
|
+
parsed: [
|
|
49
|
+
{
|
|
50
|
+
price: {
|
|
51
|
+
price: 100,
|
|
52
|
+
expo: 2,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
const price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
59
|
+
expect(price).toEqual("1");
|
|
60
|
+
});
|
|
61
|
+
it("should return the price for a given price feed ID with a negative exponent", async () => {
|
|
62
|
+
fetchMock.mockResolvedValueOnce({
|
|
63
|
+
ok: true,
|
|
64
|
+
json: async () => ({
|
|
65
|
+
parsed: [
|
|
66
|
+
{
|
|
67
|
+
price: {
|
|
68
|
+
price: 100,
|
|
69
|
+
expo: -2,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
const provider = (0, pythActionProvider_1.pythActionProvider)();
|
|
76
|
+
const price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
77
|
+
expect(price).toEqual("1.00");
|
|
78
|
+
});
|
|
79
|
+
it("should handle scaled price starting with a decimal", async () => {
|
|
80
|
+
fetchMock.mockResolvedValueOnce({
|
|
81
|
+
ok: true,
|
|
82
|
+
json: async () => ({
|
|
83
|
+
parsed: [
|
|
84
|
+
{
|
|
85
|
+
price: {
|
|
86
|
+
price: 25,
|
|
87
|
+
expo: -2,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
const price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
94
|
+
expect(price).toEqual("0.25");
|
|
95
|
+
});
|
|
96
|
+
it("should throw an error if there is no price data", async () => {
|
|
97
|
+
fetchMock.mockResolvedValueOnce({
|
|
98
|
+
ok: true,
|
|
99
|
+
json: async () => ({
|
|
100
|
+
parsed: [],
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
await expect(provider.fetchPrice({ priceFeedID: "some-price-feed-id" })).rejects.toThrow("No price data found for some-price-feed-id");
|
|
104
|
+
});
|
|
105
|
+
it("should throw an error if response is not ok", async () => {
|
|
106
|
+
fetchMock.mockResolvedValueOnce({
|
|
107
|
+
ok: false,
|
|
108
|
+
status: 404,
|
|
109
|
+
});
|
|
110
|
+
await expect(provider.fetchPrice({ priceFeedID: "some-price-feed-id" })).rejects.toThrow("HTTP error! status: 404");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for Pyth fetch price feed ID action.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PythFetchPriceFeedIDSchema: z.ZodObject<{
|
|
6
|
+
tokenSymbol: z.ZodString;
|
|
7
|
+
}, "strict", z.ZodTypeAny, {
|
|
8
|
+
tokenSymbol: string;
|
|
9
|
+
}, {
|
|
10
|
+
tokenSymbol: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Input schema for Pyth fetch price action.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PythFetchPriceSchema: z.ZodObject<{
|
|
16
|
+
priceFeedID: z.ZodString;
|
|
17
|
+
}, "strict", z.ZodTypeAny, {
|
|
18
|
+
priceFeedID: string;
|
|
19
|
+
}, {
|
|
20
|
+
priceFeedID: string;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PythFetchPriceSchema = exports.PythFetchPriceFeedIDSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for Pyth fetch price feed ID action.
|
|
7
|
+
*/
|
|
8
|
+
exports.PythFetchPriceFeedIDSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
tokenSymbol: zod_1.z.string().describe("The token symbol to fetch the price feed ID for"),
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
13
|
+
/**
|
|
14
|
+
* Input schema for Pyth fetch price action.
|
|
15
|
+
*/
|
|
16
|
+
exports.PythFetchPriceSchema = zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
priceFeedID: zod_1.z.string().describe("The price feed ID to fetch the price for"),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./splActionProvider";
|