From 44c34c7826954fae36744d1a56a0714e3bdede98 Mon Sep 17 00:00:00 2001 From: tommasini <46944231+tommasini@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:06:23 +0000 Subject: [PATCH] wallet_swapAsset v1 (#201) * wallet_swapAsset v1 * add patterns to the user address and tokens address * update error codes and remove referral code, also edit the value property to optional and added to the description that defaults to 0 * remove bad identation * update api spec with the new params accordingly and remove sendTo optional param * add schema for caip10 addresses and update address format on swap asset rpc method * update error code * added more error to the api spec regarding caip 10 addresses * the swap could not be completed as requested * add schema for Caip10Address * remove invalid params error from the api spec * change the code of swap not available on chain to 36000 * Update openrpc.yaml Co-authored-by: Alex Donesky * Update openrpc.yaml Co-authored-by: Alex Donesky --------- Co-authored-by: Alex Donesky --- openrpc.yaml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/openrpc.yaml b/openrpc.yaml index ad18203..7b1652b 100644 --- a/openrpc.yaml +++ b/openrpc.yaml @@ -872,6 +872,76 @@ methods: result: name: eth_unsubscribeExampleResult value: true + - name: wallet_swapAsset + tags: + - $ref: '#/components/tags/MetaMask' + - $ref: '#/components/tags/Experimental' + summary: Allows dApps to request MetaMask to perform a token swap operation. + description: >- + This method enables dApps to initiate a token swap directly within MetaMask, improving the user experience by streamlining the process of swapping tokens. The method accepts parameters for the source and destination tokens and initiates a token swap operation. + params: + - name: SwapAssetParameter + required: true + schema: + title: SwapAssetParameter + type: object + required: + - fromToken + - toToken + - userAddress + properties: + fromToken: + type: array + items: + type: object + required: + - address + properties: + address: + type: string + description: The CAIP-10 formatted address of the source token. + $ref: '#/components/schemas/Caip10Address' + value: + type: string + description: (Optional) The amount of the source token to be swapped, in wei, as a hexadecimal string, defaults to 0. + nullable: true + toToken: + type: object + required: + - address + properties: + address: + type: string + description: The CAIP-10 formatted address of the destination token. + $ref: '#/components/schemas/Caip10Address' + userAddress: + type: string + description: The CAIP-10 formatted address of the user performing the swap. + $ref: '#/components/schemas/Caip10Address' + result: + name: SwapAssetResult + description: A boolean indicating if the swap was initiated successfully. + schema: + type: boolean + errors: + - code: 6000 + message: "Swap is not available on this chain {{chainName}}" + - code: -32600 + message: "Cross-chain swaps are currently not supported. Both fromToken and toToken must be on the same blockchain." + examples: + - name: wallet_swapAsset example + params: + - name: SwapAssetParameter + value: + from: + - tokenAddress: '0x1234567890abcdefABCDEF1234567890ABCDEF' + value: '0xDE0B6B3A7640000' + to: + tokenAddress: '0xabcdef1234567890ABCDEF1234567890abcdef' + userAddress: '0x0000000000000000000000000000000000000000' + result: + name: wallet_swapAssetExampleResult + value: true components: schemas: TypedData: @@ -1057,6 +1127,10 @@ components: type: array items: $ref: '#/components/schemas/Permission' + Caip10Address: + title: Caip10Address + type: string + description: CAIP-10 defines a way to identify an account/address in any blockchain. tags: MetaMask: name: MetaMask