From 2829e0e97615700904691ac2509df5e663d37c6d Mon Sep 17 00:00:00 2001 From: kunalroute Date: Fri, 4 Oct 2024 15:31:48 +0530 Subject: [PATCH] update: solana docs --- .../solana-support.md | 160 +++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/docs/develop/asset-transfer-via-nitro/tools/nitro-pathfinder-api/performing-cross-chain-transaction/solana-support.md b/docs/develop/asset-transfer-via-nitro/tools/nitro-pathfinder-api/performing-cross-chain-transaction/solana-support.md index 12cf7a95..fe4eaf01 100644 --- a/docs/develop/asset-transfer-via-nitro/tools/nitro-pathfinder-api/performing-cross-chain-transaction/solana-support.md +++ b/docs/develop/asset-transfer-via-nitro/tools/nitro-pathfinder-api/performing-cross-chain-transaction/solana-support.md @@ -220,7 +220,11 @@ const getTransaction = async (params, quoteData) => { ...quoteData, senderAddress: "", receiverAddress: "", - refundAddress: "" // (optional) By default equal to `senderAddress` if not provided + refundAddress: "" // (optional) By default equal to `senderAddress` if not provided, + metaData: { + ataAddress: + await getAtaAddress( new PublicKey(senderAddress), fromTokenAddress) + } }) return res.data; } catch (e) { @@ -228,6 +232,64 @@ const getTransaction = async (params, quoteData) => { } } +async function getAtaAddress(wallet: string | PublicKey, asset: string) { + const ownerAddress = new PublicKey(wallet); + const tokenMintAddressPubKey = new PublicKey(asset) + console.log('asset - ', asset) + + const tokenProgram = asset === 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' ? TOKEN_PROGRAM_ID : TOKEN_2022_PROGRAM_ID + + const ataAddress = await getAssociatedTokenAddress( + tokenMintAddressPubKey, + ownerAddress, + true, + tokenProgram + ); + + const account = await solanaConnection.getAccountInfo(ataAddress); + + console.log('ata address from fn - ', ataAddress, ataAddress.toBase58(), account) + return ataAddress; +} + +``` + +Examples on testnet - + +1. Get quote +``` +curl 'https://k8-testnet-pf.routerchain.dev/api/v2/quote?fromTokenAddress=CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2&toTokenAddress=0x69dc97bb33e9030533ca2006ab4cef67f4db4125&amount=400000000&fromTokenChainId=solana-devnet&toTokenChainId=43113&partnerId=1&slippageTolerance=1&destFuel=0' \ + -H 'accept: application/json, text/plain, */*' \ + -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ + -H 'origin: https://testnet.routernitro.com' \ + -H 'priority: u=1, i' \ + -H 'referer: https://testnet.routernitro.com/' \ + -H 'sec-ch-ua: "Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"' \ + -H 'sec-ch-ua-mobile: ?0' \ + -H 'sec-ch-ua-platform: "macOS"' \ + -H 'sec-fetch-dest: empty' \ + -H 'sec-fetch-mode: cors' \ + -H 'sec-fetch-site: cross-site' \ + -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' +``` + +2. Build transaction +``` +curl 'https://k8-testnet-pf.routerchain.dev/api/v2/transaction' \ + -H 'accept: application/json, text/plain, */*' \ + -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ + -H 'content-type: application/json' \ + -H 'origin: https://testnet.routernitro.com' \ + -H 'priority: u=1, i' \ + -H 'referer: https://testnet.routernitro.com/' \ + -H 'sec-ch-ua: "Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"' \ + -H 'sec-ch-ua-mobile: ?0' \ + -H 'sec-ch-ua-platform: "macOS"' \ + -H 'sec-fetch-dest: empty' \ + -H 'sec-fetch-mode: cors' \ + -H 'sec-fetch-site: cross-site' \ + -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \ + --data-raw '{"flowType":"trustless","isTransfer":true,"isWrappedToken":false,"allowanceTo":"3rexFGP7LYszqCRZR78Bo6XNGZNLZekA2Lpgh9fAdaeY","bridgeFee":{"amount":"800000","decimals":18,"symbol":"AFTT","address":"CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2"},"fromTokenAddress":"CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2","toTokenAddress":"0x69dc97bb33e9030533ca2006ab4cef67f4db4125","source":{"chainId":"solana-devnet","chainType":"solana","asset":{"decimals":9,"symbol":"AFTT","name":"AFTT","chainId":"solana-devnet","address":"CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2","resourceID":"aftt","isMintable":false,"isWrappedAsset":false},"stableReserveAsset":{"decimals":9,"symbol":"AFTT","name":"AFTT","chainId":"solana-devnet","address":"CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2","resourceID":"aftt","isMintable":false,"isWrappedAsset":false},"tokenAmount":"400000000","stableReserveAmount":"400000000","path":[],"flags":[],"priceImpact":"0","tokenPath":"","dataTx":[]},"destination":{"chainId":"43113","chainType":"evm","asset":{"decimals":18,"symbol":"AFTT","name":"AFTT","chainId":"43113","address":"0x69DC97Bb33E9030533Ca2006aB4Cef67f4DB4125","resourceID":"aftt","isMintable":false,"isWrappedAsset":false},"stableReserveAsset":{"decimals":18,"symbol":"AFTT","name":"AFTT","chainId":"43113","address":"0x69DC97Bb33E9030533Ca2006aB4Cef67f4DB4125","resourceID":"aftt","isMintable":false,"isWrappedAsset":false},"tokenAmount":"399999999999200000","stableReserveAmount":"399999999999200000","path":[],"flags":[],"priceImpact":"0","tokenPath":"","dataTx":[]},"partnerId":1,"fuelTransfer":null,"slippageTolerance":"1","estimatedTime":40,"senderAddress":"GHELhmF2K3B9FthTq5FQAgN1ntJw6N4EmNqQYEjJdwPz","receiverAddress":"0x2B351b7bbC86ab5DF433539fE907f8EE4DE1B964","metaData":{"ataAddress":"6vyNyzxsD391XTK6q9j85Ns62nDGPZwHiJVB5eR1yC6E"}}' ``` @@ -263,3 +325,99 @@ const getTransaction = async (params, quoteData) => { ``` + + +Examples on testnet - + +1. Get quote +``` +curl --location 'https://k8-testnet-pf.routerchain.dev/api/v2/quote?fromTokenAddress=0x69dc97bb33e9030533ca2006ab4cef67f4db4125&toTokenAddress=CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2&amount=1000000000000000000&fromTokenChainId=43113&toTokenChainId=solana-devnet&partnerId=1&slippageTolerance=1&destFuel=0' +``` + +2. Build transaction +``` +curl --location 'https://k8-testnet-pf.routerchain.dev/api/v2/transaction' \ +--header 'Content-Type: application/json' \ +--data '{ + "flowType": "trustless", + "isTransfer": true, + "isWrappedToken": false, + "allowanceTo": "0x8db3ac65e18c87d960efd56e8fd3548acba51d8f", + "bridgeFee": { + "amount": "25000000", + "decimals": 9, + "symbol": "AFTT", + "address": "0x69DC97Bb33E9030533Ca2006aB4Cef67f4DB4125" + }, + "fromTokenAddress": "0x69dc97bb33e9030533ca2006ab4cef67f4db4125", + "toTokenAddress": "CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2", + "source": { + "chainId": "43113", + "chainType": "evm", + "asset": { + "decimals": 18, + "symbol": "AFTT", + "name": "AFTT", + "chainId": "43113", + "address": "0x69DC97Bb33E9030533Ca2006aB4Cef67f4DB4125", + "resourceID": "aftt", + "isMintable": false, + "isWrappedAsset": false + }, + "stableReserveAsset": { + "decimals": 18, + "symbol": "AFTT", + "name": "AFTT", + "chainId": "43113", + "address": "0x69DC97Bb33E9030533Ca2006aB4Cef67f4DB4125", + "resourceID": "aftt", + "isMintable": false, + "isWrappedAsset": false + }, + "tokenAmount": "1000000000000000000", + "stableReserveAmount": "1000000000000000000", + "path": [], + "flags": [], + "priceImpact": "0", + "tokenPath": "", + "dataTx": [] + }, + "destination": { + "chainId": "solana-devnet", + "chainType": "solana", + "asset": { + "decimals": 9, + "symbol": "AFTT", + "name": "AFTT", + "chainId": "solana-devnet", + "address": "CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2", + "resourceID": "aftt", + "isMintable": false, + "isWrappedAsset": false + }, + "stableReserveAsset": { + "decimals": 9, + "symbol": "AFTT", + "name": "AFTT", + "chainId": "solana-devnet", + "address": "CuDPEYd8tFRBvUs97mUQzQcECwgXGj5ZmFM4qNnjkfq2", + "resourceID": "aftt", + "isMintable": false, + "isWrappedAsset": false + }, + "tokenAmount": "975000000", + "stableReserveAmount": "975000000", + "path": [], + "flags": [], + "priceImpact": "0", + "tokenPath": "", + "dataTx": [] + }, + "partnerId": 1, + "fuelTransfer": null, + "slippageTolerance": "1", + "estimatedTime": 40, + "senderAddress": "0x2B351b7bbC86ab5DF433539fE907f8EE4DE1B964", + "receiverAddress": "GHELhmF2K3B9FthTq5FQAgN1ntJw6N4EmNqQYEjJdwPz" +}' +```