Skip to content

Commit

Permalink
update client to allow transfer to off curve addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorian1te committed Feb 18, 2025
1 parent 5458003 commit b6a6e29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-beans-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-solana': patch
---

Allows tranfers to off-curve-addresses
5 changes: 5 additions & 0 deletions packages/xchain-solana/__e2e__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('Solana client', () => {
console.log(address)
})

it('Should validate address', async () => {
const res = await client.validateAddress('GHityuQumkHn8JPpHYt9oxR5xi9X8R2kWsprdH9nPvT7')
console.log(res)
})

it('Should get all address balances', async () => {
const balances = await client.getBalance('94bPUbh8iazbg2UgUDrmMkgWoZz9Q1H813JZifZRB35v')

Expand Down
7 changes: 7 additions & 0 deletions packages/xchain-solana/jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/lib'],
testMatch: ['<rootDir>/__e2e__/**/*.[jt]s?(x)'],
setupFilesAfterEnv: ['./jest.setup.js'],
}
8 changes: 4 additions & 4 deletions packages/xchain-solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export class Client extends BaseXChainClient {
} else {
// Token transfer
const mintAddress = new PublicKey(getContractAddressFromAsset(params.asset as TokenAsset))
const associatedTokenAddress = getAssociatedTokenAddressSync(mintAddress, toPubkey)
const associatedTokenAddress = getAssociatedTokenAddressSync(mintAddress, toPubkey, true) // allow off curve owners

try {
await getAccount(provider.solanaProvider, associatedTokenAddress, undefined, TOKEN_PROGRAM_ID)
Expand Down Expand Up @@ -647,11 +647,13 @@ export class Client extends BaseXChainClient {
if (asset && !eqAsset(asset, this.getAssetInfo().asset)) {
// Check if receipt token account is created, otherwise, create it
const mintAddress = new PublicKey(getContractAddressFromAsset(asset as TokenAsset))

await getOrCreateAssociatedTokenAccount(
provider.solanaProvider,
senderKeyPair,
mintAddress,
new PublicKey(recipient),
true,
)
}

Expand Down Expand Up @@ -720,7 +722,6 @@ export class Client extends BaseXChainClient {
try {
for (const provider of this.providers) {
const transaction = new Transaction()

const fromPubkey = new PublicKey(sender)
const toPubkey = new PublicKey(recipient)

Expand All @@ -741,7 +742,6 @@ export class Client extends BaseXChainClient {
} else {
// Token transfer
const mintAddress = new PublicKey(getContractAddressFromAsset(asset as TokenAsset))

const fromAssociatedAccount = getAssociatedTokenAddressSync(mintAddress, fromPubkey)
let fromTokenAccount: Account
try {
Expand All @@ -753,7 +753,7 @@ export class Client extends BaseXChainClient {
throw error
}

const toAssociatedAccount = getAssociatedTokenAddressSync(mintAddress, toPubkey)
const toAssociatedAccount = getAssociatedTokenAddressSync(mintAddress, toPubkey, true)
let toTokenAccount: Account
try {
toTokenAccount = await getAccount(provider.solanaProvider, toAssociatedAccount)
Expand Down

0 comments on commit b6a6e29

Please sign in to comment.