Skip to content

Commit

Permalink
Merge pull request #37 from router-protocol/update/solana-eg
Browse files Browse the repository at this point in the history
update: solana docs
  • Loading branch information
vatsalgupta13 authored Oct 4, 2024
2 parents 7c9eb61 + 2829e0e commit 232f003
Showing 1 changed file with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,76 @@ const getTransaction = async (params, quoteData) => {
...quoteData,
senderAddress: "<sender-address>",
receiverAddress: "<receiver-address>",
refundAddress: "<refundAddress>" // (optional) By default equal to `senderAddress` if not provided
refundAddress: "<refundAddress>" // (optional) By default equal to `senderAddress` if not provided,
metaData: {
ataAddress:
await getAtaAddress( new PublicKey(senderAddress), fromTokenAddress)
}
})
return res.data;
} catch (e) {
console.error(`Fetching tx data from pathfinder: ${e}`)
}
}

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"}}'
```
Expand Down Expand Up @@ -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"
}'
```

0 comments on commit 232f003

Please sign in to comment.