@atomiqlabs/chain-solana 8.0.2 → 9.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- package/dist/solana/SolanaChainType.d.ts +3 -2
- package/dist/solana/SolanaInitializer.d.ts +2 -2
- package/dist/solana/SolanaInitializer.js +9 -5
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +4 -4
- package/dist/solana/btcrelay/SolanaBtcRelay.js +13 -14
- package/dist/solana/{base → chain}/SolanaAction.d.ts +2 -2
- package/dist/solana/chain/SolanaChainInterface.d.ts +58 -0
- package/dist/solana/chain/SolanaChainInterface.js +112 -0
- package/dist/solana/{base → chain}/SolanaModule.d.ts +3 -3
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -0
- package/dist/solana/{base → chain}/modules/SolanaAddresses.js +2 -3
- package/dist/solana/events/SolanaChainEventsBrowser.js +0 -1
- package/dist/solana/program/SolanaProgramBase.d.ts +11 -5
- package/dist/solana/program/SolanaProgramBase.js +7 -7
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -0
- package/dist/solana/program/SolanaProgramModule.js +11 -0
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +4 -3
- package/dist/solana/program/modules/SolanaProgramEvents.js +8 -8
- package/dist/solana/swaps/SolanaSwapData.js +1 -1
- package/dist/solana/swaps/SolanaSwapModule.d.ts +6 -5
- package/dist/solana/swaps/SolanaSwapModule.js +5 -6
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +4 -23
- package/dist/solana/swaps/SolanaSwapProgram.js +22 -98
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +3 -2
- package/dist/solana/swaps/modules/SolanaDataAccount.js +9 -9
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +1 -1
- package/dist/solana/swaps/modules/SolanaLpVault.js +13 -13
- package/dist/solana/swaps/modules/SwapClaim.d.ts +3 -2
- package/dist/solana/swaps/modules/SwapClaim.js +15 -15
- package/dist/solana/swaps/modules/SwapInit.d.ts +1 -1
- package/dist/solana/swaps/modules/SwapInit.js +21 -21
- package/dist/solana/swaps/modules/SwapRefund.d.ts +1 -1
- package/dist/solana/swaps/modules/SwapRefund.js +17 -17
- package/package.json +2 -2
- package/src/index.ts +11 -11
- package/src/solana/SolanaChainType.ts +7 -2
- package/src/solana/SolanaInitializer.ts +13 -9
- package/src/solana/btcrelay/SolanaBtcRelay.ts +17 -17
- package/src/solana/{base → chain}/SolanaAction.ts +3 -3
- package/src/solana/chain/SolanaChainInterface.ts +175 -0
- package/src/solana/{base → chain}/SolanaModule.ts +3 -3
- package/src/solana/{base → chain}/modules/SolanaAddresses.ts +2 -3
- package/src/solana/events/SolanaChainEventsBrowser.ts +0 -1
- package/src/solana/program/SolanaProgramBase.ts +13 -10
- package/src/solana/program/SolanaProgramModule.ts +16 -0
- package/src/solana/program/modules/SolanaProgramEvents.ts +10 -9
- package/src/solana/swaps/SolanaSwapData.ts +1 -1
- package/src/solana/swaps/SolanaSwapModule.ts +8 -8
- package/src/solana/swaps/SolanaSwapProgram.ts +28 -133
- package/src/solana/swaps/modules/SolanaDataAccount.ts +11 -10
- package/src/solana/swaps/modules/SolanaLpVault.ts +15 -15
- package/src/solana/swaps/modules/SwapClaim.ts +17 -16
- package/src/solana/swaps/modules/SwapInit.ts +22 -22
- package/src/solana/swaps/modules/SwapRefund.ts +18 -18
- package/dist/solana/base/SolanaBase.d.ts +0 -36
- package/dist/solana/base/SolanaBase.js +0 -30
- package/dist/solana/base/modules/SolanaAddresses.d.ts +0 -9
- package/src/solana/base/SolanaBase.ts +0 -56
- /package/dist/solana/{base → chain}/SolanaAction.js +0 -0
- /package/dist/solana/{base → chain}/SolanaModule.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaBlocks.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaBlocks.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaEvents.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaEvents.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaFees.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaFees.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSignatures.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSignatures.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSlots.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSlots.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTokens.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTokens.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTransactions.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTransactions.js +0 -0
- /package/src/solana/{base → chain}/modules/SolanaBlocks.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaEvents.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaFees.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaSignatures.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaSlots.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaTokens.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaTransactions.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ParsedAccountsModeBlockResponse, PublicKey, SystemProgram, Transaction} from "@solana/web3.js";
|
|
2
2
|
import {SignatureVerificationError, SwapCommitStatus, SwapDataVerificationError} from "@atomiqlabs/base";
|
|
3
3
|
import {SolanaSwapData} from "../SolanaSwapData";
|
|
4
|
-
import {SolanaAction} from "../../
|
|
4
|
+
import {SolanaAction} from "../../chain/SolanaAction";
|
|
5
5
|
import {
|
|
6
6
|
Account,
|
|
7
7
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
TOKEN_PROGRAM_ID
|
|
10
10
|
} from "@solana/spl-token";
|
|
11
11
|
import {SolanaSwapModule} from "../SolanaSwapModule";
|
|
12
|
-
import {SolanaTx} from "../../
|
|
12
|
+
import {SolanaTx} from "../../chain/modules/SolanaTransactions";
|
|
13
13
|
import {toBN, tryWithRetries} from "../../../utils/Utils";
|
|
14
14
|
import {Buffer} from "buffer";
|
|
15
15
|
import {SolanaSigner} from "../../wallet/SolanaSigner";
|
|
16
|
-
import {SolanaTokens} from "../../
|
|
16
|
+
import {SolanaTokens} from "../../chain/modules/SolanaTokens";
|
|
17
17
|
|
|
18
18
|
export type SolanaPreFetchVerification = {
|
|
19
19
|
latestSlot?: {
|
|
@@ -55,18 +55,18 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
55
55
|
const accounts = {
|
|
56
56
|
claimer: swapData.claimer,
|
|
57
57
|
offerer: swapData.offerer,
|
|
58
|
-
escrowState: this.
|
|
58
|
+
escrowState: this.program.SwapEscrowState(paymentHash),
|
|
59
59
|
mint: swapData.token,
|
|
60
60
|
systemProgram: SystemProgram.programId,
|
|
61
61
|
claimerAta: swapData.payOut ? claimerAta : null,
|
|
62
|
-
claimerUserData: !swapData.payOut ? this.
|
|
62
|
+
claimerUserData: !swapData.payOut ? this.program.SwapUserVault(swapData.claimer, swapData.token) : null
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
if(swapData.payIn) {
|
|
66
66
|
const ata = getAssociatedTokenAddressSync(swapData.token, swapData.offerer);
|
|
67
67
|
|
|
68
68
|
return new SolanaAction(swapData.offerer, this.root,
|
|
69
|
-
await this.
|
|
69
|
+
await this.swapProgram.methods
|
|
70
70
|
.offererInitializePayIn(
|
|
71
71
|
swapData.toSwapDataStruct(),
|
|
72
72
|
[...Buffer.alloc(32, 0)],
|
|
@@ -75,8 +75,8 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
75
75
|
.accounts({
|
|
76
76
|
...accounts,
|
|
77
77
|
offererAta: ata,
|
|
78
|
-
vault: this.
|
|
79
|
-
vaultAuthority: this.
|
|
78
|
+
vault: this.program.SwapVault(swapData.token),
|
|
79
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
80
80
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
81
81
|
})
|
|
82
82
|
.instruction(),
|
|
@@ -84,7 +84,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
84
84
|
);
|
|
85
85
|
} else {
|
|
86
86
|
return new SolanaAction(swapData.claimer, this.root,
|
|
87
|
-
await this.
|
|
87
|
+
await this.swapProgram.methods
|
|
88
88
|
.offererInitialize(
|
|
89
89
|
swapData.toSwapDataStruct(),
|
|
90
90
|
swapData.securityDeposit,
|
|
@@ -94,7 +94,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
94
94
|
)
|
|
95
95
|
.accounts({
|
|
96
96
|
...accounts,
|
|
97
|
-
offererUserData: this.
|
|
97
|
+
offererUserData: this.program.SwapUserVault(swapData.offerer, swapData.token),
|
|
98
98
|
})
|
|
99
99
|
.instruction(),
|
|
100
100
|
SwapInit.CUCosts.INIT
|
|
@@ -354,14 +354,14 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
354
354
|
const sender = swapData.isPayIn() ? swapData.offerer : swapData.claimer;
|
|
355
355
|
const signer = swapData.isPayIn() ? swapData.claimer : swapData.offerer;
|
|
356
356
|
|
|
357
|
-
if(!swapData.isPayIn() && await this.
|
|
357
|
+
if(!swapData.isPayIn() && await this.program.isExpired(sender.toString(), swapData)) {
|
|
358
358
|
throw new SignatureVerificationError("Swap will expire too soon!");
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
if(prefix!==this.getAuthPrefix(swapData)) throw new SignatureVerificationError("Invalid prefix");
|
|
362
362
|
|
|
363
363
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
364
|
-
const isExpired = (BigInt(timeout) - currentTimestamp) < BigInt(this.
|
|
364
|
+
const isExpired = (BigInt(timeout) - currentTimestamp) < BigInt(this.program.authGracePeriod);
|
|
365
365
|
if (isExpired) throw new SignatureVerificationError("Authorization expired!");
|
|
366
366
|
|
|
367
367
|
const [transactionSlot, signatureString] = signature.split(";");
|
|
@@ -412,7 +412,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
412
412
|
const now = Date.now();
|
|
413
413
|
|
|
414
414
|
const slotExpiryTime = now + (slotsLeft*this.root.SLOT_TIME);
|
|
415
|
-
const timeoutExpiryTime = (parseInt(timeout)-this.
|
|
415
|
+
const timeoutExpiryTime = (parseInt(timeout)-this.program.authGracePeriod)*1000;
|
|
416
416
|
const expiry = Math.min(slotExpiryTime, timeoutExpiryTime);
|
|
417
417
|
|
|
418
418
|
if(expiry<now) return 0;
|
|
@@ -439,7 +439,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
439
439
|
const slotsLeft = lastValidTransactionSlot-latestSlot+this.SIGNATURE_SLOT_BUFFER;
|
|
440
440
|
|
|
441
441
|
if(slotsLeft<0) return true;
|
|
442
|
-
if((parseInt(timeout)+this.
|
|
442
|
+
if((parseInt(timeout)+this.program.authGracePeriod)*1000 < Date.now()) return true;
|
|
443
443
|
return false;
|
|
444
444
|
}
|
|
445
445
|
|
|
@@ -469,7 +469,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
469
469
|
() => this.isSignatureValid(swapData, timeout, prefix, signature, feeRate),
|
|
470
470
|
this.retryPolicy, (e) => e instanceof SignatureVerificationError
|
|
471
471
|
),
|
|
472
|
-
tryWithRetries(() => this.
|
|
472
|
+
tryWithRetries(() => this.program.getClaimHashStatus(swapData.getClaimHash()), this.retryPolicy)
|
|
473
473
|
]);
|
|
474
474
|
if(payStatus!==SwapCommitStatus.NOT_COMMITED) throw new SwapDataVerificationError("Invoice already being paid for or paid");
|
|
475
475
|
}
|
|
@@ -556,11 +556,11 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
556
556
|
|
|
557
557
|
if (offerer != null) accounts.push(offerer);
|
|
558
558
|
if (token != null) {
|
|
559
|
-
accounts.push(this.
|
|
559
|
+
accounts.push(this.program.SwapVault(token));
|
|
560
560
|
if (offerer != null) accounts.push(getAssociatedTokenAddressSync(token, offerer));
|
|
561
|
-
if (claimer != null) accounts.push(this.
|
|
561
|
+
if (claimer != null) accounts.push(this.program.SwapUserVault(claimer, token));
|
|
562
562
|
}
|
|
563
|
-
if (paymentHash != null) accounts.push(this.
|
|
563
|
+
if (paymentHash != null) accounts.push(this.program.SwapEscrowState(Buffer.from(paymentHash, "hex")));
|
|
564
564
|
|
|
565
565
|
const shouldCheckWSOLAta = token != null && offerer != null && token.equals(SolanaTokens.WSOL_ADDRESS);
|
|
566
566
|
let [feeRate, _account] = await Promise.all([
|
|
@@ -592,9 +592,9 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
592
592
|
public getInitFeeRate(offerer?: PublicKey, claimer?: PublicKey, token?: PublicKey, paymentHash?: string): Promise<string> {
|
|
593
593
|
const accounts: PublicKey[] = [];
|
|
594
594
|
|
|
595
|
-
if(offerer!=null && token!=null) accounts.push(this.
|
|
595
|
+
if(offerer!=null && token!=null) accounts.push(this.program.SwapUserVault(offerer, token));
|
|
596
596
|
if(claimer!=null) accounts.push(claimer)
|
|
597
|
-
if(paymentHash!=null) accounts.push(this.
|
|
597
|
+
if(paymentHash!=null) accounts.push(this.program.SwapEscrowState(Buffer.from(paymentHash, "hex")));
|
|
598
598
|
|
|
599
599
|
return this.root.Fees.getFeeRate(accounts);
|
|
600
600
|
}
|
|
@@ -604,7 +604,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
604
604
|
* and also deposit for ATAs
|
|
605
605
|
*/
|
|
606
606
|
async getInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint> {
|
|
607
|
-
if(swapData==null) return BigInt(this.
|
|
607
|
+
if(swapData==null) return BigInt(this.program.ESCROW_STATE_RENT_EXEMPT) + await this.getRawInitFee(swapData, feeRate);
|
|
608
608
|
|
|
609
609
|
feeRate = feeRate ||
|
|
610
610
|
(swapData.payIn
|
|
@@ -618,7 +618,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
618
618
|
Promise.resolve<null>(null)
|
|
619
619
|
]);
|
|
620
620
|
|
|
621
|
-
let resultingFee = BigInt(this.
|
|
621
|
+
let resultingFee = BigInt(this.program.ESCROW_STATE_RENT_EXEMPT) + rawFee;
|
|
622
622
|
if(initAta) resultingFee += BigInt(SolanaTokens.SPL_ATA_RENT_EXEMPT);
|
|
623
623
|
|
|
624
624
|
if(swapData.payIn && this.shouldWrapOnInit(swapData, feeRate) && this.extractAtaDataFromFeeRate(feeRate).initAta) {
|
|
@@ -3,7 +3,7 @@ import {SolanaSwapData} from "../SolanaSwapData";
|
|
|
3
3
|
import {sha256} from "@noble/hashes/sha2";
|
|
4
4
|
import {sign} from "tweetnacl";
|
|
5
5
|
import {SignatureVerificationError, SwapDataVerificationError} from "@atomiqlabs/base";
|
|
6
|
-
import {SolanaTx} from "../../
|
|
6
|
+
import {SolanaTx} from "../../chain/modules/SolanaTransactions";
|
|
7
7
|
import {
|
|
8
8
|
Ed25519Program,
|
|
9
9
|
PublicKey,
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
getAssociatedTokenAddressSync,
|
|
14
14
|
TOKEN_PROGRAM_ID
|
|
15
15
|
} from "@solana/spl-token";
|
|
16
|
-
import {SolanaAction} from "../../
|
|
16
|
+
import {SolanaAction} from "../../chain/SolanaAction";
|
|
17
17
|
import {toBN, tryWithRetries} from "../../../utils/Utils";
|
|
18
18
|
import {Buffer} from "buffer";
|
|
19
19
|
import {SolanaSigner} from "../../wallet/SolanaSigner";
|
|
20
|
-
import {SolanaTokens} from "../../
|
|
20
|
+
import {SolanaTokens} from "../../chain/modules/SolanaTokens";
|
|
21
21
|
import * as BN from "bn.js";
|
|
22
22
|
|
|
23
23
|
export class SwapRefund extends SolanaSwapModule {
|
|
@@ -39,8 +39,8 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
39
39
|
const accounts = {
|
|
40
40
|
offerer: swapData.offerer,
|
|
41
41
|
claimer: swapData.claimer,
|
|
42
|
-
escrowState: this.
|
|
43
|
-
claimerUserData: !swapData.payOut ? this.
|
|
42
|
+
escrowState: this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
|
|
43
|
+
claimerUserData: !swapData.payOut ? this.program.SwapUserVault(swapData.claimer, swapData.token) : null,
|
|
44
44
|
ixSysvar: refundAuthTimeout!=null ? SYSVAR_INSTRUCTIONS_PUBKEY : null
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -49,13 +49,13 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
49
49
|
const ata = getAssociatedTokenAddressSync(swapData.token, swapData.offerer);
|
|
50
50
|
|
|
51
51
|
return new SolanaAction(swapData.offerer, this.root,
|
|
52
|
-
await this.
|
|
52
|
+
await this.swapProgram.methods
|
|
53
53
|
.offererRefundPayIn(toBN(useTimeout))
|
|
54
54
|
.accounts({
|
|
55
55
|
...accounts,
|
|
56
56
|
offererAta: ata,
|
|
57
|
-
vault: this.
|
|
58
|
-
vaultAuthority: this.
|
|
57
|
+
vault: this.program.SwapVault(swapData.token),
|
|
58
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
59
59
|
tokenProgram: TOKEN_PROGRAM_ID
|
|
60
60
|
})
|
|
61
61
|
.instruction(),
|
|
@@ -63,11 +63,11 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
63
63
|
);
|
|
64
64
|
} else {
|
|
65
65
|
return new SolanaAction(swapData.offerer, this.root,
|
|
66
|
-
await this.
|
|
66
|
+
await this.swapProgram.methods
|
|
67
67
|
.offererRefund(toBN(useTimeout))
|
|
68
68
|
.accounts({
|
|
69
69
|
...accounts,
|
|
70
|
-
offererUserData: this.
|
|
70
|
+
offererUserData: this.program.SwapUserVault(swapData.offerer, swapData.token)
|
|
71
71
|
})
|
|
72
72
|
.instruction(),
|
|
73
73
|
SwapRefund.CUCosts.REFUND
|
|
@@ -166,7 +166,7 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
166
166
|
const expiryTimestamp = BigInt(timeout);
|
|
167
167
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
168
168
|
|
|
169
|
-
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.
|
|
169
|
+
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.program.authGracePeriod);
|
|
170
170
|
if(isExpired) throw new SignatureVerificationError("Authorization expired!");
|
|
171
171
|
|
|
172
172
|
const signatureBuffer = Buffer.from(signature, "hex");
|
|
@@ -193,13 +193,13 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
193
193
|
initAta?: boolean,
|
|
194
194
|
feeRate?: string
|
|
195
195
|
): Promise<SolanaTx[]> {
|
|
196
|
-
if(check && !await tryWithRetries(() => this.
|
|
196
|
+
if(check && !await tryWithRetries(() => this.program.isRequestRefundable(swapData.offerer.toString(), swapData), this.retryPolicy)) {
|
|
197
197
|
throw new SwapDataVerificationError("Not refundable yet!");
|
|
198
198
|
}
|
|
199
199
|
const shouldInitAta = swapData.isPayIn() && !await this.root.Tokens.ataExists(swapData.offererAta);
|
|
200
200
|
if(shouldInitAta && !initAta) throw new SwapDataVerificationError("ATA not initialized");
|
|
201
201
|
|
|
202
|
-
if(feeRate==null) feeRate = await this.
|
|
202
|
+
if(feeRate==null) feeRate = await this.program.getRefundFeeRate(swapData)
|
|
203
203
|
|
|
204
204
|
const shouldUnwrap = this.shouldUnwrap(swapData);
|
|
205
205
|
const action = new SolanaAction(swapData.offerer, this.root);
|
|
@@ -237,7 +237,7 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
237
237
|
initAta?: boolean,
|
|
238
238
|
feeRate?: string
|
|
239
239
|
): Promise<SolanaTx[]> {
|
|
240
|
-
if(check && !await tryWithRetries(() => this.
|
|
240
|
+
if(check && !await tryWithRetries(() => this.program.isCommited(swapData), this.retryPolicy)) {
|
|
241
241
|
throw new SwapDataVerificationError("Not correctly committed");
|
|
242
242
|
}
|
|
243
243
|
await tryWithRetries(
|
|
@@ -248,7 +248,7 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
248
248
|
const shouldInitAta = swapData.isPayIn() && !await this.root.Tokens.ataExists(swapData.offererAta);
|
|
249
249
|
if(shouldInitAta && !initAta) throw new SwapDataVerificationError("ATA not initialized");
|
|
250
250
|
|
|
251
|
-
if(feeRate==null) feeRate = await this.
|
|
251
|
+
if(feeRate==null) feeRate = await this.program.getRefundFeeRate(swapData);
|
|
252
252
|
console.log("[SolanaSwapProgram] txsRefundsWithAuthorization: feeRate: ", feeRate);
|
|
253
253
|
|
|
254
254
|
const signatureBuffer = Buffer.from(signature, "hex");
|
|
@@ -272,19 +272,19 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
272
272
|
public getRefundFeeRate(swapData: SolanaSwapData): Promise<string> {
|
|
273
273
|
const accounts: PublicKey[] = [];
|
|
274
274
|
if(swapData.payIn) {
|
|
275
|
-
if(swapData.token!=null) accounts.push(this.
|
|
275
|
+
if(swapData.token!=null) accounts.push(this.program.SwapVault(swapData.token));
|
|
276
276
|
if(swapData.offerer!=null) accounts.push(swapData.offerer);
|
|
277
277
|
if(swapData.claimer!=null) accounts.push(swapData.claimer);
|
|
278
278
|
if(swapData.offererAta!=null && !swapData.offererAta.equals(PublicKey.default)) accounts.push(swapData.offererAta);
|
|
279
279
|
} else {
|
|
280
280
|
if(swapData.offerer!=null) {
|
|
281
281
|
accounts.push(swapData.offerer);
|
|
282
|
-
if(swapData.token!=null) accounts.push(this.
|
|
282
|
+
if(swapData.token!=null) accounts.push(this.program.SwapUserVault(swapData.offerer, swapData.token));
|
|
283
283
|
}
|
|
284
284
|
if(swapData.claimer!=null) accounts.push(swapData.claimer);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
if(swapData.paymentHash!=null) accounts.push(this.
|
|
287
|
+
if(swapData.paymentHash!=null) accounts.push(this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")));
|
|
288
288
|
|
|
289
289
|
return this.root.Fees.getFeeRate(accounts);
|
|
290
290
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import { SolanaFees } from "./modules/SolanaFees";
|
|
3
|
-
import { SolanaBlocks } from "./modules/SolanaBlocks";
|
|
4
|
-
import { SolanaSlots } from "./modules/SolanaSlots";
|
|
5
|
-
import { SolanaTokens } from "./modules/SolanaTokens";
|
|
6
|
-
import { SolanaTransactions } from "./modules/SolanaTransactions";
|
|
7
|
-
import { SolanaAddresses } from "./modules/SolanaAddresses";
|
|
8
|
-
import { SolanaSignatures } from "./modules/SolanaSignatures";
|
|
9
|
-
import { SolanaEvents } from "./modules/SolanaEvents";
|
|
10
|
-
export type SolanaRetryPolicy = {
|
|
11
|
-
maxRetries?: number;
|
|
12
|
-
delay?: number;
|
|
13
|
-
exponential?: boolean;
|
|
14
|
-
transactionResendInterval?: number;
|
|
15
|
-
};
|
|
16
|
-
export declare class SolanaBase {
|
|
17
|
-
readonly SLOT_TIME = 400;
|
|
18
|
-
readonly TX_SLOT_VALIDITY = 151;
|
|
19
|
-
readonly connection: Connection;
|
|
20
|
-
readonly retryPolicy: SolanaRetryPolicy;
|
|
21
|
-
readonly Blocks: SolanaBlocks;
|
|
22
|
-
Fees: SolanaFees;
|
|
23
|
-
readonly Slots: SolanaSlots;
|
|
24
|
-
readonly Tokens: SolanaTokens;
|
|
25
|
-
readonly Transactions: SolanaTransactions;
|
|
26
|
-
readonly Addresses: SolanaAddresses;
|
|
27
|
-
readonly Signatures: SolanaSignatures;
|
|
28
|
-
readonly Events: SolanaEvents;
|
|
29
|
-
protected readonly logger: {
|
|
30
|
-
debug: (msg: any, ...args: any[]) => void;
|
|
31
|
-
info: (msg: any, ...args: any[]) => void;
|
|
32
|
-
warn: (msg: any, ...args: any[]) => void;
|
|
33
|
-
error: (msg: any, ...args: any[]) => void;
|
|
34
|
-
};
|
|
35
|
-
constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
|
|
36
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaBase = void 0;
|
|
4
|
-
const SolanaFees_1 = require("./modules/SolanaFees");
|
|
5
|
-
const SolanaBlocks_1 = require("./modules/SolanaBlocks");
|
|
6
|
-
const SolanaSlots_1 = require("./modules/SolanaSlots");
|
|
7
|
-
const SolanaTokens_1 = require("./modules/SolanaTokens");
|
|
8
|
-
const SolanaTransactions_1 = require("./modules/SolanaTransactions");
|
|
9
|
-
const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
10
|
-
const SolanaSignatures_1 = require("./modules/SolanaSignatures");
|
|
11
|
-
const SolanaEvents_1 = require("./modules/SolanaEvents");
|
|
12
|
-
const Utils_1 = require("../../utils/Utils");
|
|
13
|
-
class SolanaBase {
|
|
14
|
-
constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
|
|
15
|
-
this.SLOT_TIME = 400;
|
|
16
|
-
this.TX_SLOT_VALIDITY = 151;
|
|
17
|
-
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
18
|
-
this.connection = connection;
|
|
19
|
-
this.retryPolicy = retryPolicy;
|
|
20
|
-
this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
|
|
21
|
-
this.Fees = solanaFeeEstimator;
|
|
22
|
-
this.Slots = new SolanaSlots_1.SolanaSlots(this);
|
|
23
|
-
this.Tokens = new SolanaTokens_1.SolanaTokens(this);
|
|
24
|
-
this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
|
|
25
|
-
this.Addresses = new SolanaAddresses_1.SolanaAddresses(this);
|
|
26
|
-
this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
|
|
27
|
-
this.Events = new SolanaEvents_1.SolanaEvents(this);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.SolanaBase = SolanaBase;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SolanaModule } from "../SolanaModule";
|
|
2
|
-
export declare class SolanaAddresses extends SolanaModule {
|
|
3
|
-
/**
|
|
4
|
-
* Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
|
|
5
|
-
*
|
|
6
|
-
* @param address
|
|
7
|
-
*/
|
|
8
|
-
isValidAddress(address: string): boolean;
|
|
9
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {Connection} from "@solana/web3.js";
|
|
2
|
-
import {SolanaFees} from "./modules/SolanaFees";
|
|
3
|
-
import {SolanaBlocks} from "./modules/SolanaBlocks";
|
|
4
|
-
import {SolanaSlots} from "./modules/SolanaSlots";
|
|
5
|
-
import {SolanaTokens} from "./modules/SolanaTokens";
|
|
6
|
-
import {SolanaTransactions} from "./modules/SolanaTransactions";
|
|
7
|
-
import {SolanaAddresses} from "./modules/SolanaAddresses";
|
|
8
|
-
import {SolanaSignatures} from "./modules/SolanaSignatures";
|
|
9
|
-
import {SolanaEvents} from "./modules/SolanaEvents";
|
|
10
|
-
import {getLogger} from "../../utils/Utils";
|
|
11
|
-
|
|
12
|
-
export type SolanaRetryPolicy = {
|
|
13
|
-
maxRetries?: number,
|
|
14
|
-
delay?: number,
|
|
15
|
-
exponential?: boolean,
|
|
16
|
-
transactionResendInterval?: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class SolanaBase {
|
|
20
|
-
|
|
21
|
-
public readonly SLOT_TIME = 400;
|
|
22
|
-
public readonly TX_SLOT_VALIDITY = 151;
|
|
23
|
-
|
|
24
|
-
readonly connection: Connection;
|
|
25
|
-
readonly retryPolicy: SolanaRetryPolicy;
|
|
26
|
-
|
|
27
|
-
public readonly Blocks: SolanaBlocks;
|
|
28
|
-
public Fees: SolanaFees;
|
|
29
|
-
public readonly Slots: SolanaSlots;
|
|
30
|
-
public readonly Tokens: SolanaTokens;
|
|
31
|
-
public readonly Transactions: SolanaTransactions;
|
|
32
|
-
public readonly Addresses: SolanaAddresses;
|
|
33
|
-
public readonly Signatures: SolanaSignatures;
|
|
34
|
-
public readonly Events: SolanaEvents;
|
|
35
|
-
|
|
36
|
-
protected readonly logger = getLogger(this.constructor.name+": ");
|
|
37
|
-
|
|
38
|
-
constructor(
|
|
39
|
-
connection: Connection,
|
|
40
|
-
retryPolicy?: SolanaRetryPolicy,
|
|
41
|
-
solanaFeeEstimator: SolanaFees = new SolanaFees(connection)
|
|
42
|
-
) {
|
|
43
|
-
this.connection = connection;
|
|
44
|
-
this.retryPolicy = retryPolicy;
|
|
45
|
-
|
|
46
|
-
this.Blocks = new SolanaBlocks(this);
|
|
47
|
-
this.Fees = solanaFeeEstimator;
|
|
48
|
-
this.Slots = new SolanaSlots(this);
|
|
49
|
-
this.Tokens = new SolanaTokens(this);
|
|
50
|
-
this.Transactions = new SolanaTransactions(this);
|
|
51
|
-
this.Addresses = new SolanaAddresses(this);
|
|
52
|
-
this.Signatures = new SolanaSignatures(this);
|
|
53
|
-
this.Events = new SolanaEvents(this);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|