@cityofzion/bs-ethereum 2.2.7 → 2.2.9
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/BSEthereum.js
CHANGED
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
37
37
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
38
|
};
|
|
39
|
-
var _BSEthereum_instances, _BSEthereum_setTokens;
|
|
39
|
+
var _BSEthereum_instances, _BSEthereum_buildTransferParams, _BSEthereum_setTokens;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.BSEthereum = void 0;
|
|
42
42
|
const ethers_1 = require("ethers");
|
|
@@ -139,76 +139,23 @@ class BSEthereum {
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
transfer(param) {
|
|
142
|
-
var _a;
|
|
143
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const
|
|
145
|
-
let
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
throw new Error('You must provide getLedgerTransport function to use Ledger');
|
|
149
|
-
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
150
|
-
}
|
|
151
|
-
let signer;
|
|
152
|
-
if (ledgerTransport) {
|
|
153
|
-
signer = this.ledgerService.getSigner(ledgerTransport, provider);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
|
|
143
|
+
const { signer, transactionParams, gasPrice } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, param);
|
|
144
|
+
let gasLimit;
|
|
145
|
+
try {
|
|
146
|
+
gasLimit = yield signer.estimateGas(transactionParams);
|
|
157
147
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const gasPrice = yield provider.getGasPrice();
|
|
161
|
-
let transactionParams = {
|
|
162
|
-
gasPrice,
|
|
163
|
-
};
|
|
164
|
-
const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
|
|
165
|
-
if (isNative) {
|
|
166
|
-
transactionParams.to = param.intent.receiverAddress;
|
|
167
|
-
transactionParams.value = amount;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
|
|
171
|
-
'function transfer(address to, uint amount) returns (bool)',
|
|
172
|
-
]);
|
|
173
|
-
const populatedTransaction = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
|
|
174
|
-
transactionParams = Object.assign(Object.assign({}, populatedTransaction), transactionParams);
|
|
148
|
+
catch (_a) {
|
|
149
|
+
gasLimit = BSEthereumHelper_1.BSEthereumHelper.DEFAULT_GAS_LIMIT;
|
|
175
150
|
}
|
|
176
|
-
const transaction = yield signer.sendTransaction(transactionParams);
|
|
151
|
+
const transaction = yield signer.sendTransaction(Object.assign(Object.assign({}, transactionParams), { gasLimit, maxPriorityFeePerGas: gasPrice, maxFeePerGas: gasPrice }));
|
|
177
152
|
return transaction.hash;
|
|
178
153
|
});
|
|
179
154
|
}
|
|
180
155
|
calculateTransferFee(param) {
|
|
181
|
-
var _a;
|
|
182
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
if (param.isLedger) {
|
|
186
|
-
if (!this.ledgerService.getLedgerTransport)
|
|
187
|
-
throw new Error('You must provide getLedgerTransport function to use Ledger');
|
|
188
|
-
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
189
|
-
}
|
|
190
|
-
let signer;
|
|
191
|
-
if (ledgerTransport) {
|
|
192
|
-
signer = this.ledgerService.getSigner(ledgerTransport, provider);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
|
|
196
|
-
}
|
|
197
|
-
const gasPrice = yield provider.getGasPrice();
|
|
198
|
-
let estimated;
|
|
199
|
-
const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
|
|
200
|
-
const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
201
|
-
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
|
|
202
|
-
if (!isNative) {
|
|
203
|
-
const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], signer);
|
|
204
|
-
estimated = yield contract.estimateGas.transfer(param.intent.receiverAddress, amount);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
estimated = yield signer.estimateGas({
|
|
208
|
-
to: param.intent.receiverAddress,
|
|
209
|
-
value: amount,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
157
|
+
const { signer, transactionParams, gasPrice } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, param);
|
|
158
|
+
const estimated = yield signer.estimateGas(transactionParams);
|
|
212
159
|
return ethers_1.ethers.utils.formatEther(gasPrice.mul(estimated));
|
|
213
160
|
});
|
|
214
161
|
}
|
|
@@ -223,7 +170,48 @@ class BSEthereum {
|
|
|
223
170
|
}
|
|
224
171
|
}
|
|
225
172
|
exports.BSEthereum = BSEthereum;
|
|
226
|
-
_BSEthereum_instances = new WeakSet(),
|
|
173
|
+
_BSEthereum_instances = new WeakSet(), _BSEthereum_buildTransferParams = function _BSEthereum_buildTransferParams(param) {
|
|
174
|
+
var _a;
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
177
|
+
let ledgerTransport;
|
|
178
|
+
if (param.isLedger) {
|
|
179
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
180
|
+
throw new Error('You must provide getLedgerTransport function to use Ledger');
|
|
181
|
+
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
182
|
+
}
|
|
183
|
+
let signer;
|
|
184
|
+
if (ledgerTransport) {
|
|
185
|
+
signer = this.ledgerService.getSigner(ledgerTransport, provider);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
|
|
189
|
+
}
|
|
190
|
+
const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
191
|
+
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
|
|
192
|
+
const gasPrice = yield provider.getGasPrice();
|
|
193
|
+
let transactionParams = {
|
|
194
|
+
type: 2,
|
|
195
|
+
};
|
|
196
|
+
const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
|
|
197
|
+
if (isNative) {
|
|
198
|
+
transactionParams.to = param.intent.receiverAddress;
|
|
199
|
+
transactionParams.value = amount;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
|
|
203
|
+
'function transfer(address to, uint amount) returns (bool)',
|
|
204
|
+
]);
|
|
205
|
+
const populatedTransaction = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
|
|
206
|
+
transactionParams = Object.assign(Object.assign({}, populatedTransaction), transactionParams);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
transactionParams,
|
|
210
|
+
signer,
|
|
211
|
+
gasPrice,
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
}, _BSEthereum_setTokens = function _BSEthereum_setTokens(network) {
|
|
227
215
|
const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(network);
|
|
228
216
|
this.tokens = [nativeAsset];
|
|
229
217
|
this.feeToken = nativeAsset;
|
|
@@ -3,6 +3,7 @@ export type BSEthereumNetworkId = NetworkId<'1' | '10' | '25' | '56' | '137' | '
|
|
|
3
3
|
export declare class BSEthereumHelper {
|
|
4
4
|
#private;
|
|
5
5
|
static DEFAULT_DECIMALS: number;
|
|
6
|
+
static DEFAULT_GAS_LIMIT: number;
|
|
6
7
|
static DERIVATION_PATH: string;
|
|
7
8
|
static DEFAULT_PATH: string;
|
|
8
9
|
static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId;
|
package/dist/BSEthereumHelper.js
CHANGED
|
@@ -30,6 +30,7 @@ class BSEthereumHelper {
|
|
|
30
30
|
exports.BSEthereumHelper = BSEthereumHelper;
|
|
31
31
|
_a = BSEthereumHelper;
|
|
32
32
|
BSEthereumHelper.DEFAULT_DECIMALS = 18;
|
|
33
|
+
BSEthereumHelper.DEFAULT_GAS_LIMIT = 0x5208;
|
|
33
34
|
_BSEthereumHelper_NATIVE_ASSET = { value: {
|
|
34
35
|
decimals: 18,
|
|
35
36
|
hash: '-',
|