@cityofzion/bs-multichain 3.1.10 → 3.1.11
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/features/bridge/Neo3NeoXBridgeOrchestrator.js +9 -11
- package/dist/features/swap/SimpleSwapOrchestrator.js +6 -13
- package/dist/features/wallet-connect/WalletKitHelper.d.ts +6 -2
- package/dist/features/wallet-connect/WalletKitHelper.js +16 -6
- package/dist/features/wallet-connect/types.d.ts +5 -0
- package/package.json +9 -9
|
@@ -153,14 +153,14 @@ class Neo3NeoXBridgeOrchestrator {
|
|
|
153
153
|
const constants = await neo3NeoXBridgeService.getBridgeConstants(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
|
|
154
154
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeMinAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
155
155
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeFee }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
156
|
-
const bridgeMaxAmountBn = blockchain_service_1.
|
|
157
|
-
const tokenBalanceAmountBn = blockchain_service_1.
|
|
156
|
+
const bridgeMaxAmountBn = new blockchain_service_1.BSBigHumanAmount(constants.bridgeMaxAmount);
|
|
157
|
+
const tokenBalanceAmountBn = new blockchain_service_1.BSBigHumanAmount(tokenToUseBalance?.amount);
|
|
158
158
|
const isFeeToken = this.fromService.tokenService.predicateByHash(this.fromService.feeToken, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
|
|
159
159
|
const maxTokenBalanceAmountBn = isFeeToken
|
|
160
160
|
? tokenBalanceAmountBn.minus(constants.bridgeFee)
|
|
161
161
|
: tokenBalanceAmountBn;
|
|
162
|
-
const
|
|
163
|
-
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value:
|
|
162
|
+
const amountToUseMax = new blockchain_service_1.BSBigHumanAmount(blockchain_service_1.BSBigNumber.max(0, blockchain_service_1.BSBigNumber.min(bridgeMaxAmountBn, maxTokenBalanceAmountBn)), __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value.decimals).toFormatted();
|
|
163
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: amountToUseMax }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
164
164
|
}
|
|
165
165
|
catch (error) {
|
|
166
166
|
const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
|
|
@@ -187,7 +187,8 @@ class Neo3NeoXBridgeOrchestrator {
|
|
|
187
187
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_amountToUseTimeout, setTimeout(async () => {
|
|
188
188
|
if (!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value)
|
|
189
189
|
return;
|
|
190
|
-
const
|
|
190
|
+
const amountToUseBn = new blockchain_service_1.BSBigHumanAmount(amount, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value.decimals);
|
|
191
|
+
const formattedAmount = amountToUseBn.toFormatted();
|
|
191
192
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_set);
|
|
192
193
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
193
194
|
try {
|
|
@@ -201,7 +202,6 @@ class Neo3NeoXBridgeOrchestrator {
|
|
|
201
202
|
}
|
|
202
203
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
203
204
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
204
|
-
const amountToUseBn = blockchain_service_1.BSBigNumberHelper.fromNumber(formattedAmount);
|
|
205
205
|
if (amountToUseBn.isLessThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_get).value)) {
|
|
206
206
|
throw new blockchain_service_1.BSError('Amount is below the minimum', 'AMOUNT_BELOW_MINIMUM');
|
|
207
207
|
}
|
|
@@ -217,12 +217,10 @@ class Neo3NeoXBridgeOrchestrator {
|
|
|
217
217
|
})
|
|
218
218
|
.then(fee => fee)
|
|
219
219
|
.catch(() => '0');
|
|
220
|
-
const
|
|
221
|
-
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
222
|
-
value: blockchain_service_1.BSBigNumberHelper.format(newBridgeFee, { decimals: this.fromService.feeToken.decimals }),
|
|
223
|
-
}, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
220
|
+
const newBridgeFeeBn = new blockchain_service_1.BSBigHumanAmount(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value, this.fromService.feeToken.decimals).plus(approvalFee);
|
|
221
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: newBridgeFeeBn.toFormatted() }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
224
222
|
const isFeeToken = this.fromService.tokenService.predicateByHash(this.fromService.feeToken, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
|
|
225
|
-
if (
|
|
223
|
+
if (newBridgeFeeBn.plus(isFeeToken ? amountToUseBn : 0).isGreaterThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, "f")?.amount ?? 0)) {
|
|
226
224
|
throw new blockchain_service_1.BSError('You do not have enough fee token balance to cover the bridge fee', 'INSUFFICIENT_FEE_TOKEN_BALANCE');
|
|
227
225
|
}
|
|
228
226
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
@@ -96,9 +96,7 @@ class SimpleSwapOrchestrator {
|
|
|
96
96
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_amountToUseTimeout, setTimeout(() => {
|
|
97
97
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
98
98
|
value: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value
|
|
99
|
-
? blockchain_service_1.
|
|
100
|
-
decimals: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value?.decimals,
|
|
101
|
-
})
|
|
99
|
+
? new blockchain_service_1.BSBigHumanAmount(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value?.decimals).toFormatted()
|
|
102
100
|
: __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_amountToUse_get).value,
|
|
103
101
|
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
104
102
|
__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "m", _SimpleSwapOrchestrator_recalculateValues).call(this, ['amountToReceive']);
|
|
@@ -369,23 +367,18 @@ _SimpleSwapOrchestrator_api = new WeakMap(), _SimpleSwapOrchestrator_blockchainS
|
|
|
369
367
|
const { decimals } = __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value;
|
|
370
368
|
const rangeResponse = await __classPrivateFieldGet(this, _SimpleSwapOrchestrator_api, "f").getRange(__classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToReceive_get).value);
|
|
371
369
|
// Add 1% because the SimpleSwap sends us a smaller minimum than the required
|
|
372
|
-
const
|
|
373
|
-
decimals,
|
|
374
|
-
});
|
|
370
|
+
const minWithOnePercentBn = new blockchain_service_1.BSBigHumanAmount(rangeResponse.min, decimals).multipliedBy(1.01);
|
|
375
371
|
// Add the smallest number to round up correctly because the SimpleSwap doesn't have the decimals, and we need to apply the decimals here
|
|
376
372
|
const smallestNumberToRoundUp = decimals ? `0.${'2'.padStart(decimals, '0')}` : '1';
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}),
|
|
381
|
-
max: rangeResponse.max ? blockchain_service_1.BSBigNumberHelper.format(rangeResponse.max, { decimals }) : rangeResponse.max,
|
|
382
|
-
};
|
|
373
|
+
const min = minWithOnePercentBn.plus(smallestNumberToRoundUp).toFormatted();
|
|
374
|
+
const max = rangeResponse.max ? new blockchain_service_1.BSBigHumanAmount(rangeResponse.max, decimals).toFormatted() : null;
|
|
375
|
+
range = { min, max };
|
|
383
376
|
}
|
|
384
377
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, { value: range }, "a", _SimpleSwapOrchestrator_amountToUseMinMax_set);
|
|
385
378
|
if (shouldRecalculateAmountToUse && range) {
|
|
386
379
|
__classPrivateFieldSet(this, _SimpleSwapOrchestrator_instances, {
|
|
387
380
|
value: range.min
|
|
388
|
-
? blockchain_service_1.
|
|
381
|
+
? new blockchain_service_1.BSBigHumanAmount(range.min, __classPrivateFieldGet(this, _SimpleSwapOrchestrator_instances, "a", _SimpleSwapOrchestrator_tokenToUse_get).value.decimals).toFormatted()
|
|
389
382
|
: range.min,
|
|
390
383
|
}, "a", _SimpleSwapOrchestrator_amountToUse_set);
|
|
391
384
|
}
|
|
@@ -2,7 +2,7 @@ import { type IBlockchainService, type IBSWithWalletConnect, type TBSNetworkId }
|
|
|
2
2
|
import { ErrorResponse } from '@walletconnect/jsonrpc-utils';
|
|
3
3
|
import type { PendingRequestTypes, SessionTypes } from '@walletconnect/types';
|
|
4
4
|
import { SdkErrorKey } from '@walletconnect/utils';
|
|
5
|
-
import type { TWalletKitHelperFilterSessionsParams, TWalletKitHelperGetProposalDetailsParams, TWalletKitHelperGetSessionDetailsParams, TWalletKitHelperProcessRequestParams, TWalletKitHelperProposalDetails, TWalletKitHelperSessionDetails, TWalletKitHelperGetProposalServicesParams } from './types';
|
|
5
|
+
import type { TWalletKitHelperFilterSessionsParams, TWalletKitHelperGetProposalDetailsParams, TWalletKitHelperGetSessionDetailsParams, TWalletKitHelperProcessRequestParams, TWalletKitHelperProposalDetails, TWalletKitHelperSessionDetails, TWalletKitHelperGetProposalServicesParams, TWalletKitHelperValidateRequestParams } from './types';
|
|
6
6
|
export declare class WalletKitHelper {
|
|
7
7
|
static getProposalDetails({ address, proposal, service, }: TWalletKitHelperGetProposalDetailsParams): TWalletKitHelperProposalDetails;
|
|
8
8
|
static getProposalServices({ proposal, services }: TWalletKitHelperGetProposalServicesParams): (IBlockchainService<"ethereum" | "polygon" | "base" | "arbitrum" | "neo3" | "neoLegacy" | "neox" | "solana" | "stellar" | "bitcoin", TBSNetworkId> & IBSWithWalletConnect<"ethereum" | "polygon" | "base" | "arbitrum" | "neo3" | "neoLegacy" | "neox" | "solana" | "stellar" | "bitcoin">)[];
|
|
@@ -13,7 +13,11 @@ export declare class WalletKitHelper {
|
|
|
13
13
|
};
|
|
14
14
|
static formatRequestResult(request: PendingRequestTypes.Struct, response: any): import("@walletconnect/jsonrpc-utils").JsonRpcResult<any>;
|
|
15
15
|
static formatRequestError(request: PendingRequestTypes.Struct, reason: ErrorResponse): import("@walletconnect/jsonrpc-utils").JsonRpcError;
|
|
16
|
-
static
|
|
16
|
+
static validateRequest({ account, sessionDetails, request }: TWalletKitHelperValidateRequestParams): Promise<{
|
|
17
|
+
handler: import("@cityofzion/blockchain-service").TWalletConnectServiceMethodHandler<"ethereum" | "polygon" | "base" | "arbitrum" | "neo3" | "neoLegacy" | "neox" | "solana" | "stellar" | "bitcoin", any>;
|
|
18
|
+
validatedParams: any;
|
|
19
|
+
}>;
|
|
20
|
+
static processRequest({ account, request, sessionDetails }: TWalletKitHelperProcessRequestParams): Promise<any>;
|
|
17
21
|
static filterSessions(sessions: SessionTypes.Struct[], filters: TWalletKitHelperFilterSessionsParams): SessionTypes.Struct[];
|
|
18
22
|
static isValidURI(uri: string): boolean;
|
|
19
23
|
}
|
|
@@ -54,7 +54,7 @@ class WalletKitHelper {
|
|
|
54
54
|
static formatRequestError(request, reason) {
|
|
55
55
|
return (0, jsonrpc_utils_1.formatJsonRpcError)(request.id, reason ?? (0, utils_1.getSdkError)('USER_REJECTED'));
|
|
56
56
|
}
|
|
57
|
-
static async
|
|
57
|
+
static async validateRequest({ account, sessionDetails, request }) {
|
|
58
58
|
if (account.address !== sessionDetails.address) {
|
|
59
59
|
throw new blockchain_service_1.BSError('Account address does not match session address', 'INVALID_ACCOUNT');
|
|
60
60
|
}
|
|
@@ -62,12 +62,22 @@ class WalletKitHelper {
|
|
|
62
62
|
if (!sessionDetails.methods.includes(method)) {
|
|
63
63
|
throw new blockchain_service_1.BSError('Method not supported by session', 'UNSUPPORTED_METHOD');
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const handler = sessionDetails.service.walletConnectService.handlers[method];
|
|
66
|
+
if (!handler)
|
|
67
67
|
throw new blockchain_service_1.BSError('Method not supported', 'UNSUPPORTED_METHOD');
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const validatedParams = await handler.validate(request.params.request.params);
|
|
69
|
+
return {
|
|
70
|
+
handler,
|
|
71
|
+
validatedParams,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
static async processRequest({ account, request, sessionDetails }) {
|
|
75
|
+
const { handler, validatedParams } = await this.validateRequest({ account, request, sessionDetails });
|
|
76
|
+
const response = await handler.process({
|
|
77
|
+
account,
|
|
78
|
+
params: validatedParams,
|
|
79
|
+
method: request.params.request.method,
|
|
80
|
+
});
|
|
71
81
|
return response;
|
|
72
82
|
}
|
|
73
83
|
static filterSessions(sessions, filters) {
|
|
@@ -31,6 +31,11 @@ export type TWalletKitHelperProcessRequestParams = {
|
|
|
31
31
|
sessionDetails: TWalletKitHelperSessionDetails;
|
|
32
32
|
account: TBSAccount<TBSServiceName>;
|
|
33
33
|
};
|
|
34
|
+
export type TWalletKitHelperValidateRequestParams = {
|
|
35
|
+
request: PendingRequestTypes.Struct;
|
|
36
|
+
sessionDetails: TWalletKitHelperSessionDetails;
|
|
37
|
+
account: TBSAccount<TBSServiceName>;
|
|
38
|
+
};
|
|
34
39
|
export type TWalletKitHelperFilterSessionsParams = {
|
|
35
40
|
addresses?: string[];
|
|
36
41
|
chains?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-multichain",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.11",
|
|
4
4
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"author": "Coz",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@walletconnect/utils": "~2.21.9",
|
|
14
14
|
"@walletconnect/jsonrpc-utils": "~1.0.8",
|
|
15
15
|
"axios": "~1.15.0",
|
|
16
|
-
"@cityofzion/blockchain-service": "3.1.
|
|
16
|
+
"@cityofzion/blockchain-service": "3.1.11"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "~24.5.2",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"typed-emitter": "~2.1.0",
|
|
24
24
|
"typescript": "~5.9.2",
|
|
25
25
|
"vitest": "~4.0.18",
|
|
26
|
-
"@cityofzion/bs-bitcoin": "3.1.
|
|
27
|
-
"@cityofzion/bs-ethereum": "3.1.
|
|
28
|
-
"@cityofzion/bs-neo3": "3.1.
|
|
29
|
-
"@cityofzion/bs-neox": "3.1.
|
|
30
|
-
"@cityofzion/bs-solana": "3.1.
|
|
31
|
-
"@cityofzion/bs-neo-legacy": "3.1.
|
|
32
|
-
"@cityofzion/bs-stellar": "3.1.
|
|
26
|
+
"@cityofzion/bs-bitcoin": "3.1.11",
|
|
27
|
+
"@cityofzion/bs-ethereum": "3.1.11",
|
|
28
|
+
"@cityofzion/bs-neo3": "3.1.11",
|
|
29
|
+
"@cityofzion/bs-neox": "3.1.11",
|
|
30
|
+
"@cityofzion/bs-solana": "3.1.11",
|
|
31
|
+
"@cityofzion/bs-neo-legacy": "3.1.11",
|
|
32
|
+
"@cityofzion/bs-stellar": "3.1.11"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "rm -rf ./dist && rm -f *.tgz && npm run typecheck && tsc --project tsconfig.build.json",
|