carbon-js-sdk 0.11.71 → 0.11.72
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/package.json +2 -2
- package/lib/clients/N3Client.d.ts +0 -73
- package/lib/clients/N3Client.js +0 -285
- package/lib/clients/NEOClient.d.ts +0 -57
- package/lib/clients/NEOClient.js +0 -337
- package/lib/clients/ZILClient.d.ts +0 -106
- package/lib/clients/ZILClient.js +0 -437
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/BIP44.d.ts +0 -5
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/BIP44.js +0 -26
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.d.ts +0 -40
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +0 -62
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/index.d.ts +0 -3
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/index.js +0 -21
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.d.ts +0 -42
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +0 -181
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.d.ts +0 -24
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +0 -150
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.d.ts +0 -59
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +0 -180
- package/lib/provider/account/NeoLedgerAccount/index.d.ts +0 -1
- package/lib/provider/account/NeoLedgerAccount/index.js +0 -17
- package/lib/provider/account/index.d.ts +0 -1
- package/lib/provider/account/index.js +0 -17
- package/lib/provider/o3/O3Types.d.ts +0 -84
- package/lib/provider/o3/O3Types.js +0 -41
- package/lib/provider/o3/O3Wallet.d.ts +0 -29
- package/lib/provider/o3/O3Wallet.js +0 -242
- package/lib/provider/o3/index.d.ts +0 -2
- package/lib/provider/o3/index.js +0 -32
- package/lib/provider/zilpay/Zilpay.d.ts +0 -33
- package/lib/provider/zilpay/Zilpay.js +0 -82
- package/lib/provider/zilpay/index.d.ts +0 -1
- package/lib/provider/zilpay/index.js +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-js-sdk",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.72",
|
|
4
4
|
"description": "TypeScript SDK for Carbon blockchain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test": "tsc && node lib/test.js",
|
|
18
18
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
19
19
|
"lint": "eslint . --ext .ts",
|
|
20
|
-
"prepare": "yarn run build",
|
|
20
|
+
"prepare": "rm -rf ./lib && yarn run build",
|
|
21
21
|
"prepublishOnly": "yarn run lint",
|
|
22
22
|
"preversion": "yarn run lint",
|
|
23
23
|
"version": "yarn run format && git add -A src",
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import CarbonSDK from "../CarbonSDK";
|
|
2
|
-
import { NetworkConfigProvider } from "../constant";
|
|
3
|
-
import { NeoLedgerAccount } from "../provider/account";
|
|
4
|
-
import { O3Wallet } from "../provider/o3";
|
|
5
|
-
import { Blockchain } from "../util/blockchain";
|
|
6
|
-
import { TokensWithExternalBalance } from "../util/external";
|
|
7
|
-
import { SimpleMap } from "../util/type";
|
|
8
|
-
import { tx, u } from "@cityofzion/neon-core-next";
|
|
9
|
-
import BigNumber from "bignumber.js";
|
|
10
|
-
export interface N3ClientOpts {
|
|
11
|
-
configProvider: NetworkConfigProvider;
|
|
12
|
-
blockchain?: Blockchain;
|
|
13
|
-
}
|
|
14
|
-
export interface LockLedgerDepositParams {
|
|
15
|
-
token: TokensWithExternalBalance;
|
|
16
|
-
toAddressHex: string;
|
|
17
|
-
feeAmount: BigNumber;
|
|
18
|
-
amount: BigNumber;
|
|
19
|
-
signCompleteCallback?: () => void;
|
|
20
|
-
ledger: NeoLedgerAccount;
|
|
21
|
-
}
|
|
22
|
-
export interface LockO3DepositParams {
|
|
23
|
-
token: TokensWithExternalBalance;
|
|
24
|
-
toAddressHex: string;
|
|
25
|
-
feeAmount: BigNumber;
|
|
26
|
-
amount: BigNumber;
|
|
27
|
-
signCompleteCallback?: () => void;
|
|
28
|
-
o3Wallet: O3Wallet;
|
|
29
|
-
}
|
|
30
|
-
export interface NeoDapiInvokeArgs {
|
|
31
|
-
scriptHash: string;
|
|
32
|
-
args?: any[];
|
|
33
|
-
operation: string;
|
|
34
|
-
fee?: string;
|
|
35
|
-
signers: any[];
|
|
36
|
-
}
|
|
37
|
-
export interface NeoDapiInvokeOutput {
|
|
38
|
-
txid: string;
|
|
39
|
-
nodeUrl: string;
|
|
40
|
-
}
|
|
41
|
-
export interface N3Signer {
|
|
42
|
-
scriptHash: string;
|
|
43
|
-
sign: (txn: tx.Transaction, networkMagic?: number, k?: string | number) => Promise<tx.Transaction>;
|
|
44
|
-
}
|
|
45
|
-
export declare class N3Client {
|
|
46
|
-
readonly configProvider: NetworkConfigProvider;
|
|
47
|
-
readonly blockchain: Blockchain;
|
|
48
|
-
static SUPPORTED_BLOCKCHAINS: Blockchain[];
|
|
49
|
-
static BLOCKCHAIN_KEY: {
|
|
50
|
-
neo3: string;
|
|
51
|
-
};
|
|
52
|
-
private rpcClient;
|
|
53
|
-
private constructor();
|
|
54
|
-
static signerFromPrivateKey(privateKey: string): N3Signer;
|
|
55
|
-
static signerFromLedger(ledger: NeoLedgerAccount): N3Signer;
|
|
56
|
-
static instance(opts: N3ClientOpts): N3Client;
|
|
57
|
-
getExternalBalances(sdk: CarbonSDK, address: string, whitelistDenoms?: string[]): Promise<TokensWithExternalBalance[]>;
|
|
58
|
-
getAllN3Balances(address: string): Promise<SimpleMap<string>>;
|
|
59
|
-
lock(lockProxyScriptHash: string, tokenScriptHash: string, fromAddressHex: string, toAddressHex: string, amount: BigNumber, feeAmount: BigNumber, signer: N3Signer): Promise<string | false>;
|
|
60
|
-
lockDeposit(token: TokensWithExternalBalance, feeAmountInput: string, swthAddress: string, neoPrivateKey: string): Promise<string | false>;
|
|
61
|
-
lockO3Deposit(params: LockO3DepositParams): Promise<string>;
|
|
62
|
-
lockLedgerDeposit(params: LockLedgerDepositParams): Promise<string | false>;
|
|
63
|
-
getNetworkFee(txn: tx.Transaction, networkFee: number): Promise<u.BigInteger>;
|
|
64
|
-
getSystemFee(txn: tx.Transaction, systemFee: number, signers?: (tx.Signer | tx.SignerJson)[]): Promise<u.BigInteger>;
|
|
65
|
-
formatWithdrawalAddress(address: string): string;
|
|
66
|
-
retrieveNEP17Info(address: string): Promise<{
|
|
67
|
-
name: string;
|
|
68
|
-
symbol: string;
|
|
69
|
-
address: string;
|
|
70
|
-
decimals: number;
|
|
71
|
-
}>;
|
|
72
|
-
}
|
|
73
|
-
export default N3Client;
|
package/lib/clients/N3Client.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.N3Client = void 0;
|
|
16
|
-
const o3_1 = require("../provider/o3");
|
|
17
|
-
const address_1 = require("../util/address");
|
|
18
|
-
const blockchain_1 = require("../util/blockchain");
|
|
19
|
-
const neon_core_next_1 = require("@cityofzion/neon-core-next");
|
|
20
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
21
|
-
class N3Client {
|
|
22
|
-
constructor(configProvider, blockchain) {
|
|
23
|
-
var _a;
|
|
24
|
-
this.configProvider = configProvider;
|
|
25
|
-
this.blockchain = blockchain;
|
|
26
|
-
const config = configProvider.getConfig();
|
|
27
|
-
const isValidNeoRpcUrl = ((_a = config.n3.rpcURL) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
28
|
-
this.rpcClient = isValidNeoRpcUrl ? new neon_core_next_1.rpc.RPCClient(config.n3.rpcURL) : null;
|
|
29
|
-
}
|
|
30
|
-
static signerFromPrivateKey(privateKey) {
|
|
31
|
-
const account = new neon_core_next_1.wallet.Account(privateKey);
|
|
32
|
-
return {
|
|
33
|
-
scriptHash: account.scriptHash,
|
|
34
|
-
sign: (txn, networkMagic = neon_core_next_1.CONST.MAGIC_NUMBER.MainNet, k) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
yield txn.sign(account, networkMagic, k);
|
|
36
|
-
return txn;
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
static signerFromLedger(ledger) {
|
|
41
|
-
return {
|
|
42
|
-
scriptHash: ledger.scriptHash,
|
|
43
|
-
sign: (txn, networkMagic = neon_core_next_1.CONST.MAGIC_NUMBER.MainNet) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const signature = yield ledger.sign(txn.serialize(false), networkMagic);
|
|
45
|
-
const encodedPublicKey = neon_core_next_1.wallet.getPublicKeyEncoded(ledger.publicKey);
|
|
46
|
-
txn.addWitness(neon_core_next_1.tx.Witness.fromSignature(signature, encodedPublicKey));
|
|
47
|
-
return txn;
|
|
48
|
-
}),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
static instance(opts) {
|
|
52
|
-
const { configProvider, blockchain = blockchain_1.Blockchain.Neo3 } = opts;
|
|
53
|
-
if (!N3Client.SUPPORTED_BLOCKCHAINS.includes(blockchain))
|
|
54
|
-
throw new Error(`unsupported blockchain - ${blockchain}`);
|
|
55
|
-
return new N3Client(configProvider, blockchain);
|
|
56
|
-
}
|
|
57
|
-
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const tokens = yield sdk.token.getAllTokens();
|
|
60
|
-
const balances = yield this.getAllN3Balances(address);
|
|
61
|
-
const tokensWithBalance = [];
|
|
62
|
-
for (const token of tokens) {
|
|
63
|
-
if (!token.tokenAddress.match(/^[0-9a-f]+$/i))
|
|
64
|
-
continue;
|
|
65
|
-
if (whitelistDenoms && !whitelistDenoms.includes(token.denom))
|
|
66
|
-
continue;
|
|
67
|
-
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
68
|
-
if (!balances[tokenScriptHash])
|
|
69
|
-
continue;
|
|
70
|
-
tokensWithBalance.push(Object.assign(Object.assign({}, token), { externalBalance: balances[tokenScriptHash] }));
|
|
71
|
-
}
|
|
72
|
-
return tokensWithBalance;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getAllN3Balances(address) {
|
|
76
|
-
var _a;
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const response = yield this.rpcClient.execute(new neon_core_next_1.rpc.Query({
|
|
79
|
-
method: "getnep17balances",
|
|
80
|
-
params: [address],
|
|
81
|
-
}));
|
|
82
|
-
const balances = {};
|
|
83
|
-
for (const balanceResult of (_a = response === null || response === void 0 ? void 0 : response.balance) !== null && _a !== void 0 ? _a : []) {
|
|
84
|
-
balances[balanceResult.assethash.replace(/^0x/i, "")] = balanceResult.amount;
|
|
85
|
-
}
|
|
86
|
-
return balances;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
lock(lockProxyScriptHash, tokenScriptHash, fromAddressHex, toAddressHex, amount, feeAmount, signer) {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const nonce = Math.floor(Math.random() * 1000000);
|
|
92
|
-
const networkConfig = this.configProvider.getConfig();
|
|
93
|
-
const args = [
|
|
94
|
-
neon_core_next_1.sc.ContractParam.hash160(tokenScriptHash),
|
|
95
|
-
neon_core_next_1.sc.ContractParam.hash160(fromAddressHex),
|
|
96
|
-
neon_core_next_1.sc.ContractParam.byteArray(neon_core_next_1.u.HexString.fromHex(toAddressHex, true)),
|
|
97
|
-
neon_core_next_1.sc.ContractParam.integer(amount.toString(10)),
|
|
98
|
-
neon_core_next_1.sc.ContractParam.integer(feeAmount.toString(10)),
|
|
99
|
-
neon_core_next_1.sc.ContractParam.byteArray(neon_core_next_1.u.HexString.fromHex(feeAmount.isZero() ? "" : networkConfig.feeAddress, true)),
|
|
100
|
-
neon_core_next_1.sc.ContractParam.integer(nonce),
|
|
101
|
-
];
|
|
102
|
-
const script = neon_core_next_1.sc.createScript({
|
|
103
|
-
scriptHash: lockProxyScriptHash,
|
|
104
|
-
operation: "lock",
|
|
105
|
-
args,
|
|
106
|
-
});
|
|
107
|
-
const currentHeight = yield this.rpcClient.getBlockCount();
|
|
108
|
-
const txn = new neon_core_next_1.tx.Transaction({
|
|
109
|
-
script,
|
|
110
|
-
validUntilBlock: currentHeight + 100,
|
|
111
|
-
signers: [
|
|
112
|
-
{
|
|
113
|
-
account: signer.scriptHash,
|
|
114
|
-
scopes: neon_core_next_1.tx.WitnessScope.Global,
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
});
|
|
118
|
-
const networkFee = yield this.getNetworkFee(txn, 0);
|
|
119
|
-
txn.networkFee = networkFee;
|
|
120
|
-
const systemFee = yield this.getSystemFee(txn, 0, [
|
|
121
|
-
{
|
|
122
|
-
account: signer.scriptHash,
|
|
123
|
-
scopes: neon_core_next_1.tx.WitnessScope.Global.toString(),
|
|
124
|
-
},
|
|
125
|
-
]);
|
|
126
|
-
txn.systemFee = systemFee;
|
|
127
|
-
if (amount.lt(feeAmount)) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
const config = this.configProvider.getConfig();
|
|
131
|
-
yield signer.sign(txn, config.n3.networkMagic);
|
|
132
|
-
const txHash = yield this.rpcClient.sendRawTransaction(neon_core_next_1.u.HexString.fromHex(txn.serialize(true)));
|
|
133
|
-
return txHash;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
lockDeposit(token, feeAmountInput, swthAddress, neoPrivateKey) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
const networkConfig = this.configProvider.getConfig();
|
|
139
|
-
const scriptHash = neon_core_next_1.u.reverseHex(token.bridgeAddress);
|
|
140
|
-
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
141
|
-
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
142
|
-
const toAddress = Buffer.from(addressBytes).toString("hex");
|
|
143
|
-
const amount = new bignumber_js_1.default(token.externalBalance);
|
|
144
|
-
const feeAmount = new bignumber_js_1.default(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
145
|
-
const n3Signer = N3Client.signerFromPrivateKey(neoPrivateKey);
|
|
146
|
-
const fromAddress = address_1.N3Address.privateKeyToAddress(neoPrivateKey);
|
|
147
|
-
return yield this.lock(scriptHash, tokenScriptHash, fromAddress, toAddress, amount, feeAmount, n3Signer);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
lockO3Deposit(params) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
const { feeAmount, toAddressHex, amount, token, o3Wallet } = params;
|
|
153
|
-
if (!o3Wallet.isConnected()) {
|
|
154
|
-
throw new Error("O3 wallet not connected. Please reconnect and try again.");
|
|
155
|
-
}
|
|
156
|
-
const nonce = Math.floor(Math.random() * 1000000);
|
|
157
|
-
const networkConfig = this.configProvider.getConfig();
|
|
158
|
-
const lockProxyScriptHash = neon_core_next_1.u.reverseHex(token.bridgeAddress);
|
|
159
|
-
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
160
|
-
const fromAddressHex = o3Wallet.address;
|
|
161
|
-
const publicKeyOutput = (yield o3Wallet.getPublicKeyOutput());
|
|
162
|
-
const accountScriptHash = address_1.N3Address.publicKeyToScriptHash(publicKeyOutput.publicKey);
|
|
163
|
-
const feeAddress = feeAmount.isZero() ? "" : neon_core_next_1.u.HexString.fromHex(networkConfig.feeAddress).toBase64();
|
|
164
|
-
const args = [
|
|
165
|
-
{ type: o3_1.O3Types.ArgTypes.Hash160, value: tokenScriptHash },
|
|
166
|
-
{ type: o3_1.O3Types.ArgTypes.Hash160, value: fromAddressHex },
|
|
167
|
-
{ type: o3_1.O3Types.ArgTypes.ByteArray, value: neon_core_next_1.u.HexString.fromHex(toAddressHex).toBase64() },
|
|
168
|
-
{ type: o3_1.O3Types.ArgTypes.Integer, value: amount.toString(10) },
|
|
169
|
-
{ type: o3_1.O3Types.ArgTypes.Integer, value: feeAmount.toString(10) },
|
|
170
|
-
{ type: o3_1.O3Types.ArgTypes.ByteArray, value: feeAddress },
|
|
171
|
-
{ type: o3_1.O3Types.ArgTypes.Integer, value: nonce.toString() },
|
|
172
|
-
];
|
|
173
|
-
const result = yield o3Wallet.getDAPI().invoke({
|
|
174
|
-
operation: "lock",
|
|
175
|
-
scriptHash: lockProxyScriptHash,
|
|
176
|
-
args,
|
|
177
|
-
network: o3Wallet.neoNetwork,
|
|
178
|
-
signers: [
|
|
179
|
-
{
|
|
180
|
-
account: accountScriptHash,
|
|
181
|
-
scopes: neon_core_next_1.tx.WitnessScope.Global,
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
});
|
|
185
|
-
return result.txid;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
lockLedgerDeposit(params) {
|
|
189
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
const { feeAmount, toAddressHex, amount, token, ledger } = params;
|
|
191
|
-
const scriptHash = neon_core_next_1.u.reverseHex(token.bridgeAddress);
|
|
192
|
-
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
193
|
-
const fromAddressHex = ledger.displayAddress;
|
|
194
|
-
const n3Signer = N3Client.signerFromLedger(ledger);
|
|
195
|
-
return yield this.lock(scriptHash, tokenScriptHash, fromAddressHex, toAddressHex, amount, feeAmount, n3Signer);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
getNetworkFee(txn, networkFee) {
|
|
199
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
const feePerByteInvokeResponse = yield this.rpcClient.invokeFunction(neon_core_next_1.CONST.NATIVE_CONTRACT_HASH.PolicyContract, "getFeePerByte");
|
|
201
|
-
if (feePerByteInvokeResponse.state !== "HALT") {
|
|
202
|
-
if (networkFee === 0) {
|
|
203
|
-
throw new Error("Unable to retrieve data to calculate network fee.");
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
txn.networkFee = neon_core_next_1.u.BigInteger.fromNumber(networkFee);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const feePerByte = new bignumber_js_1.default(feePerByteInvokeResponse.stack[0].value);
|
|
210
|
-
// Account for witness size
|
|
211
|
-
const transactionByteSize = txn.serialize().length / 2 + 109;
|
|
212
|
-
// Hardcoded. Running a witness is always the same cost for the basic account.
|
|
213
|
-
const witnessProcessingFee = new bignumber_js_1.default(1000390);
|
|
214
|
-
const networkFeeEstimate = feePerByte.times(transactionByteSize).plus(witnessProcessingFee);
|
|
215
|
-
if (networkFee && networkFee >= networkFeeEstimate.toNumber()) {
|
|
216
|
-
return neon_core_next_1.u.BigInteger.fromNumber(networkFee);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
return neon_core_next_1.u.BigInteger.fromNumber(networkFeeEstimate.toString(10));
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
getSystemFee(txn, systemFee, signers) {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
const invokeFunctionResponse = yield this.rpcClient.invokeScript(neon_core_next_1.u.HexString.fromHex(txn.script), signers);
|
|
226
|
-
if (invokeFunctionResponse.state !== "HALT") {
|
|
227
|
-
throw new Error(`Simulation errored out: ${invokeFunctionResponse.exception}`);
|
|
228
|
-
}
|
|
229
|
-
const requiredSystemFee = new bignumber_js_1.default(invokeFunctionResponse.gasconsumed).toNumber();
|
|
230
|
-
if (systemFee && systemFee >= requiredSystemFee) {
|
|
231
|
-
return neon_core_next_1.u.BigInteger.fromNumber(systemFee);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
return neon_core_next_1.u.BigInteger.fromNumber(requiredSystemFee);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
formatWithdrawalAddress(address) {
|
|
239
|
-
const isValidAddress = neon_core_next_1.wallet.isAddress(address);
|
|
240
|
-
if (!isValidAddress) {
|
|
241
|
-
throw new Error("invalid address");
|
|
242
|
-
}
|
|
243
|
-
const scriptHash = neon_core_next_1.wallet.getScriptHashFromAddress(address);
|
|
244
|
-
// return the little endian version of the address
|
|
245
|
-
return neon_core_next_1.u.reverseHex(scriptHash);
|
|
246
|
-
}
|
|
247
|
-
retrieveNEP17Info(address) {
|
|
248
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
const result = yield this.rpcClient.executeAll([
|
|
250
|
-
new neon_core_next_1.rpc.Query({
|
|
251
|
-
method: "invokefunction",
|
|
252
|
-
params: [address, "decimals"],
|
|
253
|
-
}),
|
|
254
|
-
new neon_core_next_1.rpc.Query({
|
|
255
|
-
method: "invokefunction",
|
|
256
|
-
params: [address, "symbol"],
|
|
257
|
-
}),
|
|
258
|
-
new neon_core_next_1.rpc.Query({
|
|
259
|
-
method: "getcontractstate",
|
|
260
|
-
params: [address],
|
|
261
|
-
}),
|
|
262
|
-
]);
|
|
263
|
-
const [decimalRaw, symbolRaw, nameRaw] = result;
|
|
264
|
-
let decimals = 0;
|
|
265
|
-
let symbol = "";
|
|
266
|
-
let name = "";
|
|
267
|
-
if (typeof decimalRaw.stack[0].value === "string") {
|
|
268
|
-
decimals = Number(decimalRaw.stack[0].value);
|
|
269
|
-
}
|
|
270
|
-
if (typeof symbolRaw.stack[0].value === "string") {
|
|
271
|
-
symbol = Buffer.from(symbolRaw.stack[0].value, "base64").toString("ascii");
|
|
272
|
-
}
|
|
273
|
-
if (typeof nameRaw.manifest.name === "string") {
|
|
274
|
-
name = nameRaw.manifest.name;
|
|
275
|
-
}
|
|
276
|
-
return { name, symbol, address, decimals };
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
exports.N3Client = N3Client;
|
|
281
|
-
N3Client.SUPPORTED_BLOCKCHAINS = [blockchain_1.Blockchain.Neo3];
|
|
282
|
-
N3Client.BLOCKCHAIN_KEY = {
|
|
283
|
-
[blockchain_1.Blockchain.Neo3]: "Neo3",
|
|
284
|
-
};
|
|
285
|
-
exports.default = N3Client;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import CarbonSDK from "../CarbonSDK";
|
|
2
|
-
import { NeoNetworkConfig, NetworkConfig, NetworkConfigProvider } from "../constant";
|
|
3
|
-
import { Carbon } from "../CarbonSDK";
|
|
4
|
-
import { NeoLedgerAccount } from "../provider/account";
|
|
5
|
-
import { O3Wallet } from "../provider/o3";
|
|
6
|
-
import { Blockchain } from "../util/blockchain";
|
|
7
|
-
import { TokenInitInfo, TokensWithExternalBalance } from "../util/external";
|
|
8
|
-
import BigNumber from "bignumber.js";
|
|
9
|
-
export interface NEOClientOpts {
|
|
10
|
-
configProvider: NetworkConfigProvider;
|
|
11
|
-
blockchain?: Blockchain;
|
|
12
|
-
}
|
|
13
|
-
export interface LockLedgerDepositParams {
|
|
14
|
-
feeAmount: BigNumber;
|
|
15
|
-
amount: BigNumber;
|
|
16
|
-
address: Uint8Array;
|
|
17
|
-
token: TokensWithExternalBalance;
|
|
18
|
-
ledger: NeoLedgerAccount;
|
|
19
|
-
signCompleteCallback?: () => void;
|
|
20
|
-
}
|
|
21
|
-
export interface LockO3DepositParams {
|
|
22
|
-
feeAmount: BigNumber;
|
|
23
|
-
amount: BigNumber;
|
|
24
|
-
address: Uint8Array;
|
|
25
|
-
token: TokensWithExternalBalance;
|
|
26
|
-
o3Wallet: O3Wallet;
|
|
27
|
-
signCompleteCallback?: () => void;
|
|
28
|
-
}
|
|
29
|
-
export declare class NEOClient {
|
|
30
|
-
readonly configProvider: NetworkConfigProvider;
|
|
31
|
-
readonly blockchain: Blockchain;
|
|
32
|
-
static SUPPORTED_BLOCKCHAINS: Blockchain[];
|
|
33
|
-
static BLOCKCHAIN_KEY: {
|
|
34
|
-
neo: string;
|
|
35
|
-
};
|
|
36
|
-
private constructor();
|
|
37
|
-
static instance(opts: NEOClientOpts): CarbonSDK.NEOClient;
|
|
38
|
-
static parseHexNum(hex: string, exp?: number): string;
|
|
39
|
-
getExternalBalances(sdk: CarbonSDK, address: string, url: string, whitelistDenoms?: string[], version?: string): Promise<TokensWithExternalBalance[]>;
|
|
40
|
-
lockDeposit(token: TokensWithExternalBalance, feeAmountInput: string, swthAddress: string, neoPrivateKey: string): Promise<false | import("@cityofzion/neon-api/lib/funcs/types").DoInvokeConfig>;
|
|
41
|
-
lockO3Deposit(params: LockO3DepositParams): Promise<any>;
|
|
42
|
-
lockLedgerDeposit(params: LockLedgerDepositParams): Promise<any>;
|
|
43
|
-
retrieveNEP5Info(scriptHash: string): Promise<TokenInitInfo>;
|
|
44
|
-
wrapNeoToNneo(neoAmount: BigNumber, neoPrivateKey: string): Promise<import("@cityofzion/neon-api/lib/funcs/types").DoInvokeConfig>;
|
|
45
|
-
formatWithdrawalAddress(address: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* TargetProxyHash is a hash of token originator address that is used
|
|
48
|
-
* for lockproxy asset registration and identification
|
|
49
|
-
*
|
|
50
|
-
* @param token
|
|
51
|
-
*/
|
|
52
|
-
getTargetProxyHash(token: Carbon.Coin.Token): string;
|
|
53
|
-
getNetworkConfig(): NetworkConfig;
|
|
54
|
-
getConfig(): NeoNetworkConfig;
|
|
55
|
-
getProviderUrl(): string;
|
|
56
|
-
}
|
|
57
|
-
export default NEOClient;
|