@atomiqlabs/lp-lib 14.0.0-dev.31 → 14.0.0-dev.32

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.
@@ -80,35 +80,40 @@ class SpvVaults {
80
80
  const address = await this.vaultSigner.getAddress(chainId, vaultId);
81
81
  vaultAddreses.push({ vaultId, address });
82
82
  }
83
- //Construct transaction
84
- const txResult = await this.bitcoin.getSignedMultiTransaction(vaultAddreses.map(val => {
85
- return { address: val.address, amount: exports.VAULT_DUST_AMOUNT };
86
- }), feeRate);
87
83
  const nativeToken = chainInterface.getNativeCurrencyAddress();
88
- const vaults = await Promise.all(vaultAddreses.map(async (val, index) => {
89
- const vaultData = await spvVaultContract.createVaultData(signerAddress, val.vaultId, txResult.txId + ":" + index, confirmations, [
90
- { token, multiplier: tokenMultipliers?.[token] ?? 1n },
91
- { token: nativeToken, multiplier: tokenMultipliers?.[nativeToken] ?? 1n }
92
- ]);
93
- return new SpvVault_1.SpvVault(chainId, vaultData, val.address);
94
- }));
95
- //Save vaults
96
- if (this.vaultStorage.saveDataArr != null) {
97
- await this.vaultStorage.saveDataArr(vaults.map(val => {
98
- return { id: val.getIdentifier(), object: val };
84
+ let txId = null;
85
+ let vaults = null;
86
+ await this.bitcoin.execute(async () => {
87
+ //Construct transaction
88
+ const txResult = await this.bitcoin.getSignedMultiTransaction(vaultAddreses.map(val => {
89
+ return { address: val.address, amount: exports.VAULT_DUST_AMOUNT };
90
+ }), feeRate);
91
+ vaults = await Promise.all(vaultAddreses.map(async (val, index) => {
92
+ const vaultData = await spvVaultContract.createVaultData(signerAddress, val.vaultId, txResult.txId + ":" + index, confirmations, [
93
+ { token, multiplier: tokenMultipliers?.[token] ?? 1n },
94
+ { token: nativeToken, multiplier: tokenMultipliers?.[nativeToken] ?? 1n }
95
+ ]);
96
+ return new SpvVault_1.SpvVault(chainId, vaultData, val.address);
99
97
  }));
100
- }
101
- else {
102
- for (let vault of vaults) {
103
- await this.vaultStorage.saveData(vault.getIdentifier(), vault);
98
+ //Save vaults
99
+ if (this.vaultStorage.saveDataArr != null) {
100
+ await this.vaultStorage.saveDataArr(vaults.map(val => {
101
+ return { id: val.getIdentifier(), object: val };
102
+ }));
104
103
  }
105
- }
106
- //Send bitcoin tx
107
- await this.bitcoin.sendRawTransaction(txResult.raw);
108
- this.logger.info("createVaults(): Funding " + count + " vaults, bitcoin txId: " + txResult.txId);
104
+ else {
105
+ for (let vault of vaults) {
106
+ await this.vaultStorage.saveData(vault.getIdentifier(), vault);
107
+ }
108
+ }
109
+ //Send bitcoin tx
110
+ await this.bitcoin.sendRawTransaction(txResult.raw);
111
+ txId = txResult.txId;
112
+ });
113
+ this.logger.info("createVaults(): Funding " + count + " vaults, bitcoin txId: " + txId);
109
114
  return {
110
115
  vaultsCreated: vaults.map(val => val.data.getVaultId()),
111
- btcTxId: txResult.txId
116
+ btcTxId: txId
112
117
  };
113
118
  }
114
119
  async listVaults(chainId, token) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "14.0.0-dev.31",
3
+ "version": "14.0.0-dev.32",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -115,40 +115,46 @@ export class SpvVaults {
115
115
  vaultAddreses.push({vaultId, address});
116
116
  }
117
117
 
118
- //Construct transaction
119
- const txResult = await this.bitcoin.getSignedMultiTransaction(vaultAddreses.map(val => {
120
- return {address: val.address, amount: VAULT_DUST_AMOUNT}
121
- }), feeRate);
122
-
123
118
  const nativeToken = chainInterface.getNativeCurrencyAddress();
124
119
 
125
- const vaults = await Promise.all(vaultAddreses.map(async (val, index) => {
126
- const vaultData = await spvVaultContract.createVaultData(signerAddress, val.vaultId, txResult.txId+":"+index, confirmations, [
127
- {token, multiplier: tokenMultipliers?.[token] ?? 1n},
128
- {token: nativeToken, multiplier: tokenMultipliers?.[nativeToken] ?? 1n}
129
- ]);
130
- return new SpvVault(chainId, vaultData, val.address);
131
- }));
132
-
133
- //Save vaults
134
- if(this.vaultStorage.saveDataArr!=null) {
135
- await this.vaultStorage.saveDataArr(vaults.map(val => {
136
- return {id: val.getIdentifier(), object: val}
120
+ let txId: string = null;
121
+ let vaults: SpvVault[] = null;
122
+ await this.bitcoin.execute(async () => {
123
+ //Construct transaction
124
+ const txResult = await this.bitcoin.getSignedMultiTransaction(vaultAddreses.map(val => {
125
+ return {address: val.address, amount: VAULT_DUST_AMOUNT}
126
+ }), feeRate);
127
+
128
+ vaults = await Promise.all(vaultAddreses.map(async (val, index) => {
129
+ const vaultData = await spvVaultContract.createVaultData(signerAddress, val.vaultId, txResult.txId+":"+index, confirmations, [
130
+ {token, multiplier: tokenMultipliers?.[token] ?? 1n},
131
+ {token: nativeToken, multiplier: tokenMultipliers?.[nativeToken] ?? 1n}
132
+ ]);
133
+ return new SpvVault(chainId, vaultData, val.address);
137
134
  }));
138
- } else {
139
- for(let vault of vaults) {
140
- await this.vaultStorage.saveData(vault.getIdentifier(), vault);
135
+
136
+ //Save vaults
137
+ if(this.vaultStorage.saveDataArr!=null) {
138
+ await this.vaultStorage.saveDataArr(vaults.map(val => {
139
+ return {id: val.getIdentifier(), object: val}
140
+ }));
141
+ } else {
142
+ for(let vault of vaults) {
143
+ await this.vaultStorage.saveData(vault.getIdentifier(), vault);
144
+ }
141
145
  }
142
- }
143
146
 
144
- //Send bitcoin tx
145
- await this.bitcoin.sendRawTransaction(txResult.raw);
147
+ //Send bitcoin tx
148
+ await this.bitcoin.sendRawTransaction(txResult.raw);
149
+
150
+ txId = txResult.txId;
151
+ });
146
152
 
147
- this.logger.info("createVaults(): Funding "+count+" vaults, bitcoin txId: "+txResult.txId);
153
+ this.logger.info("createVaults(): Funding "+count+" vaults, bitcoin txId: "+txId);
148
154
 
149
155
  return {
150
156
  vaultsCreated: vaults.map(val => val.data.getVaultId()),
151
- btcTxId: txResult.txId
157
+ btcTxId: txId
152
158
  };
153
159
  }
154
160