@atomiqlabs/chain-solana
Advanced tools
Comparing version 7.3.6 to 7.3.7
@@ -120,11 +120,10 @@ import { SolanaSwapModule } from "../SolanaSwapModule"; | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN>; | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
* Get the estimated solana transaction fee of the claim transaction, without | ||
*/ | ||
getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN>; | ||
} |
@@ -276,16 +276,12 @@ "use strict"; | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
getClaimFee(signer, swapData, feeRate) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (swapData == null) | ||
return new BN(-this.root.ESCROW_STATE_RENT_EXEMPT + 5000); | ||
feeRate = feeRate || (yield this.getClaimFeeRate(signer, swapData)); | ||
return new BN(-this.root.ESCROW_STATE_RENT_EXEMPT + 5000).add(this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate)); | ||
return new BN(swapData == null || swapData.payOut ? this.root.Tokens.SPL_ATA_RENT_EXEMPT : 0).add(yield this.getRawClaimFee(signer, swapData, feeRate)); | ||
}); | ||
} | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
* Get the estimated solana transaction fee of the claim transaction, without | ||
*/ | ||
@@ -298,3 +294,3 @@ getRawClaimFee(signer, swapData, feeRate) { | ||
//Include rent exempt in claim fee, to take into consideration worst case cost when user destroys ATA | ||
return new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT + 5000).add(this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate)); | ||
return new BN(5000).add(this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate)); | ||
}); | ||
@@ -301,0 +297,0 @@ } |
@@ -210,2 +210,3 @@ /// <reference types="node" /> | ||
* Get the estimated solana fee of the init transaction, this includes the required deposit for creating swap PDA | ||
* and also deposit for ATAs | ||
*/ | ||
@@ -212,0 +213,0 @@ getInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>; |
@@ -490,6 +490,25 @@ "use strict"; | ||
* Get the estimated solana fee of the init transaction, this includes the required deposit for creating swap PDA | ||
* and also deposit for ATAs | ||
*/ | ||
getInitFee(swapData, feeRate) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add(yield this.getRawInitFee(swapData, feeRate)); | ||
if (swapData == null) | ||
return new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add(yield this.getRawInitFee(swapData, feeRate)); | ||
feeRate = feeRate || | ||
(swapData.payIn | ||
? yield this.getInitPayInFeeRate(swapData.offerer, swapData.claimer, swapData.token, swapData.paymentHash) | ||
: yield this.getInitFeeRate(swapData.offerer, swapData.claimer, swapData.token, swapData.paymentHash)); | ||
const [rawFee, initAta] = yield Promise.all([ | ||
this.getRawInitFee(swapData, feeRate), | ||
swapData != null && swapData.payOut ? | ||
this.root.Tokens.getATAOrNull((0, spl_token_1.getAssociatedTokenAddressSync)(swapData.claimer, swapData.token)).then(acc => acc == null) : | ||
Promise.resolve(null) | ||
]); | ||
let resultingFee = new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add(rawFee); | ||
if (initAta) | ||
resultingFee = resultingFee.add(new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT)); | ||
if (swapData.payIn && this.shouldWrapOnInit(swapData, feeRate) && this.extractAtaDataFromFeeRate(feeRate).initAta) { | ||
resultingFee = resultingFee.add(new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT)); | ||
} | ||
return resultingFee; | ||
}); | ||
@@ -496,0 +515,0 @@ } |
@@ -75,4 +75,4 @@ /// <reference types="node" /> | ||
/** | ||
* Get the estimated solana transaction fee of the refund transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the refund transaction, in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
@@ -79,0 +79,0 @@ getRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>; |
@@ -238,9 +238,8 @@ "use strict"; | ||
/** | ||
* Get the estimated solana transaction fee of the refund transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the refund transaction, in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
getRefundFee(swapData, feeRate) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const rawFee = yield this.getRawRefundFee(swapData, feeRate); | ||
return rawFee.sub(new BN(this.root.ESCROW_STATE_RENT_EXEMPT)); | ||
return new BN(swapData == null || swapData.payIn ? this.root.Tokens.SPL_ATA_RENT_EXEMPT : 0).add(yield this.getRawRefundFee(swapData, feeRate)); | ||
}); | ||
@@ -247,0 +246,0 @@ } |
@@ -287,5 +287,5 @@ "use strict"; | ||
let { balance, ataExists } = yield this.Tokens.getTokenBalance(publicKey, token); | ||
if (token.equals(this.Tokens.WSOL_ADDRESS) && !ataExists) { | ||
const feeCosts = new BN(this.Tokens.SPL_ATA_RENT_EXEMPT); | ||
balance = BN.max(balance.sub(feeCosts), new BN(0)); | ||
if (token.equals(this.Tokens.WSOL_ADDRESS)) { | ||
const accountRentExemptCost = new BN(1000000); | ||
balance = BN.max(balance.sub(accountRentExemptCost), new BN(0)); | ||
} | ||
@@ -292,0 +292,0 @@ this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10)); |
{ | ||
"name": "@atomiqlabs/chain-solana", | ||
"version": "7.3.6", | ||
"version": "7.3.7", | ||
"description": "Solana specific base implementation", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -369,12 +369,8 @@ import {SolanaSwapModule} from "../SolanaSwapModule"; | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
public async getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN> { | ||
if(swapData==null) return new BN(-this.root.ESCROW_STATE_RENT_EXEMPT+5000); | ||
feeRate = feeRate || await this.getClaimFeeRate(signer, swapData); | ||
return new BN(-this.root.ESCROW_STATE_RENT_EXEMPT+5000).add( | ||
this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate) | ||
return new BN(swapData==null || swapData.payOut ? this.root.Tokens.SPL_ATA_RENT_EXEMPT : 0).add( | ||
await this.getRawClaimFee(signer, swapData, feeRate) | ||
); | ||
@@ -384,4 +380,3 @@ } | ||
/** | ||
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
* Get the estimated solana transaction fee of the claim transaction, without | ||
*/ | ||
@@ -394,3 +389,3 @@ public async getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN> { | ||
//Include rent exempt in claim fee, to take into consideration worst case cost when user destroys ATA | ||
return new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT+5000).add( | ||
return new BN(5000).add( | ||
this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate) | ||
@@ -397,0 +392,0 @@ ); |
@@ -605,7 +605,27 @@ import {ParsedAccountsModeBlockResponse, PublicKey, SystemProgram, Transaction} from "@solana/web3.js"; | ||
* Get the estimated solana fee of the init transaction, this includes the required deposit for creating swap PDA | ||
* and also deposit for ATAs | ||
*/ | ||
async getInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN> { | ||
return new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add( | ||
await this.getRawInitFee(swapData, feeRate) | ||
); | ||
if(swapData==null) return new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add(await this.getRawInitFee(swapData, feeRate)); | ||
feeRate = feeRate || | ||
(swapData.payIn | ||
? await this.getInitPayInFeeRate(swapData.offerer, swapData.claimer, swapData.token, swapData.paymentHash) | ||
: await this.getInitFeeRate(swapData.offerer, swapData.claimer, swapData.token, swapData.paymentHash)); | ||
const [rawFee, initAta] = await Promise.all([ | ||
this.getRawInitFee(swapData, feeRate), | ||
swapData!=null && swapData.payOut ? | ||
this.root.Tokens.getATAOrNull(getAssociatedTokenAddressSync(swapData.claimer, swapData.token)).then(acc => acc==null) : | ||
Promise.resolve<null>(null) | ||
]); | ||
let resultingFee = new BN(this.root.ESCROW_STATE_RENT_EXEMPT).add(rawFee); | ||
if(initAta) resultingFee = resultingFee.add(new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT)); | ||
if(swapData.payIn && this.shouldWrapOnInit(swapData, feeRate) && this.extractAtaDataFromFeeRate(feeRate).initAta) { | ||
resultingFee = resultingFee.add(new BN(this.root.Tokens.SPL_ATA_RENT_EXEMPT)); | ||
} | ||
return resultingFee; | ||
} | ||
@@ -612,0 +632,0 @@ |
@@ -293,8 +293,9 @@ import {SolanaSwapModule} from "../SolanaSwapModule"; | ||
/** | ||
* Get the estimated solana transaction fee of the refund transaction, this fee might be negative since it | ||
* includes the rebate for closing the swap PDA | ||
* Get the estimated solana transaction fee of the refund transaction, in the worst case scenario in case where the | ||
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee) | ||
*/ | ||
async getRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN> { | ||
const rawFee = await this.getRawRefundFee(swapData, feeRate); | ||
return rawFee.sub(new BN(this.root.ESCROW_STATE_RENT_EXEMPT)); | ||
return new BN(swapData==null || swapData.payIn ? this.root.Tokens.SPL_ATA_RENT_EXEMPT : 0).add( | ||
await this.getRawRefundFee(swapData, feeRate) | ||
); | ||
} | ||
@@ -301,0 +302,0 @@ |
@@ -363,5 +363,5 @@ import {SolanaSwapData} from "./SolanaSwapData"; | ||
let { balance, ataExists } = await this.Tokens.getTokenBalance(publicKey, token); | ||
if(token.equals(this.Tokens.WSOL_ADDRESS) && !ataExists) { | ||
const feeCosts = new BN(this.Tokens.SPL_ATA_RENT_EXEMPT); | ||
balance = BN.max(balance.sub(feeCosts), new BN(0)); | ||
if(token.equals(this.Tokens.WSOL_ADDRESS)) { | ||
const accountRentExemptCost = new BN(1000000); | ||
balance = BN.max(balance.sub(accountRentExemptCost), new BN(0)); | ||
} | ||
@@ -368,0 +368,0 @@ this.logger.debug("getBalance(): token balance, token: "+token.toBase58()+" balance: "+balance.toString(10)); |
803416
20017