diff --git a/packages/safe-apps-provider/CHANGELOG.md b/packages/safe-apps-provider/CHANGELOG.md index fe4fb36b..539acd41 100644 --- a/packages/safe-apps-provider/CHANGELOG.md +++ b/packages/safe-apps-provider/CHANGELOG.md @@ -1,5 +1,11 @@ # @safe-global/safe-apps-provider +## 0.18.4 + +### Patch Changes + +- 21ffde5: Add EIP-5792 support + ## 0.18.3 ### Patch Changes diff --git a/packages/safe-apps-provider/dist/provider.js b/packages/safe-apps-provider/dist/provider.js index 1b17d96c..198eacfd 100644 --- a/packages/safe-apps-provider/dist/provider.js +++ b/packages/safe-apps-provider/dist/provider.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SafeAppProvider = void 0; +const safe_apps_sdk_1 = require("@safe-global/safe-apps-sdk"); const events_1 = require("events"); const utils_1 = require("./utils"); // The API is based on Ethereum JavaScript API Provider Standard. Link: https://eips.ethereum.org/EIPS/eip-1193 @@ -29,7 +30,7 @@ class SafeAppProvider extends events_1.EventEmitter { return [this.safe.safeAddress]; case 'net_version': case 'eth_chainId': - return `0x${this.chainId.toString(16)}`; + return (0, utils_1.numberToHex)(this.chainId); case 'personal_sign': { const [message, address] = params; if (this.safe.safeAddress.toLowerCase() !== address.toLowerCase()) { @@ -155,6 +156,76 @@ class SafeAppProvider extends events_1.EventEmitter { return this.sdk.wallet.requestPermissions(params[0]); case 'safe_setSettings': return this.sdk.eth.setSafeSettings([params[0]]); + case 'wallet_sendCalls': { + if (params[0].from !== this.safe.safeAddress) { + throw Error('Invalid from address'); + } + const txs = params[0].calls.map((call, i) => { + if (call.chainId !== (0, utils_1.numberToHex)(this.chainId)) { + throw new Error(`Invalid call #${i}: Safe is not on chain ${call.chainId}`); + } + if (!call.to) { + throw new Error(`Invalid call #${i}: missing "to" field`); + } + return { + to: call.to, + data: call.data ?? '0x', + value: call.value ?? (0, utils_1.numberToHex)(0), + }; + }); + const { safeTxHash } = await this.sdk.txs.send({ txs }); + return safeTxHash; + } + case 'wallet_getCallsStatus': { + const CallStatus = { + [safe_apps_sdk_1.TransactionStatus.AWAITING_CONFIRMATIONS]: 'PENDING', + [safe_apps_sdk_1.TransactionStatus.AWAITING_EXECUTION]: 'PENDING', + [safe_apps_sdk_1.TransactionStatus.CANCELLED]: 'CONFIRMED', + [safe_apps_sdk_1.TransactionStatus.FAILED]: 'CONFIRMED', + [safe_apps_sdk_1.TransactionStatus.SUCCESS]: 'CONFIRMED', + }; + const tx = await this.sdk.txs.getBySafeTxHash(params[0]).catch(() => null); + if (!tx?.txHash) { + throw new Error('Transaction not found'); + } + const receipt = await this.sdk.eth.getTransactionReceipt([tx.txHash]).catch(() => null); + if (!receipt) { + throw new Error('Transaction receipt not found'); + } + const calls = tx.txData?.dataDecoded?.method !== 'multiSend' + ? 1 + : // Number of batched transactions + tx.txData.dataDecoded.parameters?.[0].valueDecoded?.length ?? 1; + // Typed as number; is hex + const blockNumber = Number(receipt.blockNumber); + const gasUsed = Number(receipt.gasUsed); + const receipts = Array(calls).fill({ + success: (0, utils_1.numberToHex)(tx.txStatus === safe_apps_sdk_1.TransactionStatus.SUCCESS ? 1 : 0), + blockHash: receipt.blockHash, + blockNumber: (0, utils_1.numberToHex)(blockNumber), + blockTimestamp: (0, utils_1.numberToHex)(tx.executedAt ?? 0), + gasUsed: (0, utils_1.numberToHex)(gasUsed), + transactionHash: tx.txHash, + logs: receipt.logs, + }); + return { + status: CallStatus[tx.txStatus], + receipts, + }; + } + case 'wallet_showCallsStatus': { + // Cannot open transaction details page via SDK + throw new Error(`"${request.method}" not supported`); + } + case 'wallet_getCapabilities': { + return { + [(0, utils_1.numberToHex)(this.chainId)]: { + atomicBatch: { + supported: true, + }, + }, + }; + } default: throw Error(`"${request.method}" not implemented`); } diff --git a/packages/safe-apps-provider/dist/provider.js.map b/packages/safe-apps-provider/dist/provider.js.map index 75bfe5e9..7388760a 100644 --- a/packages/safe-apps-provider/dist/provider.js.map +++ b/packages/safe-apps-provider/dist/provider.js.map @@ -1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;IACtC,iIAAiI;IACjI,IAAI,CAAC,OAAY,EAAE,QAA8C;QAC/D,IAAI,CAAC,OAAO;YAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAClB,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;aAC5E,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAtSD,0CAsSC"} \ No newline at end of file diff --git a/packages/safe-apps-provider/dist/utils.d.ts b/packages/safe-apps-provider/dist/utils.d.ts index c60dd7a8..30b30a96 100644 --- a/packages/safe-apps-provider/dist/utils.d.ts +++ b/packages/safe-apps-provider/dist/utils.d.ts @@ -1 +1,2 @@ export declare function getLowerCase(value: string): string; +export declare function numberToHex(value: number): `0x${string}`; diff --git a/packages/safe-apps-provider/dist/utils.js b/packages/safe-apps-provider/dist/utils.js index 422ad96b..9ea2f13d 100644 --- a/packages/safe-apps-provider/dist/utils.js +++ b/packages/safe-apps-provider/dist/utils.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getLowerCase = void 0; +exports.numberToHex = exports.getLowerCase = void 0; function getLowerCase(value) { if (value) { return value.toLowerCase(); @@ -8,4 +8,8 @@ function getLowerCase(value) { return value; } exports.getLowerCase = getLowerCase; +function numberToHex(value) { + return `0x${value.toString(16)}`; +} +exports.numberToHex = numberToHex; //# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/packages/safe-apps-provider/dist/utils.js.map b/packages/safe-apps-provider/dist/utils.js.map index 0e21bec9..30d8fa03 100644 --- a/packages/safe-apps-provider/dist/utils.js.map +++ b/packages/safe-apps-provider/dist/utils.js.map @@ -1 +1 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,KAAa;IACxC,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,oCAKC"} \ No newline at end of file +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,KAAa;IACxC,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,oCAKC;AAED,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC;AAFD,kCAEC"} \ No newline at end of file diff --git a/packages/safe-apps-provider/package.json b/packages/safe-apps-provider/package.json index 8fa51874..cf3711b0 100644 --- a/packages/safe-apps-provider/package.json +++ b/packages/safe-apps-provider/package.json @@ -1,6 +1,6 @@ { "name": "@safe-global/safe-apps-provider", - "version": "0.18.3", + "version": "0.18.4", "description": "A provider wrapper of Safe Apps SDK", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/packages/safe-apps-provider/src/provider.ts b/packages/safe-apps-provider/src/provider.ts index 01cee58e..4cb3baf4 100644 --- a/packages/safe-apps-provider/src/provider.ts +++ b/packages/safe-apps-provider/src/provider.ts @@ -1,7 +1,7 @@ -import SafeAppsSDK, { SafeInfo, Web3TransactionObject } from '@safe-global/safe-apps-sdk'; +import SafeAppsSDK, { SafeInfo, TransactionStatus, Web3TransactionObject } from '@safe-global/safe-apps-sdk'; import { EventEmitter } from 'events'; import { EIP1193Provider } from './types'; -import { getLowerCase } from './utils'; +import { getLowerCase, numberToHex } from './utils'; // The API is based on Ethereum JavaScript API Provider Standard. Link: https://eips.ethereum.org/EIPS/eip-1193 export class SafeAppProvider extends EventEmitter implements EIP1193Provider { @@ -38,7 +38,7 @@ export class SafeAppProvider extends EventEmitter implements EIP1193Provider { case 'net_version': case 'eth_chainId': - return `0x${this.chainId.toString(16)}`; + return numberToHex(this.chainId); case 'personal_sign': { const [message, address] = params; @@ -195,6 +195,96 @@ export class SafeAppProvider extends EventEmitter implements EIP1193Provider { case 'safe_setSettings': return this.sdk.eth.setSafeSettings([params[0]]); + case 'wallet_sendCalls': { + if (params[0].from !== this.safe.safeAddress) { + throw Error('Invalid from address'); + } + + const txs = params[0].calls.map( + ( + call: { to?: `0x${string}`; data?: `0x${string}`; value?: `0x${string}`; chainId?: `0x${string}` }, + i: number, + ) => { + if (call.chainId !== numberToHex(this.chainId)) { + throw new Error(`Invalid call #${i}: Safe is not on chain ${call.chainId}`); + } + if (!call.to) { + throw new Error(`Invalid call #${i}: missing "to" field`); + } + return { + to: call.to, + data: call.data ?? '0x', + value: call.value ?? numberToHex(0), + }; + }, + ); + + const { safeTxHash } = await this.sdk.txs.send({ txs }); + return safeTxHash; + } + + case 'wallet_getCallsStatus': { + const CallStatus: { + [key in TransactionStatus]: 'PENDING' | 'CONFIRMED'; + } = { + [TransactionStatus.AWAITING_CONFIRMATIONS]: 'PENDING', + [TransactionStatus.AWAITING_EXECUTION]: 'PENDING', + [TransactionStatus.CANCELLED]: 'CONFIRMED', + [TransactionStatus.FAILED]: 'CONFIRMED', + [TransactionStatus.SUCCESS]: 'CONFIRMED', + }; + + const tx = await this.sdk.txs.getBySafeTxHash(params[0]).catch(() => null); + if (!tx?.txHash) { + throw new Error('Transaction not found'); + } + + const receipt = await this.sdk.eth.getTransactionReceipt([tx.txHash]).catch(() => null); + if (!receipt) { + throw new Error('Transaction receipt not found'); + } + + const calls = + tx.txData?.dataDecoded?.method !== 'multiSend' + ? 1 + : // Number of batched transactions + tx.txData.dataDecoded.parameters?.[0].valueDecoded?.length ?? 1; + + // Typed as number; is hex + const blockNumber = Number(receipt.blockNumber); + const gasUsed = Number(receipt.gasUsed); + + const receipts = Array(calls).fill({ + success: numberToHex(tx.txStatus === TransactionStatus.SUCCESS ? 1 : 0), + blockHash: receipt.blockHash, + blockNumber: numberToHex(blockNumber), + blockTimestamp: numberToHex(tx.executedAt ?? 0), + gasUsed: numberToHex(gasUsed), + transactionHash: tx.txHash, + logs: receipt.logs, + }); + + return { + status: CallStatus[tx.txStatus], + receipts, + }; + } + + case 'wallet_showCallsStatus': { + // Cannot open transaction details page via SDK + throw new Error(`"${request.method}" not supported`); + } + + case 'wallet_getCapabilities': { + return { + [numberToHex(this.chainId)]: { + atomicBatch: { + supported: true, + }, + }, + }; + } + default: throw Error(`"${request.method}" not implemented`); } diff --git a/packages/safe-apps-provider/src/utils.ts b/packages/safe-apps-provider/src/utils.ts index b1bdc24a..956f2bf4 100644 --- a/packages/safe-apps-provider/src/utils.ts +++ b/packages/safe-apps-provider/src/utils.ts @@ -4,3 +4,7 @@ export function getLowerCase(value: string): string { } return value; } + +export function numberToHex(value: number): `0x${string}` { + return `0x${value.toString(16)}`; +} diff --git a/packages/safe-apps-sdk/dist/cjs/version.js b/packages/safe-apps-sdk/dist/cjs/version.js index 0cdae837..764b1729 100644 --- a/packages/safe-apps-sdk/dist/cjs/version.js +++ b/packages/safe-apps-sdk/dist/cjs/version.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSDKVersion = void 0; -const getSDKVersion = () => '9.0.0'; +const getSDKVersion = () => '9.1.0'; exports.getSDKVersion = getSDKVersion; //# sourceMappingURL=version.js.map \ No newline at end of file diff --git a/packages/safe-apps-sdk/dist/esm/version.js b/packages/safe-apps-sdk/dist/esm/version.js index 401b8959..55159035 100644 --- a/packages/safe-apps-sdk/dist/esm/version.js +++ b/packages/safe-apps-sdk/dist/esm/version.js @@ -1,2 +1,2 @@ -export const getSDKVersion = () => '9.0.0'; +export const getSDKVersion = () => '9.1.0'; //# sourceMappingURL=version.js.map \ No newline at end of file diff --git a/packages/safe-apps-sdk/src/version.ts b/packages/safe-apps-sdk/src/version.ts index 5940dc3f..6264cd59 100644 --- a/packages/safe-apps-sdk/src/version.ts +++ b/packages/safe-apps-sdk/src/version.ts @@ -1 +1 @@ -export const getSDKVersion = () => '9.0.0'; +export const getSDKVersion = () => '9.1.0'; diff --git a/yarn.lock b/yarn.lock index dc33e076..2eba0156 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7882,9 +7882,9 @@ internal-slot@^1.0.3, internal-slot@^1.0.5: side-channel "^1.0.4" ip@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da" - integrity sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ== + version "2.0.1" + resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.1.tgz#e8f3595d33a3ea66490204234b77636965307105" + integrity sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ== ipaddr.js@1.9.1: version "1.9.1"