@atomiqlabs/chain-solana 12.0.11 → 12.0.13
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/LICENSE +201 -201
- package/dist/index.d.ts +29 -29
- package/dist/index.js +45 -45
- package/dist/solana/SolanaChainType.d.ts +11 -11
- package/dist/solana/SolanaChainType.js +2 -2
- package/dist/solana/SolanaChains.d.ts +20 -20
- package/dist/solana/SolanaChains.js +25 -25
- package/dist/solana/SolanaInitializer.d.ts +18 -18
- package/dist/solana/SolanaInitializer.js +63 -63
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +228 -228
- package/dist/solana/btcrelay/SolanaBtcRelay.js +441 -441
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +29 -29
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +34 -34
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +46 -46
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +78 -78
- package/dist/solana/btcrelay/program/programIdl.json +671 -671
- package/dist/solana/chain/SolanaAction.d.ts +26 -26
- package/dist/solana/chain/SolanaAction.js +86 -86
- package/dist/solana/chain/SolanaChainInterface.d.ts +65 -65
- package/dist/solana/chain/SolanaChainInterface.js +125 -125
- package/dist/solana/chain/SolanaModule.d.ts +14 -14
- package/dist/solana/chain/SolanaModule.js +13 -13
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
- package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +28 -28
- package/dist/solana/chain/modules/SolanaBlocks.js +72 -72
- package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
- package/dist/solana/chain/modules/SolanaEvents.js +225 -225
- package/dist/solana/chain/modules/SolanaFees.d.ts +121 -121
- package/dist/solana/chain/modules/SolanaFees.js +379 -379
- package/dist/solana/chain/modules/SolanaSignatures.d.ts +23 -23
- package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
- package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
- package/dist/solana/chain/modules/SolanaSlots.js +68 -68
- package/dist/solana/chain/modules/SolanaTokens.d.ts +136 -136
- package/dist/solana/chain/modules/SolanaTokens.js +248 -248
- package/dist/solana/chain/modules/SolanaTransactions.d.ts +124 -124
- package/dist/solana/chain/modules/SolanaTransactions.js +323 -323
- package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
- package/dist/solana/events/SolanaChainEvents.js +256 -256
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +75 -75
- package/dist/solana/events/SolanaChainEventsBrowser.js +172 -172
- package/dist/solana/program/SolanaProgramBase.d.ts +40 -40
- package/dist/solana/program/SolanaProgramBase.js +43 -43
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
- package/dist/solana/program/SolanaProgramModule.js +11 -11
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
- package/dist/solana/program/modules/SolanaProgramEvents.js +114 -114
- package/dist/solana/swaps/SolanaSwapData.d.ts +71 -71
- package/dist/solana/swaps/SolanaSwapData.js +292 -292
- package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
- package/dist/solana/swaps/SolanaSwapModule.js +11 -11
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +224 -224
- package/dist/solana/swaps/SolanaSwapProgram.js +570 -567
- package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
- package/dist/solana/swaps/SwapTypeEnum.js +42 -42
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +94 -94
- package/dist/solana/swaps/modules/SolanaDataAccount.js +231 -231
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +71 -71
- package/dist/solana/swaps/modules/SolanaLpVault.js +173 -173
- package/dist/solana/swaps/modules/SwapClaim.d.ts +129 -129
- package/dist/solana/swaps/modules/SwapClaim.js +291 -291
- package/dist/solana/swaps/modules/SwapInit.d.ts +217 -217
- package/dist/solana/swaps/modules/SwapInit.js +519 -519
- package/dist/solana/swaps/modules/SwapRefund.d.ts +82 -82
- package/dist/solana/swaps/modules/SwapRefund.js +262 -262
- package/dist/solana/swaps/programIdl.json +945 -945
- package/dist/solana/swaps/programTypes.d.ts +943 -943
- package/dist/solana/swaps/programTypes.js +945 -945
- package/dist/solana/wallet/SolanaKeypairWallet.d.ts +9 -9
- package/dist/solana/wallet/SolanaKeypairWallet.js +33 -33
- package/dist/solana/wallet/SolanaSigner.d.ts +11 -11
- package/dist/solana/wallet/SolanaSigner.js +17 -17
- package/dist/utils/Utils.d.ts +53 -53
- package/dist/utils/Utils.js +170 -170
- package/package.json +41 -41
- package/src/index.ts +36 -36
- package/src/solana/SolanaChainType.ts +27 -27
- package/src/solana/SolanaChains.ts +23 -23
- package/src/solana/SolanaInitializer.ts +102 -102
- package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -589
- package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +57 -57
- package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +102 -102
- package/src/solana/btcrelay/program/programIdl.json +670 -670
- package/src/solana/chain/SolanaAction.ts +108 -108
- package/src/solana/chain/SolanaChainInterface.ts +192 -192
- package/src/solana/chain/SolanaModule.ts +20 -20
- package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
- package/src/solana/chain/modules/SolanaBlocks.ts +78 -78
- package/src/solana/chain/modules/SolanaEvents.ts +256 -256
- package/src/solana/chain/modules/SolanaFees.ts +450 -450
- package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
- package/src/solana/chain/modules/SolanaSlots.ts +82 -82
- package/src/solana/chain/modules/SolanaTokens.ts +307 -307
- package/src/solana/chain/modules/SolanaTransactions.ts +365 -365
- package/src/solana/events/SolanaChainEvents.ts +299 -299
- package/src/solana/events/SolanaChainEventsBrowser.ts +209 -209
- package/src/solana/program/SolanaProgramBase.ts +79 -79
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +155 -155
- package/src/solana/swaps/SolanaSwapData.ts +430 -430
- package/src/solana/swaps/SolanaSwapModule.ts +16 -16
- package/src/solana/swaps/SolanaSwapProgram.ts +854 -849
- package/src/solana/swaps/SwapTypeEnum.ts +29 -29
- package/src/solana/swaps/modules/SolanaDataAccount.ts +307 -307
- package/src/solana/swaps/modules/SolanaLpVault.ts +215 -215
- package/src/solana/swaps/modules/SwapClaim.ts +389 -389
- package/src/solana/swaps/modules/SwapInit.ts +663 -663
- package/src/solana/swaps/modules/SwapRefund.ts +323 -323
- package/src/solana/swaps/programIdl.json +944 -944
- package/src/solana/swaps/programTypes.ts +1885 -1885
- package/src/solana/wallet/SolanaKeypairWallet.ts +36 -36
- package/src/solana/wallet/SolanaSigner.ts +24 -24
- package/src/utils/Utils.ts +180 -180
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaLpVault = void 0;
|
|
4
|
-
const SolanaSwapModule_1 = require("../SolanaSwapModule");
|
|
5
|
-
const SolanaAction_1 = require("../../chain/SolanaAction");
|
|
6
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
8
|
-
const Utils_1 = require("../../../utils/Utils");
|
|
9
|
-
const SolanaTokens_1 = require("../../chain/modules/SolanaTokens");
|
|
10
|
-
class SolanaLpVault extends SolanaSwapModule_1.SolanaSwapModule {
|
|
11
|
-
/**
|
|
12
|
-
* Action for withdrawing funds from the LP vault
|
|
13
|
-
*
|
|
14
|
-
* @param signer
|
|
15
|
-
* @param token
|
|
16
|
-
* @param amount
|
|
17
|
-
* @constructor
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
async Withdraw(signer, token, amount) {
|
|
21
|
-
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
22
|
-
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
23
|
-
.withdraw((0, Utils_1.toBN)(amount))
|
|
24
|
-
.accounts({
|
|
25
|
-
signer,
|
|
26
|
-
signerAta: ata,
|
|
27
|
-
userData: this.program.SwapUserVault(signer, token),
|
|
28
|
-
vault: this.program.SwapVault(token),
|
|
29
|
-
vaultAuthority: this.program.SwapVaultAuthority,
|
|
30
|
-
mint: token,
|
|
31
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
32
|
-
})
|
|
33
|
-
.instruction(), SolanaLpVault.CUCosts.WITHDRAW);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Action for depositing funds to the LP vault
|
|
37
|
-
*
|
|
38
|
-
* @param signer
|
|
39
|
-
* @param token
|
|
40
|
-
* @param amount
|
|
41
|
-
* @constructor
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
async Deposit(signer, token, amount) {
|
|
45
|
-
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
46
|
-
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
47
|
-
.deposit((0, Utils_1.toBN)(amount))
|
|
48
|
-
.accounts({
|
|
49
|
-
signer,
|
|
50
|
-
signerAta: ata,
|
|
51
|
-
userData: this.program.SwapUserVault(signer, token),
|
|
52
|
-
vault: this.program.SwapVault(token),
|
|
53
|
-
vaultAuthority: this.program.SwapVaultAuthority,
|
|
54
|
-
mint: token,
|
|
55
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
56
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
57
|
-
})
|
|
58
|
-
.instruction(), SolanaLpVault.CUCosts.DEPOSIT);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns intermediary's reputation & vault balance for a specific token
|
|
62
|
-
*
|
|
63
|
-
* @param address
|
|
64
|
-
* @param token
|
|
65
|
-
*/
|
|
66
|
-
async getIntermediaryData(address, token) {
|
|
67
|
-
const data = await this.swapProgram.account.userAccount.fetchNullable(this.program.SwapUserVault(address, token));
|
|
68
|
-
if (data == null)
|
|
69
|
-
return null;
|
|
70
|
-
const response = [];
|
|
71
|
-
for (let i = 0; i < data.successVolume.length; i++) {
|
|
72
|
-
response[i] = {
|
|
73
|
-
successVolume: data.successVolume[i],
|
|
74
|
-
successCount: data.successCount[i],
|
|
75
|
-
failVolume: data.failVolume[i],
|
|
76
|
-
failCount: data.failCount[i],
|
|
77
|
-
coopCloseVolume: data.coopCloseVolume[i],
|
|
78
|
-
coopCloseCount: data.coopCloseCount[i]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
balance: (0, Utils_1.toBigInt)(data.amount),
|
|
83
|
-
reputation: response
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns intermediary's reputation for a specific token
|
|
88
|
-
*
|
|
89
|
-
* @param address
|
|
90
|
-
* @param token
|
|
91
|
-
*/
|
|
92
|
-
async getIntermediaryReputation(address, token) {
|
|
93
|
-
const intermediaryData = await this.getIntermediaryData(address, token);
|
|
94
|
-
return intermediaryData?.reputation;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns the balance of the token an intermediary has in his LP vault
|
|
98
|
-
*
|
|
99
|
-
* @param address
|
|
100
|
-
* @param token
|
|
101
|
-
*/
|
|
102
|
-
async getIntermediaryBalance(address, token) {
|
|
103
|
-
const intermediaryData = await this.getIntermediaryData(address, token);
|
|
104
|
-
const balance = intermediaryData?.balance;
|
|
105
|
-
this.logger.debug("getIntermediaryBalance(): token LP balance fetched, token: " + token.toString() +
|
|
106
|
-
" address: " + address + " amount: " + (balance == null ? "null" : balance.toString()));
|
|
107
|
-
return balance;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Creates transactions for withdrawing funds from the LP vault, creates ATA if it doesn't exist and unwraps
|
|
111
|
-
* WSOL to SOL if required
|
|
112
|
-
*
|
|
113
|
-
* @param signer
|
|
114
|
-
* @param token
|
|
115
|
-
* @param amount
|
|
116
|
-
* @param feeRate
|
|
117
|
-
*/
|
|
118
|
-
async txsWithdraw(signer, token, amount, feeRate) {
|
|
119
|
-
const ata = await (0, spl_token_1.getAssociatedTokenAddress)(token, signer);
|
|
120
|
-
feeRate = feeRate || await this.getFeeRate(signer, token);
|
|
121
|
-
const action = new SolanaAction_1.SolanaAction(signer, this.root);
|
|
122
|
-
if (!await this.root.Tokens.ataExists(ata)) {
|
|
123
|
-
action.add(this.root.Tokens.InitAta(signer, signer, token));
|
|
124
|
-
}
|
|
125
|
-
action.add(await this.Withdraw(signer, token, amount));
|
|
126
|
-
const shouldUnwrap = token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS);
|
|
127
|
-
if (shouldUnwrap)
|
|
128
|
-
action.add(this.root.Tokens.Unwrap(signer));
|
|
129
|
-
this.logger.debug("txsWithdraw(): withdraw TX created, token: " + token.toString() +
|
|
130
|
-
" amount: " + amount.toString(10) + " unwrapping: " + shouldUnwrap);
|
|
131
|
-
return [await action.tx(feeRate)];
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Creates transaction for depositing funds into the LP vault, wraps SOL to WSOL if required
|
|
135
|
-
*
|
|
136
|
-
* @param signer
|
|
137
|
-
* @param token
|
|
138
|
-
* @param amount
|
|
139
|
-
* @param feeRate
|
|
140
|
-
*/
|
|
141
|
-
async txsDeposit(signer, token, amount, feeRate) {
|
|
142
|
-
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
143
|
-
feeRate = feeRate || await this.getFeeRate(signer, token);
|
|
144
|
-
const action = new SolanaAction_1.SolanaAction(signer, this.root);
|
|
145
|
-
let wrapping = false;
|
|
146
|
-
if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
|
|
147
|
-
const account = await (0, Utils_1.tryWithRetries)(() => this.root.Tokens.getATAOrNull(ata), this.retryPolicy);
|
|
148
|
-
let balance = account == null ? 0n : account.amount;
|
|
149
|
-
if (balance < amount) {
|
|
150
|
-
action.add(this.root.Tokens.Wrap(signer, amount - balance, account == null));
|
|
151
|
-
wrapping = true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
action.addAction(await this.Deposit(signer, token, amount));
|
|
155
|
-
this.logger.debug("txsDeposit(): deposit TX created, token: " + token.toString() +
|
|
156
|
-
" amount: " + amount.toString(10) + " wrapping: " + wrapping);
|
|
157
|
-
return [await action.tx(feeRate)];
|
|
158
|
-
}
|
|
159
|
-
getFeeRate(signer, token) {
|
|
160
|
-
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
161
|
-
return this.root.Fees.getFeeRate([
|
|
162
|
-
signer,
|
|
163
|
-
ata,
|
|
164
|
-
this.program.SwapUserVault(signer, token),
|
|
165
|
-
this.program.SwapVault(token)
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.SolanaLpVault = SolanaLpVault;
|
|
170
|
-
SolanaLpVault.CUCosts = {
|
|
171
|
-
WITHDRAW: 50000,
|
|
172
|
-
DEPOSIT: 50000
|
|
173
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaLpVault = void 0;
|
|
4
|
+
const SolanaSwapModule_1 = require("../SolanaSwapModule");
|
|
5
|
+
const SolanaAction_1 = require("../../chain/SolanaAction");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
8
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
9
|
+
const SolanaTokens_1 = require("../../chain/modules/SolanaTokens");
|
|
10
|
+
class SolanaLpVault extends SolanaSwapModule_1.SolanaSwapModule {
|
|
11
|
+
/**
|
|
12
|
+
* Action for withdrawing funds from the LP vault
|
|
13
|
+
*
|
|
14
|
+
* @param signer
|
|
15
|
+
* @param token
|
|
16
|
+
* @param amount
|
|
17
|
+
* @constructor
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
async Withdraw(signer, token, amount) {
|
|
21
|
+
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
22
|
+
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
23
|
+
.withdraw((0, Utils_1.toBN)(amount))
|
|
24
|
+
.accounts({
|
|
25
|
+
signer,
|
|
26
|
+
signerAta: ata,
|
|
27
|
+
userData: this.program.SwapUserVault(signer, token),
|
|
28
|
+
vault: this.program.SwapVault(token),
|
|
29
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
30
|
+
mint: token,
|
|
31
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
32
|
+
})
|
|
33
|
+
.instruction(), SolanaLpVault.CUCosts.WITHDRAW);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Action for depositing funds to the LP vault
|
|
37
|
+
*
|
|
38
|
+
* @param signer
|
|
39
|
+
* @param token
|
|
40
|
+
* @param amount
|
|
41
|
+
* @constructor
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
async Deposit(signer, token, amount) {
|
|
45
|
+
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
46
|
+
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
47
|
+
.deposit((0, Utils_1.toBN)(amount))
|
|
48
|
+
.accounts({
|
|
49
|
+
signer,
|
|
50
|
+
signerAta: ata,
|
|
51
|
+
userData: this.program.SwapUserVault(signer, token),
|
|
52
|
+
vault: this.program.SwapVault(token),
|
|
53
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
54
|
+
mint: token,
|
|
55
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
56
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
57
|
+
})
|
|
58
|
+
.instruction(), SolanaLpVault.CUCosts.DEPOSIT);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns intermediary's reputation & vault balance for a specific token
|
|
62
|
+
*
|
|
63
|
+
* @param address
|
|
64
|
+
* @param token
|
|
65
|
+
*/
|
|
66
|
+
async getIntermediaryData(address, token) {
|
|
67
|
+
const data = await this.swapProgram.account.userAccount.fetchNullable(this.program.SwapUserVault(address, token));
|
|
68
|
+
if (data == null)
|
|
69
|
+
return null;
|
|
70
|
+
const response = [];
|
|
71
|
+
for (let i = 0; i < data.successVolume.length; i++) {
|
|
72
|
+
response[i] = {
|
|
73
|
+
successVolume: data.successVolume[i],
|
|
74
|
+
successCount: data.successCount[i],
|
|
75
|
+
failVolume: data.failVolume[i],
|
|
76
|
+
failCount: data.failCount[i],
|
|
77
|
+
coopCloseVolume: data.coopCloseVolume[i],
|
|
78
|
+
coopCloseCount: data.coopCloseCount[i]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
balance: (0, Utils_1.toBigInt)(data.amount),
|
|
83
|
+
reputation: response
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns intermediary's reputation for a specific token
|
|
88
|
+
*
|
|
89
|
+
* @param address
|
|
90
|
+
* @param token
|
|
91
|
+
*/
|
|
92
|
+
async getIntermediaryReputation(address, token) {
|
|
93
|
+
const intermediaryData = await this.getIntermediaryData(address, token);
|
|
94
|
+
return intermediaryData?.reputation;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the balance of the token an intermediary has in his LP vault
|
|
98
|
+
*
|
|
99
|
+
* @param address
|
|
100
|
+
* @param token
|
|
101
|
+
*/
|
|
102
|
+
async getIntermediaryBalance(address, token) {
|
|
103
|
+
const intermediaryData = await this.getIntermediaryData(address, token);
|
|
104
|
+
const balance = intermediaryData?.balance;
|
|
105
|
+
this.logger.debug("getIntermediaryBalance(): token LP balance fetched, token: " + token.toString() +
|
|
106
|
+
" address: " + address + " amount: " + (balance == null ? "null" : balance.toString()));
|
|
107
|
+
return balance;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates transactions for withdrawing funds from the LP vault, creates ATA if it doesn't exist and unwraps
|
|
111
|
+
* WSOL to SOL if required
|
|
112
|
+
*
|
|
113
|
+
* @param signer
|
|
114
|
+
* @param token
|
|
115
|
+
* @param amount
|
|
116
|
+
* @param feeRate
|
|
117
|
+
*/
|
|
118
|
+
async txsWithdraw(signer, token, amount, feeRate) {
|
|
119
|
+
const ata = await (0, spl_token_1.getAssociatedTokenAddress)(token, signer);
|
|
120
|
+
feeRate = feeRate || await this.getFeeRate(signer, token);
|
|
121
|
+
const action = new SolanaAction_1.SolanaAction(signer, this.root);
|
|
122
|
+
if (!await this.root.Tokens.ataExists(ata)) {
|
|
123
|
+
action.add(this.root.Tokens.InitAta(signer, signer, token));
|
|
124
|
+
}
|
|
125
|
+
action.add(await this.Withdraw(signer, token, amount));
|
|
126
|
+
const shouldUnwrap = token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS);
|
|
127
|
+
if (shouldUnwrap)
|
|
128
|
+
action.add(this.root.Tokens.Unwrap(signer));
|
|
129
|
+
this.logger.debug("txsWithdraw(): withdraw TX created, token: " + token.toString() +
|
|
130
|
+
" amount: " + amount.toString(10) + " unwrapping: " + shouldUnwrap);
|
|
131
|
+
return [await action.tx(feeRate)];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates transaction for depositing funds into the LP vault, wraps SOL to WSOL if required
|
|
135
|
+
*
|
|
136
|
+
* @param signer
|
|
137
|
+
* @param token
|
|
138
|
+
* @param amount
|
|
139
|
+
* @param feeRate
|
|
140
|
+
*/
|
|
141
|
+
async txsDeposit(signer, token, amount, feeRate) {
|
|
142
|
+
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
143
|
+
feeRate = feeRate || await this.getFeeRate(signer, token);
|
|
144
|
+
const action = new SolanaAction_1.SolanaAction(signer, this.root);
|
|
145
|
+
let wrapping = false;
|
|
146
|
+
if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
|
|
147
|
+
const account = await (0, Utils_1.tryWithRetries)(() => this.root.Tokens.getATAOrNull(ata), this.retryPolicy);
|
|
148
|
+
let balance = account == null ? 0n : account.amount;
|
|
149
|
+
if (balance < amount) {
|
|
150
|
+
action.add(this.root.Tokens.Wrap(signer, amount - balance, account == null));
|
|
151
|
+
wrapping = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
action.addAction(await this.Deposit(signer, token, amount));
|
|
155
|
+
this.logger.debug("txsDeposit(): deposit TX created, token: " + token.toString() +
|
|
156
|
+
" amount: " + amount.toString(10) + " wrapping: " + wrapping);
|
|
157
|
+
return [await action.tx(feeRate)];
|
|
158
|
+
}
|
|
159
|
+
getFeeRate(signer, token) {
|
|
160
|
+
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(token, signer);
|
|
161
|
+
return this.root.Fees.getFeeRate([
|
|
162
|
+
signer,
|
|
163
|
+
ata,
|
|
164
|
+
this.program.SwapUserVault(signer, token),
|
|
165
|
+
this.program.SwapVault(token)
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.SolanaLpVault = SolanaLpVault;
|
|
170
|
+
SolanaLpVault.CUCosts = {
|
|
171
|
+
WITHDRAW: 50000,
|
|
172
|
+
DEPOSIT: 50000
|
|
173
|
+
};
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import { SolanaSwapModule } from "../SolanaSwapModule";
|
|
2
|
-
import { SolanaSwapData } from "../SolanaSwapData";
|
|
3
|
-
import { RelaySynchronizer } from "@atomiqlabs/base";
|
|
4
|
-
import { PublicKey } from "@solana/web3.js";
|
|
5
|
-
import { SolanaTx } from "../../chain/modules/SolanaTransactions";
|
|
6
|
-
import { SolanaBtcStoredHeader } from "../../btcrelay/headers/SolanaBtcStoredHeader";
|
|
7
|
-
import { SolanaBtcRelay } from "../../btcrelay/SolanaBtcRelay";
|
|
8
|
-
import { SolanaSwapProgram } from "../SolanaSwapProgram";
|
|
9
|
-
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
10
|
-
import { SolanaChainInterface } from "../../chain/SolanaChainInterface";
|
|
11
|
-
export declare class SwapClaim extends SolanaSwapModule {
|
|
12
|
-
private static readonly CUCosts;
|
|
13
|
-
readonly btcRelay: SolanaBtcRelay<any>;
|
|
14
|
-
/**
|
|
15
|
-
* Claim action which uses the provided hex encoded secret for claiming the swap
|
|
16
|
-
*
|
|
17
|
-
* @param signer
|
|
18
|
-
* @param swapData
|
|
19
|
-
* @param secret
|
|
20
|
-
* @constructor
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
private Claim;
|
|
24
|
-
/**
|
|
25
|
-
* Verify and claim action required for BTC on-chain swaps verified through btc relay, adds the btc relay verify
|
|
26
|
-
* instruction to the 0th index in the transaction, also intentionally sets compute budget to null such that no
|
|
27
|
-
* compute budget instruction is added, since that takes up too much space and txs are limited to 1232 bytes
|
|
28
|
-
*
|
|
29
|
-
* @param signer
|
|
30
|
-
* @param swapData
|
|
31
|
-
* @param storeDataKey
|
|
32
|
-
* @param merkleProof
|
|
33
|
-
* @param commitedHeader
|
|
34
|
-
* @constructor
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
private VerifyAndClaim;
|
|
38
|
-
constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram, btcRelay: SolanaBtcRelay<any>);
|
|
39
|
-
/**
|
|
40
|
-
* Gets the compute budget required for claiming the swap
|
|
41
|
-
*
|
|
42
|
-
* @param swapData
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
private getComputeBudget;
|
|
46
|
-
/**
|
|
47
|
-
* Gets committed header, identified by blockhash & blockheight, determines required BTC relay blockheight based on
|
|
48
|
-
* requiredConfirmations
|
|
49
|
-
* If synchronizer is passed & blockhash is not found, it produces transactions to sync up the btc relay to the
|
|
50
|
-
* current chain tip & adds them to the txs array
|
|
51
|
-
*
|
|
52
|
-
* @param signer
|
|
53
|
-
* @param txBlockheight transaction blockheight
|
|
54
|
-
* @param requiredConfirmations required confirmation for the swap to be claimable with that TX
|
|
55
|
-
* @param blockhash blockhash of the block which includes the transaction
|
|
56
|
-
* @param txs solana transaction array, in case we need to synchronize the btc relay ourselves the synchronization
|
|
57
|
-
* txns are added here
|
|
58
|
-
* @param synchronizer optional synchronizer to use to synchronize the btc relay in case it is not yet synchronized
|
|
59
|
-
* to the required blockheight
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
62
|
-
private getCommitedHeaderAndSynchronize;
|
|
63
|
-
/**
|
|
64
|
-
* Adds the transactions required for initialization and writing of transaction data to the data account
|
|
65
|
-
*
|
|
66
|
-
* @param signer
|
|
67
|
-
* @param tx transaction to be written
|
|
68
|
-
* @param vout vout of the transaction to use to satisfy swap conditions
|
|
69
|
-
* @param feeRate fee rate for the transactions
|
|
70
|
-
* @param txs solana transaction array, init & write transactions are added here
|
|
71
|
-
* @private
|
|
72
|
-
* @returns {Promise<PublicKey>} publicKey/address of the data account
|
|
73
|
-
*/
|
|
74
|
-
private addTxsWriteTransactionData;
|
|
75
|
-
/**
|
|
76
|
-
* Checks whether we should unwrap the WSOL to SOL when claiming the swap
|
|
77
|
-
*
|
|
78
|
-
* @param signer
|
|
79
|
-
* @param swapData
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
private shouldUnwrap;
|
|
83
|
-
/**
|
|
84
|
-
* Creates transactions claiming the swap using a secret (for HTLC swaps)
|
|
85
|
-
*
|
|
86
|
-
* @param signer
|
|
87
|
-
* @param swapData swap to claim
|
|
88
|
-
* @param secret hex encoded secret pre-image to the HTLC hash
|
|
89
|
-
* @param checkExpiry whether to check if the swap is already expired (trying to claim an expired swap with a secret
|
|
90
|
-
* is dangerous because we might end up revealing the secret to the counterparty without being able to claim the swap)
|
|
91
|
-
* @param initAta whether to init the claimer's ATA if it doesn't exist
|
|
92
|
-
* @param feeRate fee rate to use for the transaction
|
|
93
|
-
* @param skipAtaCheck whether to check if ATA exists
|
|
94
|
-
*/
|
|
95
|
-
txsClaimWithSecret(signer: PublicKey, swapData: SolanaSwapData, secret: string, checkExpiry?: boolean, initAta?: boolean, feeRate?: string, skipAtaCheck?: boolean): Promise<SolanaTx[]>;
|
|
96
|
-
/**
|
|
97
|
-
* Creates transaction claiming the swap using a confirmed transaction data (for BTC on-chain swaps)
|
|
98
|
-
*
|
|
99
|
-
* @param signer
|
|
100
|
-
* @param swapData swap to claim
|
|
101
|
-
* @param blockheight blockheight of the bitcoin transaction
|
|
102
|
-
* @param tx bitcoin transaction that satisfies the swap condition
|
|
103
|
-
* @param vout vout of the bitcoin transaction that satisfies the swap condition
|
|
104
|
-
* @param commitedHeader commited header data from btc relay (fetched internally if null)
|
|
105
|
-
* @param synchronizer optional synchronizer to use in case we need to sync up the btc relay ourselves
|
|
106
|
-
* @param initAta whether to initialize claimer's ATA
|
|
107
|
-
* @param storageAccHolder an object holder filled in with the created data account where tx data is written
|
|
108
|
-
* @param feeRate fee rate to be used for the transactions
|
|
109
|
-
*/
|
|
110
|
-
txsClaimWithTxData(signer: PublicKey | SolanaSigner, swapData: SolanaSwapData, tx: {
|
|
111
|
-
blockhash: string;
|
|
112
|
-
confirmations: number;
|
|
113
|
-
txid: string;
|
|
114
|
-
hex: string;
|
|
115
|
-
height: number;
|
|
116
|
-
}, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, storageAccHolder?: {
|
|
117
|
-
storageAcc: PublicKey;
|
|
118
|
-
}, feeRate?: string): Promise<SolanaTx[] | null>;
|
|
119
|
-
getClaimFeeRate(signer: PublicKey, swapData: SolanaSwapData): Promise<string>;
|
|
120
|
-
/**
|
|
121
|
-
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the
|
|
122
|
-
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee)
|
|
123
|
-
*/
|
|
124
|
-
getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
|
|
125
|
-
/**
|
|
126
|
-
* Get the estimated solana transaction fee of the claim transaction, without
|
|
127
|
-
*/
|
|
128
|
-
getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
|
|
129
|
-
}
|
|
1
|
+
import { SolanaSwapModule } from "../SolanaSwapModule";
|
|
2
|
+
import { SolanaSwapData } from "../SolanaSwapData";
|
|
3
|
+
import { RelaySynchronizer } from "@atomiqlabs/base";
|
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
|
5
|
+
import { SolanaTx } from "../../chain/modules/SolanaTransactions";
|
|
6
|
+
import { SolanaBtcStoredHeader } from "../../btcrelay/headers/SolanaBtcStoredHeader";
|
|
7
|
+
import { SolanaBtcRelay } from "../../btcrelay/SolanaBtcRelay";
|
|
8
|
+
import { SolanaSwapProgram } from "../SolanaSwapProgram";
|
|
9
|
+
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
10
|
+
import { SolanaChainInterface } from "../../chain/SolanaChainInterface";
|
|
11
|
+
export declare class SwapClaim extends SolanaSwapModule {
|
|
12
|
+
private static readonly CUCosts;
|
|
13
|
+
readonly btcRelay: SolanaBtcRelay<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Claim action which uses the provided hex encoded secret for claiming the swap
|
|
16
|
+
*
|
|
17
|
+
* @param signer
|
|
18
|
+
* @param swapData
|
|
19
|
+
* @param secret
|
|
20
|
+
* @constructor
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private Claim;
|
|
24
|
+
/**
|
|
25
|
+
* Verify and claim action required for BTC on-chain swaps verified through btc relay, adds the btc relay verify
|
|
26
|
+
* instruction to the 0th index in the transaction, also intentionally sets compute budget to null such that no
|
|
27
|
+
* compute budget instruction is added, since that takes up too much space and txs are limited to 1232 bytes
|
|
28
|
+
*
|
|
29
|
+
* @param signer
|
|
30
|
+
* @param swapData
|
|
31
|
+
* @param storeDataKey
|
|
32
|
+
* @param merkleProof
|
|
33
|
+
* @param commitedHeader
|
|
34
|
+
* @constructor
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private VerifyAndClaim;
|
|
38
|
+
constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram, btcRelay: SolanaBtcRelay<any>);
|
|
39
|
+
/**
|
|
40
|
+
* Gets the compute budget required for claiming the swap
|
|
41
|
+
*
|
|
42
|
+
* @param swapData
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
private getComputeBudget;
|
|
46
|
+
/**
|
|
47
|
+
* Gets committed header, identified by blockhash & blockheight, determines required BTC relay blockheight based on
|
|
48
|
+
* requiredConfirmations
|
|
49
|
+
* If synchronizer is passed & blockhash is not found, it produces transactions to sync up the btc relay to the
|
|
50
|
+
* current chain tip & adds them to the txs array
|
|
51
|
+
*
|
|
52
|
+
* @param signer
|
|
53
|
+
* @param txBlockheight transaction blockheight
|
|
54
|
+
* @param requiredConfirmations required confirmation for the swap to be claimable with that TX
|
|
55
|
+
* @param blockhash blockhash of the block which includes the transaction
|
|
56
|
+
* @param txs solana transaction array, in case we need to synchronize the btc relay ourselves the synchronization
|
|
57
|
+
* txns are added here
|
|
58
|
+
* @param synchronizer optional synchronizer to use to synchronize the btc relay in case it is not yet synchronized
|
|
59
|
+
* to the required blockheight
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
private getCommitedHeaderAndSynchronize;
|
|
63
|
+
/**
|
|
64
|
+
* Adds the transactions required for initialization and writing of transaction data to the data account
|
|
65
|
+
*
|
|
66
|
+
* @param signer
|
|
67
|
+
* @param tx transaction to be written
|
|
68
|
+
* @param vout vout of the transaction to use to satisfy swap conditions
|
|
69
|
+
* @param feeRate fee rate for the transactions
|
|
70
|
+
* @param txs solana transaction array, init & write transactions are added here
|
|
71
|
+
* @private
|
|
72
|
+
* @returns {Promise<PublicKey>} publicKey/address of the data account
|
|
73
|
+
*/
|
|
74
|
+
private addTxsWriteTransactionData;
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether we should unwrap the WSOL to SOL when claiming the swap
|
|
77
|
+
*
|
|
78
|
+
* @param signer
|
|
79
|
+
* @param swapData
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private shouldUnwrap;
|
|
83
|
+
/**
|
|
84
|
+
* Creates transactions claiming the swap using a secret (for HTLC swaps)
|
|
85
|
+
*
|
|
86
|
+
* @param signer
|
|
87
|
+
* @param swapData swap to claim
|
|
88
|
+
* @param secret hex encoded secret pre-image to the HTLC hash
|
|
89
|
+
* @param checkExpiry whether to check if the swap is already expired (trying to claim an expired swap with a secret
|
|
90
|
+
* is dangerous because we might end up revealing the secret to the counterparty without being able to claim the swap)
|
|
91
|
+
* @param initAta whether to init the claimer's ATA if it doesn't exist
|
|
92
|
+
* @param feeRate fee rate to use for the transaction
|
|
93
|
+
* @param skipAtaCheck whether to check if ATA exists
|
|
94
|
+
*/
|
|
95
|
+
txsClaimWithSecret(signer: PublicKey, swapData: SolanaSwapData, secret: string, checkExpiry?: boolean, initAta?: boolean, feeRate?: string, skipAtaCheck?: boolean): Promise<SolanaTx[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates transaction claiming the swap using a confirmed transaction data (for BTC on-chain swaps)
|
|
98
|
+
*
|
|
99
|
+
* @param signer
|
|
100
|
+
* @param swapData swap to claim
|
|
101
|
+
* @param blockheight blockheight of the bitcoin transaction
|
|
102
|
+
* @param tx bitcoin transaction that satisfies the swap condition
|
|
103
|
+
* @param vout vout of the bitcoin transaction that satisfies the swap condition
|
|
104
|
+
* @param commitedHeader commited header data from btc relay (fetched internally if null)
|
|
105
|
+
* @param synchronizer optional synchronizer to use in case we need to sync up the btc relay ourselves
|
|
106
|
+
* @param initAta whether to initialize claimer's ATA
|
|
107
|
+
* @param storageAccHolder an object holder filled in with the created data account where tx data is written
|
|
108
|
+
* @param feeRate fee rate to be used for the transactions
|
|
109
|
+
*/
|
|
110
|
+
txsClaimWithTxData(signer: PublicKey | SolanaSigner, swapData: SolanaSwapData, tx: {
|
|
111
|
+
blockhash: string;
|
|
112
|
+
confirmations: number;
|
|
113
|
+
txid: string;
|
|
114
|
+
hex: string;
|
|
115
|
+
height: number;
|
|
116
|
+
}, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, storageAccHolder?: {
|
|
117
|
+
storageAcc: PublicKey;
|
|
118
|
+
}, feeRate?: string): Promise<SolanaTx[] | null>;
|
|
119
|
+
getClaimFeeRate(signer: PublicKey, swapData: SolanaSwapData): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the
|
|
122
|
+
* ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee)
|
|
123
|
+
*/
|
|
124
|
+
getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the estimated solana transaction fee of the claim transaction, without
|
|
127
|
+
*/
|
|
128
|
+
getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
|
|
129
|
+
}
|