@cityofzion/bs-neo3 1.7.1 → 1.8.1

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 CHANGED
@@ -1,11 +1,11 @@
1
- import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BSWithSwap, ExchangeDataService, ExplorerService, GetLedgerTransport, Network, NftDataService, SwapService, Token, TransferParam } from '@cityofzion/blockchain-service';
1
+ import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, ExchangeDataService, ExplorerService, GetLedgerTransport, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
2
  import Neon from '@cityofzion/neon-core';
3
3
  import { api } from '@cityofzion/neon-js';
4
4
  import { NeonDappKitLedgerServiceNeo3 } from './services/ledger/NeonDappKitLedgerServiceNeo3';
5
5
  import { BSNeo3NetworkId } from './constants/BSNeo3Constants';
6
- export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSNeo3NetworkId>, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService, BSWithLedger, BSWithSwap<BSNeo3NetworkId> {
6
+ export declare class BSNeo3<BSName extends string = string> implements BlockchainService<BSName, BSNeo3NetworkId>, BSClaimable<BSName>, BSWithNameService, BSCalculableFee<BSName>, BSWithNft, BSWithExplorerService, BSWithLedger<BSName> {
7
7
  #private;
8
- blockchainName: BSCustomName;
8
+ name: BSName;
9
9
  bip44DerivationPath: string;
10
10
  tokens: Token[];
11
11
  feeToken: Token;
@@ -13,29 +13,28 @@ export declare class BSNeo3<BSCustomName extends string = string> implements Blo
13
13
  burnToken: Token;
14
14
  blockchainDataService: BlockchainDataService & BDSClaimable;
15
15
  nftDataService: NftDataService;
16
- ledgerService: NeonDappKitLedgerServiceNeo3;
16
+ ledgerService: NeonDappKitLedgerServiceNeo3<BSName>;
17
17
  exchangeDataService: ExchangeDataService;
18
18
  explorerService: ExplorerService;
19
19
  network: Network<BSNeo3NetworkId>;
20
- constructor(blockchainName: BSCustomName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: GetLedgerTransport);
21
- generateSigningCallback(account: Account, isLedger?: boolean): Promise<{
20
+ constructor(name: BSName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>);
21
+ generateSigningCallback(account: Account<BSName>): Promise<{
22
22
  neonJsAccount: Neon.wallet.Account;
23
23
  signingCallback: api.SigningFunction;
24
24
  }>;
25
- createSwapService(): SwapService<BSNeo3NetworkId>;
26
25
  testNetwork(network: Network<BSNeo3NetworkId>): Promise<void>;
27
26
  setNetwork(network: Network<BSNeo3NetworkId>): void;
28
27
  validateAddress(address: string): boolean;
29
28
  validateEncrypted(encryptedKey: string): boolean;
30
29
  validateKey(key: string): boolean;
31
30
  validateNameServiceDomainFormat(domainName: string): boolean;
32
- generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account;
33
- generateAccountFromPublicKey(publicKey: string): Account;
34
- generateAccountFromKey(key: string): Account;
35
- decrypt(encryptedKey: string, password: string): Promise<Account>;
31
+ generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account<BSName>;
32
+ generateAccountFromPublicKey(publicKey: string): Account<BSName>;
33
+ generateAccountFromKey(key: string): Account<BSName>;
34
+ decrypt(encryptedKey: string, password: string): Promise<Account<BSName>>;
36
35
  encrypt(key: string, password: string): Promise<string>;
37
- calculateTransferFee(param: TransferParam): Promise<string>;
38
- transfer(param: TransferParam): Promise<string[]>;
39
- claim(account: Account, isLedger?: boolean): Promise<string>;
36
+ calculateTransferFee(param: TransferParam<BSName>): Promise<string>;
37
+ transfer(param: TransferParam<BSName>): Promise<string[]>;
38
+ claim(account: Account<BSName>): Promise<string>;
40
39
  resolveNameServiceDomain(domainName: string): Promise<any>;
41
40
  }
package/dist/BSNeo3.js CHANGED
@@ -8,18 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
11
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
12
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
13
  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");
20
14
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
15
  };
22
- var _BSNeo3_instances, _BSNeo3_getLedgerTransport, _BSNeo3_setTokens, _BSNeo3_buildTransferInvocation;
16
+ var _BSNeo3_instances, _BSNeo3_setTokens, _BSNeo3_buildTransferInvocation;
23
17
  Object.defineProperty(exports, "__esModule", { value: true });
24
18
  exports.BSNeo3 = void 0;
25
19
  const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
@@ -31,24 +25,21 @@ const FlamingoEDSNeo3_1 = require("./services/exchange-data/FlamingoEDSNeo3");
31
25
  const DoraESNeo3_1 = require("./services/explorer/DoraESNeo3");
32
26
  const NeonDappKitLedgerServiceNeo3_1 = require("./services/ledger/NeonDappKitLedgerServiceNeo3");
33
27
  const GhostMarketNDSNeo3_1 = require("./services/nft-data/GhostMarketNDSNeo3");
34
- const FlamingoSwapServiceNeo3_1 = require("./services/swap/FlamingoSwapServiceNeo3");
35
28
  const BSNeo3Constants_1 = require("./constants/BSNeo3Constants");
36
29
  const RpcBDSNeo3_1 = require("./services/blockchain-data/RpcBDSNeo3");
37
30
  class BSNeo3 {
38
- constructor(blockchainName, network, getLedgerTransport) {
31
+ constructor(name, network, getLedgerTransport) {
39
32
  _BSNeo3_instances.add(this);
40
- _BSNeo3_getLedgerTransport.set(this, void 0);
41
33
  network = network !== null && network !== void 0 ? network : BSNeo3Constants_1.BSNeo3Constants.DEFAULT_NETWORK;
42
- this.blockchainName = blockchainName;
34
+ this.name = name;
43
35
  this.ledgerService = new NeonDappKitLedgerServiceNeo3_1.NeonDappKitLedgerServiceNeo3(this, getLedgerTransport);
44
- __classPrivateFieldSet(this, _BSNeo3_getLedgerTransport, getLedgerTransport, "f");
45
36
  this.bip44DerivationPath = BSNeo3Constants_1.BSNeo3Constants.DEFAULT_BIP44_DERIVATION_PATH;
46
37
  this.setNetwork(network);
47
38
  }
48
- generateSigningCallback(account, isLedger) {
39
+ generateSigningCallback(account) {
49
40
  return __awaiter(this, void 0, void 0, function* () {
50
41
  const neonJsAccount = new neon_js_1.wallet.Account(account.key);
51
- if (isLedger) {
42
+ if (account.isHardware) {
52
43
  if (!this.ledgerService.getLedgerTransport)
53
44
  throw new Error('You must provide a getLedgerTransport function to use Ledger');
54
45
  if (typeof account.bip44Path !== 'string')
@@ -65,9 +56,6 @@ class BSNeo3 {
65
56
  };
66
57
  });
67
58
  }
68
- createSwapService() {
69
- return new FlamingoSwapServiceNeo3_1.FlamingoSwapServiceNeo3(this.network, this);
70
- }
71
59
  testNetwork(network) {
72
60
  return __awaiter(this, void 0, void 0, function* () {
73
61
  const blockchainDataServiceClone = new RpcBDSNeo3_1.RpcBDSNeo3(network, this.feeToken, this.claimToken, this.tokens);
@@ -100,7 +88,7 @@ class BSNeo3 {
100
88
  const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', bip44Path);
101
89
  const key = childKey.getWIF();
102
90
  const { address } = new neon_js_1.wallet.Account(key);
103
- return { address, key, type: 'wif', bip44Path };
91
+ return { address, key, type: 'wif', bip44Path, blockchain: this.name };
104
92
  }
105
93
  generateAccountFromPublicKey(publicKey) {
106
94
  if (!neon_js_1.wallet.isPublicKey(publicKey))
@@ -110,6 +98,7 @@ class BSNeo3 {
110
98
  address: account.address,
111
99
  key: account.publicKey,
112
100
  type: 'publicKey',
101
+ blockchain: this.name,
113
102
  };
114
103
  }
115
104
  generateAccountFromKey(key) {
@@ -117,7 +106,7 @@ class BSNeo3 {
117
106
  if (!type)
118
107
  throw new Error('Invalid key');
119
108
  const { address } = new neon_js_1.wallet.Account(key);
120
- return { address, key, type };
109
+ return { address, key, type, blockchain: this.name };
121
110
  }
122
111
  decrypt(encryptedKey, password) {
123
112
  return __awaiter(this, void 0, void 0, function* () {
@@ -132,12 +121,12 @@ class BSNeo3 {
132
121
  }
133
122
  calculateTransferFee(param) {
134
123
  return __awaiter(this, void 0, void 0, function* () {
135
- const { neonJsAccount } = yield this.generateSigningCallback(param.senderAccount, param.isLedger);
124
+ const { neonJsAccount } = yield this.generateSigningCallback(param.senderAccount);
136
125
  const invoker = yield neon_dappkit_1.NeonInvoker.init({
137
126
  rpcAddress: this.network.url,
138
127
  account: neonJsAccount,
139
128
  });
140
- const invocations = __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
129
+ const invocations = yield __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
141
130
  const { total } = yield invoker.calculateFee({
142
131
  invocations,
143
132
  signers: [],
@@ -147,13 +136,13 @@ class BSNeo3 {
147
136
  }
148
137
  transfer(param) {
149
138
  return __awaiter(this, void 0, void 0, function* () {
150
- const { neonJsAccount, signingCallback } = yield this.generateSigningCallback(param.senderAccount, param.isLedger);
139
+ const { neonJsAccount, signingCallback } = yield this.generateSigningCallback(param.senderAccount);
151
140
  const invoker = yield neon_dappkit_1.NeonInvoker.init({
152
141
  rpcAddress: this.network.url,
153
142
  account: neonJsAccount,
154
143
  signingCallback: signingCallback,
155
144
  });
156
- const invocations = __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
145
+ const invocations = yield __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
157
146
  const transactionHash = yield invoker.invokeFunction({
158
147
  invocations,
159
148
  signers: [],
@@ -161,9 +150,9 @@ class BSNeo3 {
161
150
  return param.intents.map(() => transactionHash);
162
151
  });
163
152
  }
164
- claim(account, isLedger) {
153
+ claim(account) {
165
154
  return __awaiter(this, void 0, void 0, function* () {
166
- const { neonJsAccount, signingCallback } = yield this.generateSigningCallback(account, isLedger);
155
+ const { neonJsAccount, signingCallback } = yield this.generateSigningCallback(account);
167
156
  const facade = yield neon_js_1.api.NetworkFacade.fromConfig({ node: this.network.url });
168
157
  return yield facade.claimGas(neonJsAccount, {
169
158
  signingCallback: signingCallback,
@@ -195,29 +184,43 @@ class BSNeo3 {
195
184
  }
196
185
  }
197
186
  exports.BSNeo3 = BSNeo3;
198
- _BSNeo3_getLedgerTransport = new WeakMap(), _BSNeo3_instances = new WeakSet(), _BSNeo3_setTokens = function _BSNeo3_setTokens(network) {
187
+ _BSNeo3_instances = new WeakSet(), _BSNeo3_setTokens = function _BSNeo3_setTokens(network) {
199
188
  const tokens = BSNeo3Helper_1.BSNeo3Helper.getTokens(network);
200
189
  this.tokens = tokens;
201
190
  this.feeToken = tokens.find(token => token.symbol === 'GAS');
202
191
  this.burnToken = tokens.find(token => token.symbol === 'NEO');
203
192
  this.claimToken = tokens.find(token => token.symbol === 'GAS');
204
193
  }, _BSNeo3_buildTransferInvocation = function _BSNeo3_buildTransferInvocation({ intents, tipIntent }, account) {
205
- const concatIntents = [...intents, ...(tipIntent ? [tipIntent] : [])];
206
- return concatIntents.map(intent => {
207
- return {
208
- operation: 'transfer',
209
- scriptHash: intent.tokenHash,
210
- args: [
211
- { type: 'Hash160', value: account.address },
212
- { type: 'Hash160', value: intent.receiverAddress },
213
- {
214
- type: 'Integer',
215
- value: intent.tokenDecimals
216
- ? neon_js_1.u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
217
- : intent.amount,
218
- },
219
- { type: 'Any', value: null },
220
- ],
221
- };
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const concatIntents = [...intents, ...(tipIntent ? [tipIntent] : [])];
196
+ const invocations = [];
197
+ for (const intent of concatIntents) {
198
+ let decimals = intent.tokenDecimals;
199
+ if (!decimals) {
200
+ try {
201
+ const token = yield this.blockchainDataService.getTokenInfo(intent.tokenHash);
202
+ decimals = token.decimals;
203
+ }
204
+ catch (error) {
205
+ decimals = 8;
206
+ }
207
+ }
208
+ invocations.push({
209
+ operation: 'transfer',
210
+ scriptHash: intent.tokenHash,
211
+ args: [
212
+ { type: 'Hash160', value: account.address },
213
+ { type: 'Hash160', value: intent.receiverAddress },
214
+ {
215
+ type: 'Integer',
216
+ value: intent.tokenDecimals
217
+ ? neon_js_1.u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
218
+ : intent.amount,
219
+ },
220
+ { type: 'Any', value: null },
221
+ ],
222
+ });
223
+ }
224
+ return invocations;
222
225
  });
223
226
  };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  export * from './BSNeo3';
2
- export * from './builder/invocation/FlamingoSwapInvocationBuilderNeo3';
3
- export * from './builder/invocation/NeonDappKitInvocationBuilderNeo3';
4
2
  export * from './constants/BSNeo3Constants';
5
- export * from './constants/FlamingoSwapConstants';
6
3
  export * from './helpers/BSNeo3Helper';
7
- export * from './helpers/FlamingoSwapHelper';
8
4
  export * from './services/blockchain-data/DoraBDSNeo3';
9
5
  export * from './services/blockchain-data/RpcBDSNeo3';
10
6
  export * from './services/exchange-data/FlamingoEDSNeo3';
@@ -12,4 +8,3 @@ export * from './services/explorer/DoraESNeo3';
12
8
  export * from './services/ledger/NeonDappKitLedgerServiceNeo3';
13
9
  export * from './services/nft-data/GhostMarketNDSNeo3';
14
10
  export * from './services/nft-data/RpcNDSNeo3';
15
- export * from './services/swap/FlamingoSwapServiceNeo3';
package/dist/index.js CHANGED
@@ -15,12 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BSNeo3"), exports);
18
- __exportStar(require("./builder/invocation/FlamingoSwapInvocationBuilderNeo3"), exports);
19
- __exportStar(require("./builder/invocation/NeonDappKitInvocationBuilderNeo3"), exports);
20
18
  __exportStar(require("./constants/BSNeo3Constants"), exports);
21
- __exportStar(require("./constants/FlamingoSwapConstants"), exports);
22
19
  __exportStar(require("./helpers/BSNeo3Helper"), exports);
23
- __exportStar(require("./helpers/FlamingoSwapHelper"), exports);
24
20
  __exportStar(require("./services/blockchain-data/DoraBDSNeo3"), exports);
25
21
  __exportStar(require("./services/blockchain-data/RpcBDSNeo3"), exports);
26
22
  __exportStar(require("./services/exchange-data/FlamingoEDSNeo3"), exports);
@@ -28,4 +24,3 @@ __exportStar(require("./services/explorer/DoraESNeo3"), exports);
28
24
  __exportStar(require("./services/ledger/NeonDappKitLedgerServiceNeo3"), exports);
29
25
  __exportStar(require("./services/nft-data/GhostMarketNDSNeo3"), exports);
30
26
  __exportStar(require("./services/nft-data/RpcNDSNeo3"), exports);
31
- __exportStar(require("./services/swap/FlamingoSwapServiceNeo3"), exports);
@@ -1,13 +1,13 @@
1
- import { Account, LedgerService, LedgerServiceEmitter, GetLedgerTransport } from '@cityofzion/blockchain-service';
1
+ import { Account, GetLedgerTransport, LedgerService, LedgerServiceEmitter } from '@cityofzion/blockchain-service';
2
2
  import { api } from '@cityofzion/neon-js';
3
3
  import Transport from '@ledgerhq/hw-transport';
4
4
  import { BSNeo3 } from '../../BSNeo3';
5
- export declare class NeonDappKitLedgerServiceNeo3 implements LedgerService {
5
+ export declare class NeonDappKitLedgerServiceNeo3<BSName extends string = string> implements LedgerService<BSName> {
6
6
  #private;
7
7
  emitter: LedgerServiceEmitter;
8
- getLedgerTransport?: GetLedgerTransport;
9
- constructor(blockchainService: BSNeo3, getLedgerTransport?: GetLedgerTransport);
10
- getAccount(transport: Transport, index: number): Promise<Account>;
11
- getAccounts(transport: Transport): Promise<Account[]>;
8
+ getLedgerTransport?: GetLedgerTransport<BSName>;
9
+ constructor(blockchainService: BSNeo3<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
10
+ getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
11
+ getAccounts(transport: Transport): Promise<Account<BSName>[]>;
12
12
  getSigningCallback(transport: Transport, account: Account): api.SigningFunction;
13
13
  }
@@ -63,6 +63,8 @@ class NeonDappKitLedgerServiceNeo3 {
63
63
  key: publicKey,
64
64
  type: 'publicKey',
65
65
  bip44Path,
66
+ blockchain: __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f").name,
67
+ isHardware: true,
66
68
  };
67
69
  });
68
70
  }
@@ -71,7 +73,7 @@ class NeonDappKitLedgerServiceNeo3 {
71
73
  const accountsByBlockchainService = yield (0, blockchain_service_1.fetchAccountsForBlockchainServices)([__classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
72
74
  return this.getAccount(transport, index);
73
75
  }));
74
- const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f").blockchainName);
76
+ const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f").name);
75
77
  return accounts !== null && accounts !== void 0 ? accounts : [];
76
78
  });
77
79
  }
@@ -108,8 +110,7 @@ class NeonDappKitLedgerServiceNeo3 {
108
110
  if (response.length <= 2) {
109
111
  throw new Error('Invalid signature returned from Ledger');
110
112
  }
111
- const signature = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_derSignatureToHex).call(this, response.toString('hex'));
112
- return signature;
113
+ return __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_derSignatureToHex).call(this, response.toString('hex'));
113
114
  }
114
115
  finally {
115
116
  this.emitter.emit('getSignatureEnd');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
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.7.0",
23
+ "@cityofzion/blockchain-service": "1.8.0",
24
24
  "@cityofzion/bs-asteroid-sdk": "0.9.0"
25
25
  },
26
26
  "devDependencies": {
@@ -1,7 +0,0 @@
1
- import { SwapServiceSwapToReceiveArgs, SwapServiceSwapToUseArgs } from '@cityofzion/blockchain-service';
2
- import { ContractInvocationMulti } from '@cityofzion/neon-dappkit-types';
3
- import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
4
- export declare class FlamingoSwapInvocationBuilderNeo3 {
5
- #private;
6
- static swapInvocation(data: SwapServiceSwapToReceiveArgs<BSNeo3NetworkId> | SwapServiceSwapToUseArgs<BSNeo3NetworkId>): ContractInvocationMulti;
7
- }
@@ -1,217 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- 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");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _a, _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation, _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation, _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation, _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation, _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation, _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.FlamingoSwapInvocationBuilderNeo3 = void 0;
10
- const neon_core_1 = require("@cityofzion/neon-core");
11
- const FlamingoSwapConstants_1 = require("../../constants/FlamingoSwapConstants");
12
- const FlamingoSwapHelper_1 = require("../../helpers/FlamingoSwapHelper");
13
- const NeonDappKitInvocationBuilderNeo3_1 = require("./NeonDappKitInvocationBuilderNeo3");
14
- class FlamingoSwapInvocationBuilderNeo3 {
15
- static swapInvocation(data) {
16
- const { routePath, network, type } = data;
17
- const [tokenToUse] = routePath;
18
- const tokenToReceive = routePath[routePath.length - 1];
19
- const scriptHashes = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapScriptHashes(network);
20
- const swapParams = {
21
- scriptHashes,
22
- tokenToUse,
23
- tokenToReceive,
24
- };
25
- if (type === 'swapTokenToReceive') {
26
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation).call(this, Object.assign(Object.assign({}, data), swapParams));
27
- }
28
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation).call(this, Object.assign(Object.assign({}, data), swapParams));
29
- }
30
- }
31
- exports.FlamingoSwapInvocationBuilderNeo3 = FlamingoSwapInvocationBuilderNeo3;
32
- _a = FlamingoSwapInvocationBuilderNeo3, _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapTokenToReceiveInvocation(data) {
33
- const { network, routePath } = data;
34
- if (FlamingoSwapHelper_1.FlamingoSwapHelper.isSwapUnwrappingNeo(network, routePath)) {
35
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation).call(this, data);
36
- }
37
- if (FlamingoSwapHelper_1.FlamingoSwapHelper.isUnwrapNeo(network, routePath)) {
38
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation).call(this, data);
39
- }
40
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation).call(this, data);
41
- }, _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapTokenToUseInvocation(data) {
42
- const { network, routePath } = data;
43
- if (FlamingoSwapHelper_1.FlamingoSwapHelper.isSwapWrappingNeo(network, routePath)) {
44
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation).call(this, data);
45
- }
46
- if (FlamingoSwapHelper_1.FlamingoSwapHelper.isWrapNeo(network, routePath)) {
47
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation).call(this, data);
48
- }
49
- return __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation).call(this, data);
50
- }, _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapUnwrappingNeoInvocation(data) {
51
- const { address, amountToReceive, deadline, maximumSelling, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
52
- const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
53
- const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
54
- const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
55
- const maximumSellingFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(maximumSelling, tokenToUse.decimals);
56
- const amountToReceiveTransfer = neon_core_1.u.BigInteger.fromNumber(Number(amountToReceiveFormatted) * FlamingoSwapConstants_1.FlamingoSwapConstants.UNWRAPPING_FEE).toString();
57
- const GAS = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS');
58
- const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
59
- const unwrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
60
- contractHash: GAS.hash,
61
- tokenHash: bNEO.hash,
62
- senderAddress: address,
63
- amount: amountToReceiveTransfer,
64
- });
65
- const unwrapAllowedContracts = [GAS.hash, bNEO.hash];
66
- const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenOutForTokenInContractInvocation({
67
- routerScriptHash: scriptHashes.flamingoSwapRouter,
68
- senderAddress: address,
69
- amountToReceive: amountToReceiveFormatted,
70
- maximumSelling: maximumSellingFormatted,
71
- deadline,
72
- args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
73
- });
74
- const swapAllowedContracts = [
75
- scriptHashes.flamingoSwapRouter,
76
- scriptHashes.flamingoFactory,
77
- scriptHashes.flamingoPairWhiteList,
78
- ];
79
- const allowedContracts = [
80
- ...new Set([...swapAllowedContracts, ...unwrapAllowedContracts, ...routePath.map(token => token.hash)]),
81
- ];
82
- return {
83
- invocations: [swapInvocation, unwrapInvocation],
84
- signers: [
85
- {
86
- scopes: neon_core_1.tx.WitnessScope.CustomContracts,
87
- allowedContracts,
88
- },
89
- ],
90
- };
91
- }, _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_unwrapNeoInvocation(data) {
92
- const { address, amountToReceive, network, tokenToReceive } = data;
93
- const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
94
- const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
95
- const GAS = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'GAS');
96
- const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
97
- const unwrappedAmount = FlamingoSwapHelper_1.FlamingoSwapHelper.getUnwrappedAmount(amountToReceiveFormatted);
98
- const unwrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
99
- contractHash: GAS.hash,
100
- tokenHash: bNEO.hash,
101
- senderAddress: address,
102
- amount: unwrappedAmount,
103
- });
104
- const unwrapAllowedContracts = [GAS.hash, bNEO.hash];
105
- return {
106
- invocations: [unwrapInvocation],
107
- signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts: unwrapAllowedContracts }],
108
- };
109
- }, _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapReceiveInvocation(data) {
110
- const { address, amountToReceive, deadline, maximumSelling, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
111
- const tokenToReceiveOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToReceive);
112
- const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
113
- const amountToReceiveFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToReceive, tokenToReceiveOverrode.decimals);
114
- const maximumSellingFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(maximumSelling, tokenToUse.decimals);
115
- const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenOutForTokenInContractInvocation({
116
- routerScriptHash: scriptHashes.flamingoSwapRouter,
117
- senderAddress: address,
118
- amountToReceive: amountToReceiveFormatted,
119
- maximumSelling: maximumSellingFormatted,
120
- deadline,
121
- args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
122
- });
123
- const swapAllowedContracts = [
124
- scriptHashes.flamingoSwapRouter,
125
- scriptHashes.flamingoFactory,
126
- scriptHashes.flamingoPairWhiteList,
127
- ];
128
- const allowedContracts = [...new Set([...swapAllowedContracts, ...routePath.map(token => token.hash)])];
129
- return {
130
- invocations: [swapInvocation],
131
- signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts }],
132
- };
133
- }, _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapWrappingNeoInvocation(data) {
134
- const { address, amountToUse, network, deadline, minimumReceived, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
135
- const tokenToUseOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
136
- const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
137
- const amountToUseFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToUse, tokenToUseOverrode.decimals);
138
- const minimumReceivedFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(minimumReceived, tokenToReceive.decimals);
139
- const NEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO');
140
- const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
141
- const wrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
142
- contractHash: NEO.hash,
143
- tokenHash: bNEO.hash,
144
- senderAddress: address,
145
- amount: amountToUse,
146
- });
147
- const wrapAllowedContracts = [NEO.hash, bNEO.hash];
148
- const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenInForTokenOutContractInvocation({
149
- routerScriptHash: scriptHashes.flamingoSwapRouter,
150
- amountToUse: amountToUseFormatted,
151
- minimumReceived: minimumReceivedFormatted,
152
- senderAddress: address,
153
- deadline,
154
- args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
155
- });
156
- const swapAllowedContracts = [
157
- scriptHashes.flamingoSwapRouter,
158
- scriptHashes.flamingoFactory,
159
- scriptHashes.flamingoPairWhiteList,
160
- ];
161
- const allowedContracts = [
162
- ...new Set([...swapAllowedContracts, ...wrapAllowedContracts, ...routePath.map(token => token.hash)]),
163
- ];
164
- return {
165
- invocations: [wrapInvocation, swapInvocation],
166
- signers: [
167
- {
168
- scopes: neon_core_1.tx.WitnessScope.CustomContracts,
169
- allowedContracts,
170
- },
171
- ],
172
- };
173
- }, _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation = function _FlamingoSwapInvocationBuilderNeo3_wrapNeoInvocation(data) {
174
- const { address, amountToUse, network } = data;
175
- const NEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO');
176
- const bNEO = FlamingoSwapHelper_1.FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO');
177
- const wrapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.transferContractInvocation({
178
- contractHash: NEO.hash,
179
- tokenHash: bNEO.hash,
180
- senderAddress: address,
181
- amount: amountToUse,
182
- });
183
- const wrapAllowedContracts = [NEO.hash, bNEO.hash];
184
- return {
185
- invocations: [wrapInvocation],
186
- signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts: wrapAllowedContracts }],
187
- };
188
- }, _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation = function _FlamingoSwapInvocationBuilderNeo3_swapToUseInvocation(data) {
189
- const { address, amountToUse, deadline, minimumReceived, network, routePath, scriptHashes, tokenToReceive, tokenToUse, } = data;
190
- const tokenToUseOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideToken(network, tokenToUse);
191
- const routePathOverrode = FlamingoSwapHelper_1.FlamingoSwapHelper.overrideRoutePath(network, routePath);
192
- const amountToUseFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(amountToUse, tokenToUseOverrode.decimals);
193
- const minimumReceivedFormatted = FlamingoSwapHelper_1.FlamingoSwapHelper.formatAmount(minimumReceived, tokenToReceive.decimals);
194
- const swapInvocation = NeonDappKitInvocationBuilderNeo3_1.NeonDappKitInvocationBuilderNeo3.swapTokenInForTokenOutContractInvocation({
195
- routerScriptHash: scriptHashes.flamingoSwapRouter,
196
- amountToUse: amountToUseFormatted,
197
- minimumReceived: minimumReceivedFormatted,
198
- senderAddress: address,
199
- deadline,
200
- args: __classPrivateFieldGet(this, _a, "m", _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs).call(this, routePathOverrode),
201
- });
202
- const swapAllowedContracts = [
203
- scriptHashes.flamingoSwapRouter,
204
- scriptHashes.flamingoFactory,
205
- scriptHashes.flamingoPairWhiteList,
206
- ];
207
- const allowedContracts = [...new Set([...swapAllowedContracts, ...routePath.map(token => token.hash)])];
208
- return {
209
- invocations: [swapInvocation],
210
- signers: [{ scopes: neon_core_1.tx.WitnessScope.CustomContracts, allowedContracts }],
211
- };
212
- }, _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs = function _FlamingoSwapInvocationBuilderNeo3_mapRoutePathToArgs(routePath) {
213
- return routePath.map(token => ({
214
- type: 'Hash160',
215
- value: token.hash,
216
- }));
217
- };
@@ -1,36 +0,0 @@
1
- import { Token } from '@cityofzion/blockchain-service';
2
- import BigNumber from 'bignumber.js';
3
- import { BSNeo3NetworkId } from './BSNeo3Constants';
4
- export type FlamingoSwapScriptHashes = {
5
- flamingoSwapRouter: string;
6
- flamingoPairWhiteList: string;
7
- flamingoFactory: string;
8
- };
9
- export type FlamingoSwapPoolInfo = {
10
- symbol: string;
11
- decimals: number;
12
- hash: string;
13
- tokens: Token[];
14
- };
15
- export type FlamingoSwapPools = {
16
- [key: string]: FlamingoSwapPoolInfo;
17
- };
18
- export type FlamingoSwapTokens = {
19
- [key: string]: Token;
20
- };
21
- export declare const BLOCKCHAIN_WSS_URL = "wss://rpc10.n3.nspcc.ru:10331/ws";
22
- export declare class FlamingoSwapConstants {
23
- static readonly BN_0: BigNumber;
24
- static readonly BN_1: BigNumber;
25
- static readonly BN_997: BigNumber;
26
- static readonly BN_1000: BigNumber;
27
- static readonly FEE_RATE: BigNumber;
28
- static readonly UNWRAPPING_FEE = 0.001;
29
- static readonly TESTNET_FLAMINGO_SWAP_TOKENS: FlamingoSwapTokens;
30
- static readonly MAINNET_FLAMINGO_SWAP_TOKENS: FlamingoSwapTokens;
31
- static readonly FLAMINGO_SWAP_TOKENS: Record<BSNeo3NetworkId, FlamingoSwapTokens>;
32
- static readonly FLAMINGO_SWAP_SCRIPT_HASHES: Partial<Record<BSNeo3NetworkId, FlamingoSwapScriptHashes>>;
33
- static readonly TESTNET_FLAMINGO_SWAP_POOLS: FlamingoSwapPools;
34
- static readonly MAINNET_FLAMINGO_SWAP_POOLS: FlamingoSwapPools;
35
- static readonly FLAMINGO_SWAP_POOLS: Record<BSNeo3NetworkId, FlamingoSwapPools>;
36
- }