@cityofzion/bs-neo3 1.15.2 → 1.15.4
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.
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { INeo3NeoXBridgeService,
|
|
1
|
+
import { INeo3NeoXBridgeService, TBridgeToken, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceConstants, TNeo3NeoXBridgeServiceGetNonceParams, TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { BSNeo3 } from '../../BSNeo3';
|
|
3
3
|
export declare class Neo3NeoXBridgeService<BSName extends string = string> implements INeo3NeoXBridgeService<BSName> {
|
|
4
4
|
#private;
|
|
5
5
|
readonly BRIDGE_SCRIPT_HASH = "0xbb19cfc864b73159277e1fd39694b3fd5fc613d2";
|
|
6
|
-
|
|
7
|
-
readonly BRIDGE_MIN_AMOUNT = 1;
|
|
8
|
-
readonly BRIDGE_NEOX_BASE_CONFIRMATION_URL = "https://xexplorer.neo.org:8877/api/v1/transactions/deposits";
|
|
9
|
-
readonly BRIDGE_NEOX_NEO_TOKEN_HASH = "0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f";
|
|
6
|
+
tokens: TBridgeToken<BSName>[];
|
|
10
7
|
constructor(service: BSNeo3<BSName>);
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
getApprovalFee(): Promise<string>;
|
|
9
|
+
getBridgeConstants(token: TBridgeToken<BSName>): Promise<TNeo3NeoXBridgeServiceConstants>;
|
|
13
10
|
bridge(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<BSName>): Promise<string>;
|
|
12
|
+
getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<BSName>): Promise<string>;
|
|
16
13
|
}
|
|
@@ -22,7 +22,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
|
-
var
|
|
25
|
+
var _Neo3NeoXBridgeService_service;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.Neo3NeoXBridgeService = void 0;
|
|
28
28
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
@@ -33,60 +33,75 @@ const DoraBDSNeo3_1 = require("../blockchain-data/DoraBDSNeo3");
|
|
|
33
33
|
const axios_1 = __importDefault(require("axios"));
|
|
34
34
|
class Neo3NeoXBridgeService {
|
|
35
35
|
constructor(service) {
|
|
36
|
-
_Neo3NeoXBridgeService_instances.add(this);
|
|
37
36
|
this.BRIDGE_SCRIPT_HASH = '0xbb19cfc864b73159277e1fd39694b3fd5fc613d2';
|
|
38
|
-
this.BRIDGE_GAS_FEE = 0.1;
|
|
39
|
-
this.BRIDGE_MIN_AMOUNT = 1;
|
|
40
|
-
this.BRIDGE_NEOX_BASE_CONFIRMATION_URL = 'https://xexplorer.neo.org:8877/api/v1/transactions/deposits';
|
|
41
|
-
this.BRIDGE_NEOX_NEO_TOKEN_HASH = '0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f';
|
|
42
37
|
_Neo3NeoXBridgeService_service.set(this, void 0);
|
|
43
38
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeService_service, service, "f");
|
|
39
|
+
this.tokens = [
|
|
40
|
+
Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN), { multichainId: 'gas', blockchain: service.name }),
|
|
41
|
+
Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN), { multichainId: 'neo', blockchain: service.name }),
|
|
42
|
+
];
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
getApprovalFee() {
|
|
46
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
|
|
48
|
-
throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
|
|
49
|
-
const normalizedSelectedToken = blockchain_service_1.BSTokenHelper.normalizeToken(token);
|
|
50
|
-
const selectedTokenBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.normalizeHash(balance.token.hash) === normalizedSelectedToken.hash);
|
|
51
|
-
if (!selectedTokenBalance) {
|
|
52
|
-
throw new blockchain_service_1.BSError('Token balance not found', 'TOKEN_BALANCE_NOT_FOUND');
|
|
53
|
-
}
|
|
54
|
-
const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(selectedTokenBalance.amount);
|
|
55
|
-
const validatedInputs = {
|
|
56
|
-
receiveAmount: amountNumber.minus(this.BRIDGE_MIN_AMOUNT).toString(),
|
|
57
|
-
token,
|
|
58
|
-
amount: amountNumber.toString(),
|
|
59
|
-
};
|
|
60
|
-
const fee = yield this.calculateFee({
|
|
61
|
-
account,
|
|
62
|
-
receiverAddress,
|
|
63
|
-
validatedInputs,
|
|
64
|
-
});
|
|
65
|
-
const maxAmount = amountNumber.minus(fee).toString();
|
|
66
|
-
return maxAmount;
|
|
46
|
+
throw new blockchain_service_1.BSError('Neo3 does not require approval', 'APPROVAl_NOT_NEEDED');
|
|
67
47
|
});
|
|
68
48
|
}
|
|
69
|
-
|
|
49
|
+
getBridgeConstants(token) {
|
|
70
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return total.toString();
|
|
51
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
52
|
+
rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
|
|
53
|
+
});
|
|
54
|
+
const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
|
|
55
|
+
let invocations;
|
|
56
|
+
if (isNativeToken) {
|
|
57
|
+
invocations = [
|
|
58
|
+
{ operation: 'nativeDepositFee', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
|
|
59
|
+
{ operation: 'minNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
|
|
60
|
+
{ operation: 'maxNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
|
|
61
|
+
];
|
|
83
62
|
}
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
else {
|
|
64
|
+
invocations = [
|
|
65
|
+
{
|
|
66
|
+
operation: 'tokenDepositFee',
|
|
67
|
+
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
68
|
+
args: [{ type: 'Hash160', value: token.hash }],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
operation: 'minTokenDeposit',
|
|
72
|
+
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
73
|
+
args: [{ type: 'Hash160', value: token.hash }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
operation: 'maxTokenDeposit',
|
|
77
|
+
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
78
|
+
args: [{ type: 'Hash160', value: token.hash }],
|
|
79
|
+
},
|
|
80
|
+
];
|
|
86
81
|
}
|
|
82
|
+
const response = yield invoker.testInvoke({
|
|
83
|
+
invocations,
|
|
84
|
+
});
|
|
85
|
+
const [depositFeeItem, minDepositItem, maxDepositItem] = response.stack;
|
|
86
|
+
if (!neon_dappkit_1.TypeChecker.isStackTypeInteger(depositFeeItem) ||
|
|
87
|
+
!neon_dappkit_1.TypeChecker.isStackTypeInteger(minDepositItem) ||
|
|
88
|
+
!neon_dappkit_1.TypeChecker.isStackTypeInteger(maxDepositItem))
|
|
89
|
+
throw new blockchain_service_1.BSError('Invalid response', 'INVALID_RESPONSE');
|
|
90
|
+
const bridgeFeeBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(depositFeeItem.value, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals).toString();
|
|
91
|
+
const minAmountBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(minDepositItem.value, token.decimals).toString();
|
|
92
|
+
const maxAmountBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(maxDepositItem.value, token.decimals).toString();
|
|
93
|
+
const bridgeFee = blockchain_service_1.BSBigNumberHelper.format(bridgeFeeBn, { decimals: BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals });
|
|
94
|
+
const bridgeMinAmount = blockchain_service_1.BSBigNumberHelper.format(minAmountBn, { decimals: token.decimals });
|
|
95
|
+
const bridgeMaxAmount = blockchain_service_1.BSBigNumberHelper.format(maxAmountBn, { decimals: token.decimals });
|
|
96
|
+
return {
|
|
97
|
+
bridgeFee,
|
|
98
|
+
bridgeMinAmount,
|
|
99
|
+
bridgeMaxAmount,
|
|
100
|
+
};
|
|
87
101
|
});
|
|
88
102
|
}
|
|
89
103
|
bridge(params) {
|
|
104
|
+
var _a, _b;
|
|
90
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
106
|
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
|
|
92
107
|
throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
|
|
@@ -97,206 +112,99 @@ class Neo3NeoXBridgeService {
|
|
|
97
112
|
account: neonJsAccount,
|
|
98
113
|
signingCallback: signingCallback,
|
|
99
114
|
});
|
|
100
|
-
const
|
|
101
|
-
|
|
115
|
+
const contractInvocation = {
|
|
116
|
+
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
117
|
+
operation: 'depositNative',
|
|
118
|
+
args: [
|
|
119
|
+
{ type: 'Hash160', value: neonJsAccount.address },
|
|
120
|
+
{ type: 'Hash160', value: params.receiverAddress },
|
|
121
|
+
{
|
|
122
|
+
type: 'Integer',
|
|
123
|
+
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(params.amount), params.token.decimals),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
type: 'Integer',
|
|
127
|
+
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(params.bridgeFee), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
const signer = {
|
|
132
|
+
scopes: 16,
|
|
133
|
+
allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash],
|
|
134
|
+
};
|
|
135
|
+
const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
|
|
136
|
+
if (!isNativeToken) {
|
|
137
|
+
(_a = contractInvocation.args) === null || _a === void 0 ? void 0 : _a.unshift({ type: 'Hash160', value: BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash });
|
|
138
|
+
(_b = signer.allowedContracts) === null || _b === void 0 ? void 0 : _b.push(BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash);
|
|
139
|
+
}
|
|
140
|
+
const transactionHash = yield invoker.invokeFunction({
|
|
141
|
+
invocations: [contractInvocation],
|
|
142
|
+
signers: [signer],
|
|
143
|
+
});
|
|
102
144
|
return transactionHash;
|
|
103
145
|
});
|
|
104
146
|
}
|
|
105
|
-
|
|
147
|
+
getNonce(params) {
|
|
148
|
+
var _a, _b;
|
|
106
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_validateGas).call(this, params);
|
|
150
|
+
let log;
|
|
151
|
+
try {
|
|
152
|
+
log = yield DoraBDSNeo3_1.DoraNeoRest.log(params.transactionHash, __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.id);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw new blockchain_service_1.BSError('Failed to get nonce from transaction log', 'FAILED_TO_GET_NONCE', error);
|
|
114
156
|
}
|
|
115
|
-
|
|
116
|
-
|
|
157
|
+
if ((log === null || log === void 0 ? void 0 : log.vmstate) !== 'HALT') {
|
|
158
|
+
throw new blockchain_service_1.BSError('Transaction invalid', 'INVALID_TRANSACTION');
|
|
159
|
+
}
|
|
160
|
+
const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
|
|
161
|
+
let nonce = null;
|
|
162
|
+
if (isNativeToken) {
|
|
163
|
+
const notification = log.notifications.find(item => item.event_name === 'NativeDeposit');
|
|
164
|
+
nonce = (_a = notification === null || notification === void 0 ? void 0 : notification.state.value[0].value) !== null && _a !== void 0 ? _a : null;
|
|
117
165
|
}
|
|
118
166
|
else {
|
|
119
|
-
|
|
167
|
+
const notification = log.notifications.find(item => item.event_name === 'TokenDeposit');
|
|
168
|
+
nonce = (_b = notification === null || notification === void 0 ? void 0 : notification.state.value[2].value) !== null && _b !== void 0 ? _b : null;
|
|
169
|
+
}
|
|
170
|
+
if (!nonce) {
|
|
171
|
+
throw new blockchain_service_1.BSError('Nonce not found in transaction log', 'NONCE_NOT_FOUND');
|
|
120
172
|
}
|
|
173
|
+
return nonce;
|
|
121
174
|
});
|
|
122
175
|
}
|
|
123
|
-
|
|
176
|
+
getTransactionHashByNonce(params) {
|
|
124
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
|
|
126
|
-
throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
|
|
178
|
+
let data;
|
|
127
179
|
try {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (isGasToken) {
|
|
139
|
-
const notification = log.notifications.find(item => item.event_name === 'NativeDeposit');
|
|
140
|
-
nonce = notification === null || notification === void 0 ? void 0 : notification.state.value[0].value;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
const notification = log.notifications.find(item => item.event_name === 'TokenDeposit');
|
|
144
|
-
nonce = notification === null || notification === void 0 ? void 0 : notification.state.value[2].value;
|
|
145
|
-
}
|
|
146
|
-
if (!nonce) {
|
|
147
|
-
throw new Error();
|
|
148
|
-
}
|
|
149
|
-
yield blockchain_service_1.BSUtilsHelper.retry(() => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
var _a;
|
|
151
|
-
let url;
|
|
152
|
-
if (isGasToken) {
|
|
153
|
-
url = `${this.BRIDGE_NEOX_BASE_CONFIRMATION_URL}/${nonce}`;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
url = `${this.BRIDGE_NEOX_BASE_CONFIRMATION_URL}/${this.BRIDGE_NEOX_NEO_TOKEN_HASH}/${nonce}`;
|
|
157
|
-
}
|
|
158
|
-
const response = yield axios_1.default.get(url);
|
|
159
|
-
if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.txid)) {
|
|
160
|
-
throw new blockchain_service_1.BSError('Transaction not found', 'TRANSACTION_NOT_FOUND');
|
|
161
|
-
}
|
|
162
|
-
}), {
|
|
163
|
-
retries: 10,
|
|
164
|
-
delay: 30000,
|
|
180
|
+
const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
|
|
181
|
+
const response = yield axios_1.default.post('https://neofura.ngd.network', {
|
|
182
|
+
jsonrpc: '2.0',
|
|
183
|
+
method: 'GetBridgeTxByNonce',
|
|
184
|
+
params: {
|
|
185
|
+
ContractHash: this.BRIDGE_SCRIPT_HASH,
|
|
186
|
+
TokenHash: isNativeToken ? '' : BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash,
|
|
187
|
+
Nonce: Number(params.nonce),
|
|
188
|
+
},
|
|
189
|
+
id: 1,
|
|
165
190
|
});
|
|
166
|
-
|
|
191
|
+
data = response.data;
|
|
167
192
|
}
|
|
168
193
|
catch (error) {
|
|
169
|
-
|
|
194
|
+
throw new blockchain_service_1.BSError('Failed to get transaction by nonce', 'FAILED_TO_GET_TRANSACTION_BY_NONCE', error);
|
|
195
|
+
}
|
|
196
|
+
if (!(data === null || data === void 0 ? void 0 : data.result)) {
|
|
197
|
+
throw new blockchain_service_1.BSError('Failed to get transaction by nonce', 'FAILED_TO_GET_TRANSACTION_BY_NONCE');
|
|
198
|
+
}
|
|
199
|
+
if (data.result.Vmstate !== 'HALT') {
|
|
200
|
+
throw new blockchain_service_1.BSError('Transaction invalid', 'INVALID_TRANSACTION');
|
|
170
201
|
}
|
|
202
|
+
if (!data.result.txid) {
|
|
203
|
+
throw new blockchain_service_1.BSError('Transaction ID not found in response', 'TXID_NOT_FOUND');
|
|
204
|
+
}
|
|
205
|
+
return data.result.txid;
|
|
171
206
|
});
|
|
172
207
|
}
|
|
173
208
|
}
|
|
174
209
|
exports.Neo3NeoXBridgeService = Neo3NeoXBridgeService;
|
|
175
|
-
_Neo3NeoXBridgeService_service = new WeakMap()
|
|
176
|
-
return {
|
|
177
|
-
invocations: [
|
|
178
|
-
{
|
|
179
|
-
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
180
|
-
operation: 'depositNative',
|
|
181
|
-
args: [
|
|
182
|
-
{ type: 'Hash160', value: neonJsAccount.address },
|
|
183
|
-
{ type: 'Hash160', value: receiverAddress },
|
|
184
|
-
{
|
|
185
|
-
type: 'Integer',
|
|
186
|
-
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(validatedInputs.receiveAmount), validatedInputs.token.decimals),
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
type: 'Integer',
|
|
190
|
-
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
signers: [
|
|
196
|
-
{
|
|
197
|
-
scopes: 16,
|
|
198
|
-
allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash],
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
};
|
|
202
|
-
}, _Neo3NeoXBridgeService_buildNeoCIM = function _Neo3NeoXBridgeService_buildNeoCIM({ receiverAddress, validatedInputs }, neonJsAccount) {
|
|
203
|
-
return {
|
|
204
|
-
invocations: [
|
|
205
|
-
{
|
|
206
|
-
scriptHash: this.BRIDGE_SCRIPT_HASH,
|
|
207
|
-
operation: 'depositToken',
|
|
208
|
-
args: [
|
|
209
|
-
{ type: 'Hash160', value: BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash },
|
|
210
|
-
{ type: 'Hash160', value: neonJsAccount.scriptHash },
|
|
211
|
-
{ type: 'Hash160', value: receiverAddress },
|
|
212
|
-
{
|
|
213
|
-
type: 'Integer',
|
|
214
|
-
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(validatedInputs.receiveAmount), validatedInputs.token.decimals),
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
type: 'Integer',
|
|
218
|
-
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
signers: [
|
|
224
|
-
{
|
|
225
|
-
scopes: 16,
|
|
226
|
-
allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash],
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
};
|
|
230
|
-
}, _Neo3NeoXBridgeService_buildCIM = function _Neo3NeoXBridgeService_buildCIM(params, neonJsAccount) {
|
|
231
|
-
const isGasToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.validatedInputs.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
|
|
232
|
-
if (isGasToken) {
|
|
233
|
-
return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildGasCIM).call(this, params, neonJsAccount);
|
|
234
|
-
}
|
|
235
|
-
return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildNeoCIM).call(this, params, neonJsAccount);
|
|
236
|
-
}, _Neo3NeoXBridgeService_validateGas = function _Neo3NeoXBridgeService_validateGas({ amount, balances, token, account, receiverAddress, }) {
|
|
237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
const gasBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN));
|
|
239
|
-
if (!gasBalance) {
|
|
240
|
-
throw new blockchain_service_1.BSError('GAS is necessary to bridge', 'GAS_BALANCE_NOT_FOUND');
|
|
241
|
-
}
|
|
242
|
-
const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(amount);
|
|
243
|
-
const gasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(gasBalance.amount);
|
|
244
|
-
const validatedInputs = {
|
|
245
|
-
receiveAmount: amountNumber.minus(this.BRIDGE_GAS_FEE).toString(),
|
|
246
|
-
token,
|
|
247
|
-
amount,
|
|
248
|
-
};
|
|
249
|
-
if (amountNumber.isLessThan(this.BRIDGE_MIN_AMOUNT + this.BRIDGE_GAS_FEE)) {
|
|
250
|
-
throw new blockchain_service_1.BSError('Amount is less than the minimum amount plus bridge fee', 'AMOUNT_TOO_LOW');
|
|
251
|
-
}
|
|
252
|
-
if (amountNumber.isGreaterThan(gasBalanceNumber)) {
|
|
253
|
-
throw new blockchain_service_1.BSError('Amount is greater than your balance', 'INSUFFICIENT_GAS_BALANCE');
|
|
254
|
-
}
|
|
255
|
-
const fee = yield this.calculateFee({
|
|
256
|
-
account,
|
|
257
|
-
receiverAddress,
|
|
258
|
-
validatedInputs,
|
|
259
|
-
});
|
|
260
|
-
if (amountNumber.plus(fee).isGreaterThan(gasBalanceNumber)) {
|
|
261
|
-
throw new blockchain_service_1.BSError('Amount is greater than your balance plus fee', 'INSUFFICIENT_GAS_BALANCE_FEE');
|
|
262
|
-
}
|
|
263
|
-
return validatedInputs;
|
|
264
|
-
});
|
|
265
|
-
}, _Neo3NeoXBridgeService_validateNeo = function _Neo3NeoXBridgeService_validateNeo({ amount, balances, token, account, receiverAddress, }) {
|
|
266
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
-
const gasBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN));
|
|
268
|
-
if (!gasBalance) {
|
|
269
|
-
throw new blockchain_service_1.BSError('GAS is necessary to bridge', 'GAS_BALANCE_NOT_FOUND');
|
|
270
|
-
}
|
|
271
|
-
const neoBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN));
|
|
272
|
-
if (!neoBalance) {
|
|
273
|
-
throw new blockchain_service_1.BSError('NEO balance not found', 'NEO_BALANCE_NOT_FOUND');
|
|
274
|
-
}
|
|
275
|
-
const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(amount);
|
|
276
|
-
const gasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(gasBalance.amount);
|
|
277
|
-
const minGasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE);
|
|
278
|
-
const validatedInputs = {
|
|
279
|
-
receiveAmount: amount,
|
|
280
|
-
token,
|
|
281
|
-
amount,
|
|
282
|
-
};
|
|
283
|
-
if (amountNumber.isLessThan(this.BRIDGE_MIN_AMOUNT)) {
|
|
284
|
-
throw new blockchain_service_1.BSError('Amount is less than the minimum amount', 'AMOUNT_TOO_LOW');
|
|
285
|
-
}
|
|
286
|
-
if (amountNumber.isGreaterThan(neoBalance.amount)) {
|
|
287
|
-
throw new blockchain_service_1.BSError('Amount is greater than your balance', 'INSUFFICIENT_NEO_BALANCE');
|
|
288
|
-
}
|
|
289
|
-
if (gasBalanceNumber.isLessThan(minGasBalanceNumber)) {
|
|
290
|
-
throw new blockchain_service_1.BSError('GAS balance is less than bridge fee', 'INSUFFICIENT_GAS_BALANCE_BRIDGE_FEE');
|
|
291
|
-
}
|
|
292
|
-
const fee = yield this.calculateFee({
|
|
293
|
-
account,
|
|
294
|
-
receiverAddress,
|
|
295
|
-
validatedInputs,
|
|
296
|
-
});
|
|
297
|
-
if (minGasBalanceNumber.plus(fee).isGreaterThan(gasBalanceNumber)) {
|
|
298
|
-
throw new blockchain_service_1.BSError('GAS balance is less than fees', 'INSUFFICIENT_GAS_BALANCE_FEES');
|
|
299
|
-
}
|
|
300
|
-
return validatedInputs;
|
|
301
|
-
});
|
|
302
|
-
};
|
|
210
|
+
_Neo3NeoXBridgeService_service = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo3",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
"/dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@cityofzion/neon-js": "5.
|
|
14
|
-
"@cityofzion/neon-core": "5.
|
|
13
|
+
"@cityofzion/neon-js": "~5.7.0",
|
|
14
|
+
"@cityofzion/neon-core": "~5.7.0",
|
|
15
15
|
"@cityofzion/dora-ts": "0.5.1",
|
|
16
16
|
"axios": "1.8.2",
|
|
17
17
|
"query-string": "7.1.3",
|
|
18
|
-
"@ledgerhq/hw-transport": "~6.
|
|
19
|
-
"@cityofzion/neon-dappkit": "0.
|
|
18
|
+
"@ledgerhq/hw-transport": "~6.31.8",
|
|
19
|
+
"@cityofzion/neon-dappkit": "~0.6.0",
|
|
20
20
|
"bignumber.js": "^9.1.2",
|
|
21
21
|
"isomorphic-ws": "^5.0.0",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
23
|
"date-fns": "~4.1.0",
|
|
24
|
-
"@cityofzion/blockchain-service": "1.19.
|
|
24
|
+
"@cityofzion/blockchain-service": "1.19.3",
|
|
25
25
|
"@cityofzion/bs-asteroid-sdk": "0.9.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@cityofzion/neon-dappkit-types": "~0.
|
|
28
|
+
"@cityofzion/neon-dappkit-types": "~0.5.0",
|
|
29
29
|
"@ledgerhq/hw-transport-node-hid": "~6.28.5",
|
|
30
30
|
"@types/lodash.clonedeep": "^4.5.9",
|
|
31
31
|
"@types/jest": "29.5.3",
|