-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1231 Solana client #1254
Merged
Merged
1231 Solana client #1254
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
107c58f
Solana package skeleton
0xp3gasus f38a06e
Get and validate address functions
0xp3gasus acecfba
Derivation path bug fix
0xp3gasus f23e1de
Explorer functions
0xp3gasus 1f7b1f3
getBalance function skeleton
0xp3gasus 5f09c76
getBalance method with symbol fix
0xp3gasus 34fd2b0
Solana native asset estimate fee
0xp3gasus 7332f3a
getFees
0xp3gasus 51d3a22
GetFee method with create token account cost estimation
0xp3gasus ca08f3e
Get native transaction data method
0xp3gasus 07eabc2
Get token transaction data
0xp3gasus 7f6f8ee
Get transactions method
0xp3gasus 23ec4b5
Native asset transfer
0xp3gasus 44dc1f1
Solana token transfer
0xp3gasus 815cd05
Solana readme
0xp3gasus d567f06
Get balances bug fix
0xp3gasus 41e6545
Solana examples
0xp3gasus 2b0b94f
Tests
0xp3gasus f63bf99
typo
0xp3gasus b588beb
Merge branch 'master' into 1231-solana
0xp3gasus cdab945
Changeset version file
0xp3gasus b4b787f
Comments
0xp3gasus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xchainjs/xchain-solana': patch | ||
--- | ||
|
||
First release version of the package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
// These tasks will run in order when initializing your CodeSandbox project. | ||
"setupTasks": [ | ||
{ | ||
"name": "Install Dependencies", | ||
"command": "yarn install" | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,5 @@ | ||||||||
{ | ||||||||
"name": "Devcontainer", | ||||||||
"image": "ghcr.io/codesandbox/devcontainers/typescript-node:latest" | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# xchainjs-solana | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Solana | ||
|
||
Solana examples to show different use cases using the its client | ||
|
||
## Examples | ||
|
||
### Balances | ||
|
||
#### Get all balances | ||
|
||
Check out how you should get all balances an address owns in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/balances-all.ts) or run it as | ||
|
||
```sh | ||
yarn allBalances address | ||
``` | ||
|
||
#### Get specific asset balance | ||
|
||
Check out how you should get specific token balances an address owns in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/balance.ts) or run it as | ||
|
||
```sh | ||
yarn tokenBalance address token | ||
``` | ||
|
||
### Addresses | ||
|
||
#### Get address by index | ||
|
||
Check out how you should get you account address at certain index in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/address.ts) or run it as | ||
|
||
```sh | ||
yarn address phrase index | ||
``` | ||
|
||
### Transactions | ||
|
||
#### Prepare transaction | ||
|
||
Check out how you should prepare a transaction to be signed in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/address.ts) or run it as | ||
|
||
```sh | ||
yarn prepareTx sender recipient asset assetDecimals amount | ||
``` | ||
|
||
#### Make transaction | ||
|
||
Check out how you should make a Solana native asset transaction in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/address.ts) or run it as | ||
|
||
```sh | ||
yarn transfer phrase recipient amount | ||
``` | ||
|
||
#### Make token transaction | ||
|
||
Check out how you should make a Solana token transaction in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/address.ts) or run it as | ||
|
||
```sh | ||
yarn transferToken phrase recipient asset assetDecimals amount | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Client, defaultSolanaParams } from '@xchainjs/xchain-solana' | ||
|
||
const main = async () => { | ||
const phrase = `${process.argv[2]}` | ||
const index = process.argv[3] ? Number(process.argv[3]) : 0 | ||
const client = new Client({ ...defaultSolanaParams, phrase }) | ||
|
||
const address = await client.getAddressAsync(index) | ||
|
||
console.log(`You account at index ${index} is ${address}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Client } from '@xchainjs/xchain-solana' | ||
import { assetToString, baseToAsset } from '@xchainjs/xchain-util' | ||
|
||
const main = async () => { | ||
const address = `${process.argv[2]}` | ||
const client = new Client() | ||
|
||
const balances = await client.getBalance(address) | ||
|
||
console.log('---------------------------------------------------') | ||
console.log(`${address} balances`) | ||
console.log('---------------------------------------------------') | ||
console.table( | ||
balances.map((balance) => { | ||
return { Asset: assetToString(balance.asset), Amount: baseToAsset(balance.amount).amount().toString() } | ||
}), | ||
) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Client } from '@xchainjs/xchain-solana' | ||
import { TokenAsset, assetFromStringEx, assetToString, baseToAsset } from '@xchainjs/xchain-util' | ||
|
||
const main = async () => { | ||
const address = `${process.argv[2]}` | ||
const asset = assetFromStringEx(`${process.argv[3]}`) as TokenAsset | ||
const client = new Client() | ||
|
||
const balances = await client.getBalance(address, [asset]) | ||
|
||
console.log('---------------------------------------------------') | ||
console.log(`${address} balances`) | ||
console.log('---------------------------------------------------') | ||
console.table( | ||
balances.map((balance) => { | ||
return { Asset: assetToString(balance.asset), Amount: baseToAsset(balance.amount).amount().toString() } | ||
}), | ||
) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "xchainjs-solana", | ||
"private": true, | ||
"version": "0.0.1", | ||
"scripts": { | ||
"allBalances": "npx ts-node balance-all.ts", | ||
"tokenBalance": "npx ts-node balance-token.ts", | ||
"address": "npx ts-node address.ts", | ||
"prepareTx": "npx ts-node transaction-prepare.ts", | ||
"transfer": "npx ts-node transaction-transfer.ts", | ||
"transferToken": "npx ts-node transaction-transfer-token.ts", | ||
"build": "tsc --noEmit" | ||
}, | ||
"description": "Examples using Solana client", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@xchainjs/xchain-solana": "workspace:*", | ||
"@xchainjs/xchain-util": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.11.28", | ||
"ts-node": "10.9.2", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Client } from '@xchainjs/xchain-solana' | ||
import { Asset, TokenAsset, assetAmount, assetFromStringEx, assetToBase } from '@xchainjs/xchain-util' | ||
|
||
const main = async () => { | ||
const sender = `${process.argv[2]}` | ||
const recipient = `${process.argv[3]}` | ||
const asset = assetFromStringEx(`${process.argv[4]}`) as Asset | TokenAsset | ||
const amount = assetAmount(`${process.argv[6]}`, Number(process.argv[5])) | ||
|
||
const client = new Client() | ||
|
||
const { rawUnsignedTx } = await client.prepareTx({ | ||
sender, | ||
recipient, | ||
asset, | ||
amount: assetToBase(amount), | ||
}) | ||
|
||
console.log(rawUnsignedTx) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Client, defaultSolanaParams } from '@xchainjs/xchain-solana' | ||
import { Asset, TokenAsset, assetAmount, assetFromStringEx, assetToBase } from '@xchainjs/xchain-util' | ||
|
||
const main = async () => { | ||
const phrase = `${process.argv[2]}` | ||
const recipient = `${process.argv[3]}` | ||
const asset = assetFromStringEx(`${process.argv[4]}`) as Asset | TokenAsset | ||
const amount = assetAmount(`${process.argv[6]}`, Number(process.argv[5])) | ||
|
||
const client = new Client({ | ||
...defaultSolanaParams, | ||
phrase, | ||
}) | ||
|
||
const hash = await client.transfer({ | ||
recipient, | ||
asset, | ||
amount: assetToBase(amount), | ||
}) | ||
|
||
console.log({ | ||
hash, | ||
url: client.getExplorerTxUrl(hash), | ||
}) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Client, SOL_DECIMALS, defaultSolanaParams } from '@xchainjs/xchain-solana' | ||
import { assetAmount, assetToBase } from '@xchainjs/xchain-util' | ||
|
||
const main = async () => { | ||
const phrase = `${process.argv[2]}` | ||
const recipient = `${process.argv[3]}` | ||
const amount = assetAmount(`${process.argv[4]}`, SOL_DECIMALS) | ||
|
||
const client = new Client({ | ||
...defaultSolanaParams, | ||
phrase, | ||
}) | ||
|
||
const hash = await client.transfer({ | ||
recipient, | ||
amount: assetToBase(amount), | ||
}) | ||
|
||
console.log({ | ||
hash, | ||
url: client.getExplorerTxUrl(hash), | ||
}) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||
{ | ||||||||
"compilerOptions": { | ||||||||
"module":"commonjs", | ||||||||
"target": "es5", | ||||||||
"noEmitOnError": true, | ||||||||
"resolveJsonModule": true, | ||||||||
"esModuleInterop": true, | ||||||||
"lib": ["es6", "dom", "es2016", "es2017"] | ||||||||
} | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<div align="center"> | ||
<h1 align="center">Solana client</h1> | ||
|
||
<p align="center"> | ||
<a href='https://www.npmjs.com/package/@xchainjs/xchain-solana' target='_blank'> | ||
<img alt="NPM Version" src="https://img.shields.io/npm/v/%40xchainjs%2Fxchain-solana" /> | ||
</a> | ||
<a href='https://www.npmjs.com/package/@xchainjs/xchain-solana' target='_blank'> | ||
<img alt="NPM Downloads" src="https://img.shields.io/npm/d18m/%40xchainjs%2Fxchain-solana" /> | ||
</a> | ||
</p> | ||
</div> | ||
|
||
<br /> | ||
|
||
Client that allows to perform operations on the Solana blockchain abstracting developers from its particularities, thus allowing developers to focus on their projects. The Solana client is built on top of [@solana/web3.js](https://github.com/solana-labs/solana-web3.js) and the suite of packages developed by the [Metaplex](https://www.metaplex.com/) foundation. | ||
|
||
If you want to read more about Solana blockchain, go to its official [web site](https://solana.com/) | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
yarn add @xchainjs/xchain-solana | ||
``` | ||
or | ||
|
||
```sh | ||
npm install @xchainjs/xchain-solana | ||
``` | ||
|
||
## Initialization | ||
|
||
Using the Solana client you can initialize the main class of the module in consultation mode if you do not provide any parameters, this means you could retrieve information from the blockchain and prepare transactions to sign, but you will not be able to sign transactions, or generate addresses. | ||
|
||
```ts | ||
import { Client } from '@xchainjs/xchain-solana' | ||
|
||
const client = new Client() | ||
|
||
// Make read operations with your client | ||
``` | ||
|
||
Otherwise, if you want to sign transactions and get the addresses you own, you will need to initialize the main class of the protocol as follows | ||
|
||
```ts | ||
import { Client, defaultSolanaParams } from '@xchainjs/xchain-solana' | ||
|
||
const client = new Client({ | ||
phrase: 'your secret phrase', | ||
...defaultSolanaParams | ||
}) | ||
|
||
// Make read or write operations with your client | ||
``` | ||
|
||
## Features | ||
|
||
Thanks to the Solana client you will be able to: | ||
- Get the Solana and tokens balances that an address owns | ||
- Generate addresses given a secret phrase | ||
- Transfer Solana and tokens to another address | ||
- Get details of a transaction | ||
- Get address transaction history | ||
|
||
|
||
|
||
## Examples | ||
|
||
You can find examples using the Solana package in the [solana](https://github.com/xchainjs/xchainjs-lib/tree/master/examples/solana) examples folder. | ||
|
||
|
||
## Documentation | ||
|
||
More information about how to use the Solana client can be found on [documentation](https://xchainjs.gitbook.io/xchainjs/clients/xchain-solana) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.