Skip to content

Commit 7296916

Browse files
tommasiniadonesky1
andauthored
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 <[email protected]> * Update openrpc.yaml Co-authored-by: Alex Donesky <[email protected]> --------- Co-authored-by: Alex Donesky <[email protected]>
1 parent 73ffc96 commit 7296916

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

openrpc.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,76 @@ methods:
817817
result:
818818
name: eth_unsubscribeExampleResult
819819
value: true
820+
- name: wallet_swapAsset
821+
tags:
822+
- $ref: '#/components/tags/MetaMask'
823+
- $ref: '#/components/tags/Experimental'
824+
summary: Allows dApps to request MetaMask to perform a token swap operation.
825+
description: >-
826+
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.
827+
params:
828+
- name: SwapAssetParameter
829+
required: true
830+
schema:
831+
title: SwapAssetParameter
832+
type: object
833+
required:
834+
- fromToken
835+
- toToken
836+
- userAddress
837+
properties:
838+
fromToken:
839+
type: array
840+
items:
841+
type: object
842+
required:
843+
- address
844+
properties:
845+
address:
846+
type: string
847+
description: The CAIP-10 formatted address of the source token.
848+
$ref: '#/components/schemas/Caip10Address'
849+
value:
850+
type: string
851+
description: (Optional) The amount of the source token to be swapped, in wei, as a hexadecimal string, defaults to 0.
852+
nullable: true
853+
toToken:
854+
type: object
855+
required:
856+
- address
857+
properties:
858+
address:
859+
type: string
860+
description: The CAIP-10 formatted address of the destination token.
861+
$ref: '#/components/schemas/Caip10Address'
862+
userAddress:
863+
type: string
864+
description: The CAIP-10 formatted address of the user performing the swap.
865+
$ref: '#/components/schemas/Caip10Address'
866+
result:
867+
name: SwapAssetResult
868+
description: A boolean indicating if the swap was initiated successfully.
869+
schema:
870+
type: boolean
871+
errors:
872+
- code: 6000
873+
message: "Swap is not available on this chain {{chainName}}"
874+
- code: -32600
875+
message: "Cross-chain swaps are currently not supported. Both fromToken and toToken must be on the same blockchain."
876+
examples:
877+
- name: wallet_swapAsset example
878+
params:
879+
- name: SwapAssetParameter
880+
value:
881+
from:
882+
- tokenAddress: '0x1234567890abcdefABCDEF1234567890ABCDEF'
883+
value: '0xDE0B6B3A7640000'
884+
to:
885+
tokenAddress: '0xabcdef1234567890ABCDEF1234567890abcdef'
886+
userAddress: '0x0000000000000000000000000000000000000000'
887+
result:
888+
name: wallet_swapAssetExampleResult
889+
value: true
820890
components:
821891
schemas:
822892
TypedData:
@@ -1005,6 +1075,10 @@ components:
10051075
type: array
10061076
items:
10071077
$ref: '#/components/schemas/Permission'
1078+
Caip10Address:
1079+
title: Caip10Address
1080+
type: string
1081+
description: CAIP-10 defines a way to identify an account/address in any blockchain.
10081082
tags:
10091083
MetaMask:
10101084
name: MetaMask

0 commit comments

Comments
 (0)