@xmtp/content-type-wallet-send-calls 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 XMTP (xmtp.org)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Wallet Send Calls content type
2
+
3
+ ## Install the package
4
+
5
+ ```bash
6
+ # npm
7
+ npm i @xmtp/content-type-wallet-send-calls
8
+
9
+ # yarn
10
+ yarn add @xmtp/content-type-wallet-send-calls
11
+
12
+ # pnpm
13
+ pnpm i @xmtp/content-type-wallet-send-calls
14
+ ```
15
+
16
+ ## Create a transaction request
17
+
18
+ With XMTP, a transaction request is represented using `wallet_sendCalls` RPC specification from [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) with additional metadata for display:
19
+
20
+ ```tsx
21
+ const walletSendCalls: WalletSendCallsParams = {
22
+ version: "1.0",
23
+ from: "0x123...abc",
24
+ chainId: "0x2105",
25
+ calls: [
26
+ {
27
+ to: "0x456...def",
28
+ value: "0x5AF3107A4000",
29
+ metadata: {
30
+ description: "Send 0.0001 ETH on base to 0x456...def",
31
+ transactionType: "transfer",
32
+ currency: "ETH",
33
+ amount: 100000000000000,
34
+ decimals: 18,
35
+ toAddress: "0x456...def",
36
+ },
37
+ },
38
+ {
39
+ to: "0x789...cba",
40
+ data: "0xdead...beef",
41
+ metadata: {
42
+ description: "Lend 10 USDC on base with Morpho @ 8.5% APY",
43
+ transactionType: "lend",
44
+ currency: "USDC",
45
+ amount: 10000000,
46
+ decimals: 6,
47
+ platform: "morpho",
48
+ apy: "8.5",
49
+ },
50
+ },
51
+ ],
52
+ };
53
+ ```
54
+
55
+ ## Send a transaction request
56
+
57
+ Once you have a transaction reference, you can send it as part of your conversation:
58
+
59
+ ```tsx
60
+ await conversation.messages.send(walletSendCalls, {
61
+ contentType: ContentTypeWalletSendCalls,
62
+ });
63
+ ```
64
+
65
+ ## Receive a transaction request
66
+
67
+ To receive and process a transaction request:
68
+
69
+ ```tsx
70
+ // Assume `loadLastMessage` is a thing you have
71
+ const message: DecodedMessage = await loadLastMessage();
72
+
73
+ if (!message.contentType.sameAs(ContentTypeWalletSendCalls)) {
74
+ // Handle non-transaction request message
75
+ return;
76
+ }
77
+
78
+ const walletSendCalls: WalletSendCallsParams = message.content;
79
+ // Process the transaction request here
80
+ ```
81
+
82
+ ## Developing
83
+
84
+ Run `yarn dev` to build the content type and watch for changes, which will trigger a rebuild.
85
+
86
+ ## Testing
87
+
88
+ Before running unit tests, start the required Docker container at the root of this repository. For more info, see [Running tests](../../README.md#running-tests).
89
+
90
+ ## Useful commands
91
+
92
+ - `yarn build`: Builds the content type
93
+ - `yarn clean`: Removes `node_modules`, `dist`, and `.turbo` folders
94
+ - `yarn dev`: Builds the content type and watches for changes, which will trigger a rebuild
95
+ - `yarn format`: Runs Prettier format and write changes
96
+ - `yarn format:check`: Runs Prettier format check
97
+ - `yarn lint`: Runs ESLint
98
+ - `yarn test:setup`: Starts a necessary Docker container for testing
99
+ - `yarn test:teardown`: Stops Docker container for testing
100
+ - `yarn test`: Runs all unit tests
101
+ - `yarn typecheck`: Runs `tsc`
@@ -0,0 +1,2 @@
1
+ import{ContentTypeId as e}from"@xmtp/content-type-primitives";const t=new e({authorityId:"xmtp.org",typeId:"walletSendCalls",versionMajor:1,versionMinor:0});class n{get contentType(){return t}encode(e){return{type:t,parameters:{},content:(new TextEncoder).encode(JSON.stringify(e))}}decode(e){const t=e.content;return JSON.parse((new TextDecoder).decode(t))}fallback(e){return`[Transaction request generated]: ${JSON.stringify(e)}`}shouldPush(){return!0}}export{t as ContentTypeWalletSendCalls,n as WalletSendCallsCodec};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/WalletSendCalls.ts"],"sourcesContent":[null],"names":["ContentTypeWalletSendCalls","ContentTypeId","authorityId","typeId","versionMajor","versionMinor","WalletSendCallsCodec","contentType","encode","content","type","parameters","TextEncoder","JSON","stringify","decode","encodedContent","uint8Array","parse","TextDecoder","fallback","shouldPush"],"mappings":"8DAOa,MAAAA,EAA6B,IAAIC,EAAc,CAC1DC,YAAa,WACbC,OAAQ,kBACRC,aAAc,EACdC,aAAc,UAoBHC,EAGX,eAAIC,GACF,OAAOP,EAGT,MAAAQ,CAAOC,GAML,MALgB,CACdC,KAAMV,EACNW,WAAY,CAAE,EACdF,SAAS,IAAIG,aAAcJ,OAAOK,KAAKC,UAAUL,KAKrD,MAAAM,CAAOC,GACL,MAAMC,EAAaD,EAAeP,QAIlC,OAHwBI,KAAKK,OAC3B,IAAIC,aAAcJ,OAAOE,IAK7B,QAAAG,CAASX,GACP,MAAO,oCAAoCI,KAAKC,UAAUL,KAG5D,UAAAY,GACE,OAAO"}
@@ -0,0 +1,28 @@
1
+ import { ContentCodec, ContentTypeId, EncodedContent } from '@xmtp/content-type-primitives';
2
+
3
+ declare const ContentTypeWalletSendCalls: ContentTypeId;
4
+ type WalletSendCallsParams = {
5
+ version: string;
6
+ chainId: `0x${string}`;
7
+ from: `0x${string}`;
8
+ calls: {
9
+ to?: `0x${string}` | undefined;
10
+ data?: `0x${string}` | undefined;
11
+ value?: `0x${string}` | undefined;
12
+ gas?: `0x${string}` | undefined;
13
+ metadata?: {
14
+ description: string;
15
+ transactionType: string;
16
+ } & Record<string, any>;
17
+ }[];
18
+ capabilities?: Record<string, any> | undefined;
19
+ };
20
+ declare class WalletSendCallsCodec implements ContentCodec<WalletSendCallsParams> {
21
+ get contentType(): ContentTypeId;
22
+ encode(content: WalletSendCallsParams): EncodedContent;
23
+ decode(encodedContent: EncodedContent): WalletSendCallsParams;
24
+ fallback(content: WalletSendCallsParams): string | undefined;
25
+ shouldPush(): boolean;
26
+ }
27
+
28
+ export { ContentTypeWalletSendCalls, WalletSendCallsCodec, type WalletSendCallsParams };
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import { ContentTypeId } from '@xmtp/content-type-primitives';
2
+
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ const ContentTypeWalletSendCalls = new ContentTypeId({
5
+ authorityId: "xmtp.org",
6
+ typeId: "walletSendCalls",
7
+ versionMajor: 1,
8
+ versionMinor: 0,
9
+ });
10
+ class WalletSendCallsCodec {
11
+ get contentType() {
12
+ return ContentTypeWalletSendCalls;
13
+ }
14
+ encode(content) {
15
+ const encoded = {
16
+ type: ContentTypeWalletSendCalls,
17
+ parameters: {},
18
+ content: new TextEncoder().encode(JSON.stringify(content)),
19
+ };
20
+ return encoded;
21
+ }
22
+ decode(encodedContent) {
23
+ const uint8Array = encodedContent.content;
24
+ const contentReceived = JSON.parse(new TextDecoder().decode(uint8Array));
25
+ return contentReceived;
26
+ }
27
+ fallback(content) {
28
+ return `[Transaction request generated]: ${JSON.stringify(content)}`;
29
+ }
30
+ shouldPush() {
31
+ return true;
32
+ }
33
+ }
34
+
35
+ export { ContentTypeWalletSendCalls, WalletSendCallsCodec };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/WalletSendCalls.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AAOa,MAAA,0BAA0B,GAAG,IAAI,aAAa,CAAC;AAC1D,IAAA,WAAW,EAAE,UAAU;AACvB,IAAA,MAAM,EAAE,iBAAiB;AACzB,IAAA,YAAY,EAAE,CAAC;AACf,IAAA,YAAY,EAAE,CAAC;AAChB,CAAA;MAmBY,oBAAoB,CAAA;AAG/B,IAAA,IAAI,WAAW,GAAA;AACb,QAAA,OAAO,0BAA0B;;AAGnC,IAAA,MAAM,CAAC,OAA8B,EAAA;AACnC,QAAA,MAAM,OAAO,GAAG;AACd,YAAA,IAAI,EAAE,0BAA0B;AAChC,YAAA,UAAU,EAAE,EAAE;AACd,YAAA,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;SAC3D;AACD,QAAA,OAAO,OAAO;;AAGhB,IAAA,MAAM,CAAC,cAA8B,EAAA;AACnC,QAAA,MAAM,UAAU,GAAG,cAAc,CAAC,OAAO;AACzC,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAChC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CACZ;AAC1B,QAAA,OAAO,eAAe;;AAGxB,IAAA,QAAQ,CAAC,OAA8B,EAAA;QACrC,OAAO,CAAA,iCAAA,EAAoC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;;IAGtE,UAAU,GAAA;AACR,QAAA,OAAO,IAAI;;AAEd;;;;"}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@xmtp/content-type-wallet-send-calls",
3
+ "version": "1.0.0",
4
+ "description": "An XMTP content type to support sending transactions to wallet for execution",
5
+ "keywords": [
6
+ "xmtp",
7
+ "messaging",
8
+ "web3",
9
+ "js",
10
+ "ts",
11
+ "javascript",
12
+ "typescript",
13
+ "content-types"
14
+ ],
15
+ "homepage": "https://github.com/xmtp/xmtp-js",
16
+ "bugs": {
17
+ "url": "https://github.com/xmtp/xmtp-js/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+ssh://git@github.com/xmtp/xmtp-js.git",
22
+ "directory": "content-types/content-type-wallet-send-calls"
23
+ },
24
+ "license": "MIT",
25
+ "author": "XMTP Labs <eng@xmtp.com>",
26
+ "sideEffects": false,
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "browser": "./dist/browser/index.js",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "main": "dist/index.js",
37
+ "browser": "dist/browser/index.js",
38
+ "types": "dist/index.d.ts",
39
+ "files": [
40
+ "dist",
41
+ "src",
42
+ "!src/**/*.test.*"
43
+ ],
44
+ "scripts": {
45
+ "build": "yarn clean:dist && yarn rollup -c",
46
+ "clean": "yarn clean:dist && yarn clean:dbs && rimraf .turbo node_modules",
47
+ "clean:dbs": "rimraf *.db3* ||:",
48
+ "clean:dist": "rimraf dist",
49
+ "dev": "yarn clean:dist && yarn rollup -c --watch",
50
+ "test": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment node",
51
+ "typecheck": "tsc"
52
+ },
53
+ "browserslist": {
54
+ "production": [
55
+ ">0.2%",
56
+ "not dead",
57
+ "not op_mini all"
58
+ ],
59
+ "development": [
60
+ "last 3 chrome versions",
61
+ "last 3 firefox versions",
62
+ "last 3 safari versions"
63
+ ]
64
+ },
65
+ "dependencies": {
66
+ "@xmtp/content-type-primitives": "^2.0.1"
67
+ },
68
+ "devDependencies": {
69
+ "@rollup/plugin-terser": "^0.4.4",
70
+ "@rollup/plugin-typescript": "^12.1.2",
71
+ "@types/node": "^22.13.10",
72
+ "@xmtp/node-sdk": "workspace:^",
73
+ "rimraf": "^6.0.1",
74
+ "rollup": "^4.36.0",
75
+ "rollup-plugin-dts": "^6.1.1",
76
+ "rollup-plugin-filesize": "^10.0.0",
77
+ "typescript": "^5.8.2",
78
+ "vite": "^6.2.2",
79
+ "vitest": "^3.0.9"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public",
83
+ "provenance": true,
84
+ "registry": "https://registry.npmjs.org/"
85
+ }
86
+ }
@@ -0,0 +1,63 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import {
3
+ ContentTypeId,
4
+ type ContentCodec,
5
+ type EncodedContent,
6
+ } from "@xmtp/content-type-primitives";
7
+
8
+ export const ContentTypeWalletSendCalls = new ContentTypeId({
9
+ authorityId: "xmtp.org",
10
+ typeId: "walletSendCalls",
11
+ versionMajor: 1,
12
+ versionMinor: 0,
13
+ });
14
+
15
+ export type WalletSendCallsParams = {
16
+ version: string;
17
+ chainId: `0x${string}`; // Hex chain id
18
+ from: `0x${string}`;
19
+ calls: {
20
+ to?: `0x${string}` | undefined;
21
+ data?: `0x${string}` | undefined;
22
+ value?: `0x${string}` | undefined; // Hex value
23
+ gas?: `0x${string}` | undefined;
24
+ metadata?: {
25
+ description: string;
26
+ transactionType: string;
27
+ } & Record<string, any>;
28
+ }[];
29
+ capabilities?: Record<string, any> | undefined;
30
+ };
31
+
32
+ export class WalletSendCallsCodec
33
+ implements ContentCodec<WalletSendCallsParams>
34
+ {
35
+ get contentType(): ContentTypeId {
36
+ return ContentTypeWalletSendCalls;
37
+ }
38
+
39
+ encode(content: WalletSendCallsParams): EncodedContent {
40
+ const encoded = {
41
+ type: ContentTypeWalletSendCalls,
42
+ parameters: {},
43
+ content: new TextEncoder().encode(JSON.stringify(content)),
44
+ };
45
+ return encoded;
46
+ }
47
+
48
+ decode(encodedContent: EncodedContent): WalletSendCallsParams {
49
+ const uint8Array = encodedContent.content;
50
+ const contentReceived = JSON.parse(
51
+ new TextDecoder().decode(uint8Array),
52
+ ) as WalletSendCallsParams;
53
+ return contentReceived;
54
+ }
55
+
56
+ fallback(content: WalletSendCallsParams): string | undefined {
57
+ return `[Transaction request generated]: ${JSON.stringify(content)}`;
58
+ }
59
+
60
+ shouldPush() {
61
+ return true;
62
+ }
63
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export {
2
+ WalletSendCallsCodec,
3
+ ContentTypeWalletSendCalls,
4
+ } from "./WalletSendCalls";
5
+ export type { WalletSendCallsParams } from "./WalletSendCalls";