@cityofzion/bs-neo3 1.3.1 → 1.3.3
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/BSNeo3.d.ts +3 -2
- package/dist/BSNeo3.js +4 -0
- package/dist/builder/invocation/FlamingoSwapInvocationBuilderNeo3.js +21 -13
- package/dist/helpers/FlamingoSwapHelper.d.ts +2 -0
- package/dist/helpers/FlamingoSwapHelper.js +8 -0
- package/dist/services/swap/FlamingoSwapServiceNeo3.d.ts +1 -2
- package/dist/services/swap/FlamingoSwapServiceNeo3.js +6 -4
- package/package.json +2 -2
package/dist/BSNeo3.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Account, AccountWithDerivationPath, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, ExchangeDataService, ExplorerService, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
|
|
1
|
+
import { Account, AccountWithDerivationPath, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BSWithSwap, ExchangeDataService, ExplorerService, Network, NftDataService, SwapService, Token, TransferParam } from '@cityofzion/blockchain-service';
|
|
2
2
|
import Transport from '@ledgerhq/hw-transport';
|
|
3
3
|
import { BSNeo3NetworkId } from './helpers/BSNeo3Helper';
|
|
4
4
|
import { NeonDappKitLedgerServiceNeo3 } from './services/ledger/NeonDappKitLedgerServiceNeo3';
|
|
5
|
-
export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSNeo3NetworkId>, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService, BSWithLedger {
|
|
5
|
+
export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSNeo3NetworkId>, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService, BSWithLedger, BSWithSwap<BSNeo3NetworkId> {
|
|
6
6
|
#private;
|
|
7
7
|
blockchainName: BSCustomName;
|
|
8
8
|
derivationPath: string;
|
|
@@ -17,6 +17,7 @@ export declare class BSNeo3<BSCustomName extends string = string> implements Blo
|
|
|
17
17
|
explorerService: ExplorerService;
|
|
18
18
|
network: Network<BSNeo3NetworkId>;
|
|
19
19
|
constructor(blockchainName: BSCustomName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: (account: Account) => Promise<Transport>);
|
|
20
|
+
createSwapService(): SwapService<BSNeo3NetworkId>;
|
|
20
21
|
setNetwork(network: Network<BSNeo3NetworkId>): void;
|
|
21
22
|
validateAddress(address: string): boolean;
|
|
22
23
|
validateEncrypted(encryptedKey: string): boolean;
|
package/dist/BSNeo3.js
CHANGED
|
@@ -25,6 +25,7 @@ const FlamingoEDSNeo3_1 = require("./services/exchange-data/FlamingoEDSNeo3");
|
|
|
25
25
|
const DoraESNeo3_1 = require("./services/explorer/DoraESNeo3");
|
|
26
26
|
const NeonDappKitLedgerServiceNeo3_1 = require("./services/ledger/NeonDappKitLedgerServiceNeo3");
|
|
27
27
|
const GhostMarketNDSNeo3_1 = require("./services/nft-data/GhostMarketNDSNeo3");
|
|
28
|
+
const FlamingoSwapServiceNeo3_1 = require("./services/swap/FlamingoSwapServiceNeo3");
|
|
28
29
|
class BSNeo3 {
|
|
29
30
|
constructor(blockchainName, network, getLedgerTransport) {
|
|
30
31
|
_BSNeo3_instances.add(this);
|
|
@@ -34,6 +35,9 @@ class BSNeo3 {
|
|
|
34
35
|
this.derivationPath = BSNeo3Helper_1.BSNeo3Helper.DERIVATION_PATH;
|
|
35
36
|
this.setNetwork(network);
|
|
36
37
|
}
|
|
38
|
+
createSwapService() {
|
|
39
|
+
return new FlamingoSwapServiceNeo3_1.FlamingoSwapServiceNeo3(this.network, this.ledgerService);
|
|
40
|
+
}
|
|
37
41
|
setNetwork(network) {
|
|
38
42
|
__classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_setTokens).call(this, network);
|
|
39
43
|
this.network = network;
|
|
@@ -23,9 +23,10 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
23
23
|
const [tokenToUse] = routePath;
|
|
24
24
|
const tokenToReceive = routePath[routePath.length - 1];
|
|
25
25
|
const scriptHashes = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapScriptHashes(network);
|
|
26
|
-
const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
27
26
|
const invocations = [];
|
|
28
|
-
const allowedContracts =
|
|
27
|
+
const allowedContracts = [];
|
|
28
|
+
const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
|
|
29
|
+
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
29
30
|
const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
|
|
30
31
|
const maximumSellingFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(maximumSelling, tokenToUse.decimals);
|
|
31
32
|
const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenOutForTokenInContractInvocation({
|
|
@@ -34,13 +35,16 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
34
35
|
amountToReceive: amountToReceiveFormatted,
|
|
35
36
|
maximumSelling: maximumSellingFormatted,
|
|
36
37
|
deadline,
|
|
37
|
-
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this,
|
|
38
|
+
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
38
39
|
});
|
|
39
40
|
invocations.push(swapInvocation);
|
|
41
|
+
allowedContracts.push(...__classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_getAllowedContracts).call(this, scriptHashes, routePath));
|
|
40
42
|
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isNeoToken(network, tokenToReceive)) {
|
|
41
43
|
const amountToReceiveTransfer = neon_core_1.u.BigInteger.fromNumber(Number(amountToReceiveFormatted) * FlamingoSwapConstants_1.FlamingoSwapConstants.GAS_PER_NEO).toString();
|
|
42
|
-
const
|
|
44
|
+
const gasHash = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS').hash;
|
|
45
|
+
const neoTransferInvocation = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation).call(this, address, gasHash, amountToReceiveTransfer, network);
|
|
43
46
|
invocations.push(neoTransferInvocation);
|
|
47
|
+
allowedContracts.push(FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapPool(network, 'FLP-bNEO-GAS').hash);
|
|
44
48
|
}
|
|
45
49
|
return {
|
|
46
50
|
invocations,
|
|
@@ -51,12 +55,16 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
51
55
|
const tokenToReceive = routePath[routePath.length - 1];
|
|
52
56
|
const scriptHashes = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapScriptHashes(network);
|
|
53
57
|
const invocations = [];
|
|
54
|
-
const allowedContracts =
|
|
58
|
+
const allowedContracts = [];
|
|
55
59
|
if (FlamingoSwapHelper_1.FlamingoSwapHelper.isNeoToken(network, tokenToUse)) {
|
|
56
|
-
const
|
|
60
|
+
const neoHash = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO').hash;
|
|
61
|
+
const neoTransferInvocation = __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation).call(this, address, neoHash, amountToUse, network);
|
|
57
62
|
invocations.push(neoTransferInvocation);
|
|
63
|
+
allowedContracts.push(FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapPool(network, 'FLP-bNEO-GAS').hash);
|
|
58
64
|
}
|
|
59
|
-
const
|
|
65
|
+
const tokenToUseOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
|
|
66
|
+
const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
|
|
67
|
+
const amountToUseFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToUse, tokenToUseOverrode.decimals);
|
|
60
68
|
const minimumReceivedFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(minimumReceived, tokenToReceive.decimals);
|
|
61
69
|
const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenInForTokenOutContractInvocation({
|
|
62
70
|
routerScriptHash: scriptHashes.flamingoSwapRouter,
|
|
@@ -64,9 +72,10 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
64
72
|
minimumReceived: minimumReceivedFormatted,
|
|
65
73
|
senderAddress: address,
|
|
66
74
|
deadline,
|
|
67
|
-
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this,
|
|
75
|
+
args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
|
|
68
76
|
});
|
|
69
77
|
invocations.push(swapInvocation);
|
|
78
|
+
allowedContracts.push(...__classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_getAllowedContracts).call(this, scriptHashes, routePath));
|
|
70
79
|
return {
|
|
71
80
|
invocations,
|
|
72
81
|
signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts }],
|
|
@@ -83,13 +92,12 @@ _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_build
|
|
|
83
92
|
scriptHashes.flamingoPairWhiteList,
|
|
84
93
|
...routePath.map(token => token.hash),
|
|
85
94
|
];
|
|
86
|
-
}, _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation = function _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation(
|
|
95
|
+
}, _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation = function _FlamingoSwapInvocationBuilderNeo3_buildNEOTransferInvocation(senderAddress, contractHash, amount, network) {
|
|
87
96
|
const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
|
|
88
|
-
const GAS = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS');
|
|
89
97
|
return NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
|
|
90
|
-
|
|
91
|
-
amount,
|
|
98
|
+
contractHash,
|
|
92
99
|
tokenHash: bNEO.hash,
|
|
93
|
-
|
|
100
|
+
senderAddress,
|
|
101
|
+
amount,
|
|
94
102
|
});
|
|
95
103
|
};
|
|
@@ -3,6 +3,7 @@ import BigNumber from 'bignumber.js';
|
|
|
3
3
|
import { FlamingoSwapPoolInfo, FlamingoSwapPools, FlamingoSwapScriptHashes, FlamingoSwapTokens } from '../constants/FlamingoSwapConstants';
|
|
4
4
|
import { BSNeo3NetworkId } from './BSNeo3Helper';
|
|
5
5
|
export declare class FlamingoSwapHelper {
|
|
6
|
+
static listSwappableTokensSymbol(network: Network<BSNeo3NetworkId>): string[];
|
|
6
7
|
static getFlamingoSwapPools(network: Network<BSNeo3NetworkId>): FlamingoSwapPools;
|
|
7
8
|
static getFlamingoSwapPool(network: Network<BSNeo3NetworkId>, name: string): FlamingoSwapPoolInfo;
|
|
8
9
|
static getFlamingoSwapTokens(network: Network<BSNeo3NetworkId>): FlamingoSwapTokens;
|
|
@@ -13,6 +14,7 @@ export declare class FlamingoSwapHelper {
|
|
|
13
14
|
static overrideAmountInput(network: Network<BSNeo3NetworkId>, amount: string, token: Token): BigNumber;
|
|
14
15
|
static overrideAmountToDisplay(network: Network<BSNeo3NetworkId>, amount: string, token: Token): string;
|
|
15
16
|
static overrideRoute(network: Network<BSNeo3NetworkId>, route: SwapRoute[]): SwapRoute[];
|
|
17
|
+
static overrideRoutePath(network: Network<BSNeo3NetworkId>, routePath: Token[]): Token[];
|
|
16
18
|
static normalizeHash(hash: string): string;
|
|
17
19
|
static isNeoToken(network: Network<BSNeo3NetworkId>, token: Token): boolean;
|
|
18
20
|
static formatAmount(amount: string, decimals: number): string;
|
|
@@ -7,7 +7,11 @@ exports.FlamingoSwapHelper = void 0;
|
|
|
7
7
|
const neon_core_1 = require("@cityofzion/neon-core");
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const FlamingoSwapConstants_1 = require("../constants/FlamingoSwapConstants");
|
|
10
|
+
const handlers_1 = require("../services/swap/handlers");
|
|
10
11
|
class FlamingoSwapHelper {
|
|
12
|
+
static listSwappableTokensSymbol(network) {
|
|
13
|
+
return Object.keys(handlers_1.FlamingoSwapRouteHandler.createPoolGraph(network));
|
|
14
|
+
}
|
|
11
15
|
static getFlamingoSwapPools(network) {
|
|
12
16
|
const pools = FlamingoSwapConstants_1.FlamingoSwapConstants.FLAMINGO_SWAP_POOLS[network.id];
|
|
13
17
|
if (!pools) {
|
|
@@ -70,6 +74,10 @@ class FlamingoSwapHelper {
|
|
|
70
74
|
}
|
|
71
75
|
return overrodeRoute;
|
|
72
76
|
}
|
|
77
|
+
static overrideRoutePath(network, routePath) {
|
|
78
|
+
const overrodeRoutePath = routePath.map(token => this.overrideToken(network, token));
|
|
79
|
+
return overrodeRoutePath.filter((item, index, arr) => arr.indexOf(item) === index);
|
|
80
|
+
}
|
|
73
81
|
static normalizeHash(hash) {
|
|
74
82
|
return hash.startsWith('0x') ? hash.slice(2) : hash;
|
|
75
83
|
}
|
|
@@ -6,9 +6,8 @@ type BuildSwapInvocationArgs = SwapServiceSwapToUseArgs<BSNeo3NetworkId> | SwapS
|
|
|
6
6
|
export declare class FlamingoSwapServiceNeo3 implements SwapService<BSNeo3NetworkId> {
|
|
7
7
|
#private;
|
|
8
8
|
eventEmitter: TypedEmitter<SwapServiceEvents>;
|
|
9
|
-
constructor(network: Network<BSNeo3NetworkId>, ledgerService
|
|
9
|
+
constructor(network: Network<BSNeo3NetworkId>, ledgerService?: NeonDappKitLedgerServiceNeo3);
|
|
10
10
|
buildSwapInvocationArgs(): BuildSwapInvocationArgs;
|
|
11
|
-
listSwappableTokensSymbol(network: Network<BSNeo3NetworkId>): string[];
|
|
12
11
|
swap(isLedger?: boolean): Promise<void>;
|
|
13
12
|
startListeningBlockGeneration(): void;
|
|
14
13
|
stopListeningBlockGeneration(): void;
|
|
@@ -81,24 +81,26 @@ class FlamingoSwapServiceNeo3 {
|
|
|
81
81
|
throw new Error("minimumReceived is required for 'amountToUse' swap type");
|
|
82
82
|
return Object.assign(Object.assign({}, baseSwapArgs), { amountToUse: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_amountToUse_get), minimumReceived: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_minimumReceived_get), type: 'swapTokenToUse' });
|
|
83
83
|
}
|
|
84
|
-
listSwappableTokensSymbol(network) {
|
|
85
|
-
return Object.keys(handlers_1.FlamingoSwapRouteHandler.createPoolGraph(network));
|
|
86
|
-
}
|
|
87
84
|
swap(isLedger) {
|
|
88
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
86
|
const swapInvocationArgs = this.buildSwapInvocationArgs();
|
|
90
87
|
let ledgerTransport;
|
|
88
|
+
let signingCallback;
|
|
91
89
|
if (isLedger) {
|
|
90
|
+
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f")) {
|
|
91
|
+
throw new Error('You must provide a ledger service to use Ledger');
|
|
92
|
+
}
|
|
92
93
|
if (!__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getLedgerTransport) {
|
|
93
94
|
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
94
95
|
}
|
|
95
96
|
ledgerTransport = yield __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getLedgerTransport(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get));
|
|
97
|
+
signingCallback = __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_ledgerService, "f").getSigningCallback(ledgerTransport);
|
|
96
98
|
}
|
|
97
99
|
const account = new neon_core_1.wallet.Account(__classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_instances, "a", _FlamingoSwapServiceNeo3_accountToUse_get).key);
|
|
98
100
|
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
99
101
|
rpcAddress: __classPrivateFieldGet(this, _FlamingoSwapServiceNeo3_network, "f").url,
|
|
100
102
|
account,
|
|
101
|
-
signingCallback
|
|
103
|
+
signingCallback,
|
|
102
104
|
});
|
|
103
105
|
yield invoker.invokeFunction(FlamingoSwapInvocationBuilderNeo3_1.FlamingoSwapInvocationBuilderNeo3.swapInvocation(swapInvocationArgs));
|
|
104
106
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo3",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"bignumber.js": "^9.1.2",
|
|
21
21
|
"isomorphic-ws": "^5.0.0",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
|
-
"@cityofzion/blockchain-service": "1.3.
|
|
23
|
+
"@cityofzion/blockchain-service": "1.3.2",
|
|
24
24
|
"@cityofzion/bs-asteroid-sdk": "0.9.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|