carbon-js-sdk 0.2.7-beta.2 → 0.2.7-beta.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/lib/clients/CarbonQueryClient.js +1 -1
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +60 -79
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/constant/generic.js +1 -1
- package/lib/modules/gov.js +14 -14
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +20 -20
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +4 -4
- package/lib/provider/amino/types/coin.js +2 -2
- package/lib/provider/amino/types/gov.js +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/keplr/KeplrStore.js +1 -1
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/o3/O3Wallet.js +7 -8
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +5 -6
|
@@ -43,7 +43,7 @@ class CarbonQueryClient {
|
|
|
43
43
|
constructor(tmClient) {
|
|
44
44
|
this.tmClient = tmClient;
|
|
45
45
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
46
|
-
const rpcClient =
|
|
46
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
47
47
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
48
48
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
49
49
|
this.book = new query_2.QueryClientImpl(rpcClient);
|
package/lib/clients/ETHClient.js
CHANGED
|
@@ -40,13 +40,13 @@ class ETHClient {
|
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const tokenQueryResults = yield api.token.getAllTokens();
|
|
42
42
|
const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
|
|
43
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
43
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
44
44
|
token.tokenAddress.length == 40 &&
|
|
45
|
-
token.bridgeAddress.toLowerCase() ==
|
|
45
|
+
token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
|
|
46
46
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
|
|
47
|
-
this.verifyChecksum(
|
|
47
|
+
this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
|
|
48
48
|
const assetIds = tokens.map((token) => {
|
|
49
|
-
return this.verifyChecksum(
|
|
49
|
+
return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
50
50
|
});
|
|
51
51
|
const provider = this.getProvider();
|
|
52
52
|
const contractAddress = this.getBalanceReaderAddress();
|
|
@@ -95,14 +95,14 @@ class ETHClient {
|
|
|
95
95
|
throw new Error("Invalid recovery address");
|
|
96
96
|
}
|
|
97
97
|
const fromTokenId = fromToken.id;
|
|
98
|
-
const fromTokenAddress =
|
|
98
|
+
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
99
99
|
const toTokenDenom = toToken.denom;
|
|
100
100
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
101
101
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
102
102
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
103
103
|
const nonce = yield rpcProvider.getTransactionCount(fromAddress);
|
|
104
104
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
105
|
-
const feeAddress =
|
|
105
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
106
106
|
const tokenCreator = fromToken.creator;
|
|
107
107
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, CarbonSDK_1.default.Network.MainNet);
|
|
108
108
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -137,9 +137,9 @@ class ETHClient {
|
|
|
137
137
|
throw new Error("Minimum gas required: 150,000");
|
|
138
138
|
}
|
|
139
139
|
const networkConfig = this.getNetworkConfig();
|
|
140
|
-
const assetId =
|
|
141
|
-
const targetProxyHash =
|
|
142
|
-
const feeAddress =
|
|
140
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
141
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
142
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
143
143
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
144
144
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
145
145
|
const contractAddress = this.getLockProxyAddress();
|
|
@@ -190,16 +190,16 @@ class ETHClient {
|
|
|
190
190
|
return "insufficient balance";
|
|
191
191
|
}
|
|
192
192
|
const networkConfig = this.getNetworkConfig();
|
|
193
|
-
const assetId =
|
|
194
|
-
const targetProxyHash =
|
|
195
|
-
const feeAddress =
|
|
193
|
+
const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
194
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
195
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
196
196
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
|
|
197
197
|
const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
|
|
198
198
|
const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
|
|
199
199
|
// logger("sendDeposit message", message)
|
|
200
200
|
let signatureResult;
|
|
201
201
|
const { address, signature } = yield getSignatureCallback(message);
|
|
202
|
-
const signatureBytes = ethers_1.ethers.utils.arrayify(
|
|
202
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
|
|
203
203
|
const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
|
|
204
204
|
// logger("sign result", address, signature)
|
|
205
205
|
signatureResult = {
|
|
@@ -238,7 +238,7 @@ class ETHClient {
|
|
|
238
238
|
if (!feeInfo.details.deposit.fee) {
|
|
239
239
|
throw new Error("unsupported token");
|
|
240
240
|
}
|
|
241
|
-
if (
|
|
241
|
+
if (blockchain_1.blockchainForChainId(token.chainId.toNumber()) !== this.blockchain) {
|
|
242
242
|
throw new Error("unsupported token");
|
|
243
243
|
}
|
|
244
244
|
let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.details.deposit.fee);
|
|
@@ -304,7 +304,7 @@ class ETHClient {
|
|
|
304
304
|
getTargetProxyHash(token) {
|
|
305
305
|
const networkConfig = this.getNetworkConfig();
|
|
306
306
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
307
|
-
const addressHex =
|
|
307
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
308
308
|
return addressHex;
|
|
309
309
|
}
|
|
310
310
|
getProvider() {
|
|
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
|
|
|
29
29
|
const formatDateField = (value) => {
|
|
30
30
|
if (typeof value !== "string")
|
|
31
31
|
return null;
|
|
32
|
-
return
|
|
32
|
+
return dayjs_1.default(value);
|
|
33
33
|
};
|
|
34
34
|
const formatCrossChainTransfer = (value) => {
|
|
35
35
|
var _a, _b;
|
package/lib/clients/NEOClient.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -37,8 +18,8 @@ const util_1 = require("../util");
|
|
|
37
18
|
const address_1 = require("../util/address");
|
|
38
19
|
const blockchain_1 = require("../util/blockchain");
|
|
39
20
|
const generic_1 = require("../util/generic");
|
|
40
|
-
const
|
|
41
|
-
const
|
|
21
|
+
const plugin_1 = __importDefault(require("@cityofzion/neon-api/lib/plugin"));
|
|
22
|
+
const neon_core_1 = __importDefault(require("@cityofzion/neon-core"));
|
|
42
23
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
24
|
const ethers_1 = require("ethers");
|
|
44
25
|
const lodash_1 = require("lodash");
|
|
@@ -57,26 +38,26 @@ class NEOClient {
|
|
|
57
38
|
if (!hex || typeof (hex) !== "string")
|
|
58
39
|
return "0";
|
|
59
40
|
const res = hex.length % 2 !== 0 ? `0${hex}` : hex;
|
|
60
|
-
return new bignumber_js_1.default(res ? neon_core_1.u.reverseHex(res) : "00", 16).shiftedBy(-exp).toString();
|
|
41
|
+
return new bignumber_js_1.default(res ? neon_core_1.default.u.reverseHex(res) : "00", 16).shiftedBy(-exp).toString();
|
|
61
42
|
}
|
|
62
43
|
getExternalBalances(sdk, address, url, whitelistDenoms) {
|
|
63
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
45
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
65
|
-
const account = new neon_core_1.wallet.Account(address);
|
|
66
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
46
|
+
const account = new neon_core_1.default.wallet.Account(address);
|
|
47
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
67
48
|
token.tokenAddress.length == 40 &&
|
|
68
49
|
token.bridgeAddress.length == 40);
|
|
69
|
-
const client = new neon_core_1.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
50
|
+
const client = new neon_core_1.default.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
70
51
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
71
52
|
// the gas limit on the RPC node and error out otherwise
|
|
72
|
-
const promises =
|
|
53
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
73
54
|
var _a, _b, _c;
|
|
74
55
|
let acc = {};
|
|
75
56
|
for (const token of partition) {
|
|
76
57
|
if (whitelistDenoms && !whitelistDenoms.includes(token.denom))
|
|
77
58
|
continue;
|
|
78
|
-
const sb = new neon_core_1.sc.ScriptBuilder();
|
|
79
|
-
sb.emitAppCall(
|
|
59
|
+
const sb = new neon_core_1.default.sc.ScriptBuilder();
|
|
60
|
+
sb.emitAppCall(neon_core_1.default.u.reverseHex(token.tokenAddress), "balanceOf", [neon_core_1.default.u.reverseHex(account.scriptHash)]);
|
|
80
61
|
try {
|
|
81
62
|
const response = yield client.invokeScript(sb.str);
|
|
82
63
|
acc[token.denom.toUpperCase()] = ((_a = response.stack[0]) === null || _a === void 0 ? void 0 : _a.type) === "Integer" // Happens on polychain devnet
|
|
@@ -102,15 +83,15 @@ class NEOClient {
|
|
|
102
83
|
}
|
|
103
84
|
lockDeposit(token, feeAmountInput, swthAddress, neoPrivateKey) {
|
|
104
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const account =
|
|
86
|
+
const account = new neon_core_1.default.wallet.Account(neoPrivateKey);
|
|
106
87
|
const networkConfig = this.getNetworkConfig();
|
|
107
|
-
const scriptHash =
|
|
88
|
+
const scriptHash = neon_core_1.default.u.reverseHex(token.bridgeAddress);
|
|
108
89
|
const fromAssetHash = token.tokenAddress;
|
|
109
|
-
const fromAddress =
|
|
90
|
+
const fromAddress = neon_core_1.default.u.reverseHex(account.scriptHash);
|
|
110
91
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
111
|
-
const toAssetHash =
|
|
92
|
+
const toAssetHash = neon_core_1.default.u.str2hexstring(token.id);
|
|
112
93
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
113
|
-
const toAddress =
|
|
94
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
114
95
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
115
96
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
116
97
|
const feeAddress = networkConfig.feeAddress;
|
|
@@ -118,7 +99,7 @@ class NEOClient {
|
|
|
118
99
|
if (amount.lt(feeAmount)) {
|
|
119
100
|
return false;
|
|
120
101
|
}
|
|
121
|
-
const sb =
|
|
102
|
+
const sb = new neon_core_1.default.sc.ScriptBuilder();
|
|
122
103
|
sb.emitAppCall(scriptHash, "lock", [
|
|
123
104
|
fromAssetHash,
|
|
124
105
|
fromAddress,
|
|
@@ -132,9 +113,9 @@ class NEOClient {
|
|
|
132
113
|
]);
|
|
133
114
|
const rpcUrl = yield this.getProviderUrl();
|
|
134
115
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
135
|
-
? new
|
|
136
|
-
: new
|
|
137
|
-
return
|
|
116
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
117
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
118
|
+
return plugin_1.default.doInvoke({
|
|
138
119
|
api: apiProvider,
|
|
139
120
|
url: rpcUrl,
|
|
140
121
|
account,
|
|
@@ -152,26 +133,26 @@ class NEOClient {
|
|
|
152
133
|
}
|
|
153
134
|
const publicKeyOutput = yield o3Wallet.getPublicKeyOutput();
|
|
154
135
|
const networkConfig = this.getNetworkConfig();
|
|
155
|
-
const scriptHash =
|
|
156
|
-
const fromAssetHash =
|
|
136
|
+
const scriptHash = neon_core_1.default.u.reverseHex(token.bridgeAddress);
|
|
137
|
+
const fromAssetHash = neon_core_1.default.u.reverseHex(token.tokenAddress);
|
|
157
138
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
158
139
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
159
|
-
const toAssetHash =
|
|
160
|
-
const toAddress =
|
|
140
|
+
const toAssetHash = neon_core_1.default.u.str2hexstring(token.id);
|
|
141
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
161
142
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
162
143
|
if (amount.lt(feeAmount)) {
|
|
163
144
|
throw new Error("Invalid amount");
|
|
164
145
|
}
|
|
165
146
|
const data = [
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
147
|
+
neon_core_1.default.sc.ContractParam.hash160(fromAssetHash),
|
|
148
|
+
neon_core_1.default.sc.ContractParam.hash160(fromAddress),
|
|
149
|
+
neon_core_1.default.sc.ContractParam.byteArray(targetProxyHash, "hex"),
|
|
150
|
+
neon_core_1.default.sc.ContractParam.byteArray(toAssetHash, "hex"),
|
|
151
|
+
neon_core_1.default.sc.ContractParam.byteArray(toAddress, "hex"),
|
|
152
|
+
neon_core_1.default.sc.ContractParam.integer(amount.toNumber()),
|
|
153
|
+
neon_core_1.default.sc.ContractParam.integer(feeAmount.toNumber()),
|
|
154
|
+
neon_core_1.default.sc.ContractParam.byteArray(networkConfig.feeAddress, "hex"),
|
|
155
|
+
neon_core_1.default.sc.ContractParam.integer(nonce),
|
|
175
156
|
];
|
|
176
157
|
const tx = yield o3Wallet.getDAPI().invoke({
|
|
177
158
|
scriptHash,
|
|
@@ -186,20 +167,20 @@ class NEOClient {
|
|
|
186
167
|
var _a;
|
|
187
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
169
|
const { feeAmount, address, amount, token, ledger, signCompleteCallback, } = params;
|
|
189
|
-
const compressedPublicKey = neon_core_1.wallet.getPublicKeyEncoded(ledger.publicKey);
|
|
170
|
+
const compressedPublicKey = neon_core_1.default.wallet.getPublicKeyEncoded(ledger.publicKey);
|
|
190
171
|
const networkConfig = this.getNetworkConfig();
|
|
191
|
-
const scriptHash =
|
|
172
|
+
const scriptHash = neon_core_1.default.u.reverseHex(token.bridgeAddress);
|
|
192
173
|
const fromAssetHash = token.tokenAddress;
|
|
193
174
|
const fromAddress = ledger.scriptHash;
|
|
194
175
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
195
|
-
const toAssetHash =
|
|
196
|
-
const toAddress =
|
|
176
|
+
const toAssetHash = neon_core_1.default.u.str2hexstring(token.id);
|
|
177
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
197
178
|
const feeAddress = networkConfig.feeAddress;
|
|
198
179
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
199
180
|
if (amount.lt(feeAmount)) {
|
|
200
181
|
throw new Error("Invalid amount");
|
|
201
182
|
}
|
|
202
|
-
const sb =
|
|
183
|
+
const sb = new neon_core_1.default.sc.ScriptBuilder();
|
|
203
184
|
const data = [
|
|
204
185
|
fromAssetHash,
|
|
205
186
|
fromAddress,
|
|
@@ -214,15 +195,15 @@ class NEOClient {
|
|
|
214
195
|
sb.emitAppCall(scriptHash, "lock", data);
|
|
215
196
|
const rpcUrl = yield this.getProviderUrl();
|
|
216
197
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
217
|
-
? new
|
|
218
|
-
: new
|
|
198
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
199
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
219
200
|
let invokeTxConfig = {
|
|
220
|
-
account: Object.assign(Object.assign({},
|
|
201
|
+
account: Object.assign(Object.assign({}, new neon_core_1.default.wallet.Account("")), {
|
|
221
202
|
// overwrite the address and public key to values provided by the ledger.
|
|
222
203
|
address: ledger.displayAddress, publicKey: compressedPublicKey }),
|
|
223
204
|
signingFunction: (tx, publicKey) => __awaiter(this, void 0, void 0, function* () {
|
|
224
205
|
const signature = yield ledger.sign(tx);
|
|
225
|
-
const witness =
|
|
206
|
+
const witness = neon_core_1.default.tx.Witness.fromSignature(signature, publicKey);
|
|
226
207
|
return witness.serialize();
|
|
227
208
|
}),
|
|
228
209
|
api: apiProvider,
|
|
@@ -233,16 +214,16 @@ class NEOClient {
|
|
|
233
214
|
};
|
|
234
215
|
// similar to Neon.doInvoke(invokeTxConfig), but
|
|
235
216
|
// separates out sendTx to broadcast to several nodes
|
|
236
|
-
invokeTxConfig = yield
|
|
237
|
-
invokeTxConfig = yield
|
|
238
|
-
invokeTxConfig = yield
|
|
239
|
-
invokeTxConfig = yield
|
|
217
|
+
invokeTxConfig = yield plugin_1.default.fillBalance(invokeTxConfig);
|
|
218
|
+
invokeTxConfig = yield plugin_1.default.createInvocationTx(invokeTxConfig);
|
|
219
|
+
invokeTxConfig = yield plugin_1.default.modifyTransactionForEmptyTransaction(invokeTxConfig);
|
|
220
|
+
invokeTxConfig = yield plugin_1.default.signTx(invokeTxConfig);
|
|
240
221
|
// provide notification to caller that signature is
|
|
241
222
|
// done and proceeding to broadcasting tx
|
|
242
223
|
if (signCompleteCallback) {
|
|
243
224
|
signCompleteCallback();
|
|
244
225
|
}
|
|
245
|
-
yield
|
|
226
|
+
yield plugin_1.default.sendTx(Object.assign(Object.assign({}, invokeTxConfig), { rpcUrl }));
|
|
246
227
|
return (_a = invokeTxConfig.tx) === null || _a === void 0 ? void 0 : _a.hash;
|
|
247
228
|
});
|
|
248
229
|
}
|
|
@@ -250,37 +231,37 @@ class NEOClient {
|
|
|
250
231
|
var _a, _b, _c, _d, _e;
|
|
251
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
233
|
const url = this.getProviderUrl();
|
|
253
|
-
const sb =
|
|
234
|
+
const sb = new neon_core_1.default.sc.ScriptBuilder();
|
|
254
235
|
sb.emitAppCall(scriptHash, "symbol", []);
|
|
255
236
|
sb.emitAppCall(scriptHash, "name", []);
|
|
256
237
|
sb.emitAppCall(scriptHash, "decimals", []);
|
|
257
|
-
const response = yield
|
|
238
|
+
const response = yield neon_core_1.default.rpc.Query.invokeScript(sb.str).execute(url);
|
|
258
239
|
if (((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.state) !== "HALT")
|
|
259
240
|
throw new Error("retrieve failed");
|
|
260
|
-
const symbol =
|
|
261
|
-
const name =
|
|
241
|
+
const symbol = neon_core_1.default.u.hexstring2str((_b = response.result.stack) === null || _b === void 0 ? void 0 : _b[0].value);
|
|
242
|
+
const name = neon_core_1.default.u.hexstring2str((_c = response.result.stack) === null || _c === void 0 ? void 0 : _c[1].value);
|
|
262
243
|
const decimals = parseInt((_e = (_d = response.result.stack) === null || _d === void 0 ? void 0 : _d[2].value) !== null && _e !== void 0 ? _e : "0", 10);
|
|
263
244
|
return { address: scriptHash, decimals, name, symbol };
|
|
264
245
|
});
|
|
265
246
|
}
|
|
266
247
|
wrapNeoToNneo(neoAmount, neoPrivateKey) {
|
|
267
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
const account =
|
|
249
|
+
const account = new neon_core_1.default.wallet.Account(neoPrivateKey);
|
|
269
250
|
const rpcUrl = yield this.getProviderUrl();
|
|
270
251
|
const wrapperContractScriptHash = this.getConfig().wrapperScriptHash;
|
|
271
|
-
const wrapperContractAddress = neon_core_1.wallet.getAddressFromScriptHash(wrapperContractScriptHash);
|
|
252
|
+
const wrapperContractAddress = neon_core_1.default.wallet.getAddressFromScriptHash(wrapperContractScriptHash);
|
|
272
253
|
// Build config
|
|
273
|
-
const intent =
|
|
254
|
+
const intent = plugin_1.default.makeIntent({ NEO: neoAmount.toNumber() }, wrapperContractAddress);
|
|
274
255
|
const props = {
|
|
275
256
|
scriptHash: wrapperContractScriptHash,
|
|
276
257
|
operation: "mintTokens",
|
|
277
258
|
args: []
|
|
278
259
|
};
|
|
279
|
-
const script =
|
|
260
|
+
const script = neon_core_1.default.sc.createScript(props);
|
|
280
261
|
const networkConfig = this.getNetworkConfig();
|
|
281
262
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
282
|
-
? new
|
|
283
|
-
: new
|
|
263
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
264
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
284
265
|
const config = {
|
|
285
266
|
api: apiProvider,
|
|
286
267
|
url: rpcUrl,
|
|
@@ -289,19 +270,19 @@ class NEOClient {
|
|
|
289
270
|
script: script
|
|
290
271
|
};
|
|
291
272
|
// Neon API
|
|
292
|
-
const response = yield
|
|
273
|
+
const response = yield plugin_1.default.doInvoke(config);
|
|
293
274
|
return response;
|
|
294
275
|
});
|
|
295
276
|
}
|
|
296
277
|
formatWithdrawalAddress(address) {
|
|
297
278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
const isValidAddress = neon_core_1.wallet.isAddress(address);
|
|
279
|
+
const isValidAddress = neon_core_1.default.wallet.isAddress(address);
|
|
299
280
|
if (!isValidAddress) {
|
|
300
281
|
throw new Error("invalid address");
|
|
301
282
|
}
|
|
302
|
-
const scriptHash = neon_core_1.wallet.getScriptHashFromAddress(address);
|
|
283
|
+
const scriptHash = neon_core_1.default.wallet.getScriptHashFromAddress(address);
|
|
303
284
|
// return the little endian version of the address
|
|
304
|
-
return neon_core_1.u.reverseHex(scriptHash);
|
|
285
|
+
return neon_core_1.default.u.reverseHex(scriptHash);
|
|
305
286
|
});
|
|
306
287
|
}
|
|
307
288
|
/**
|
|
@@ -313,7 +294,7 @@ class NEOClient {
|
|
|
313
294
|
getTargetProxyHash(token) {
|
|
314
295
|
const networkConfig = this.getNetworkConfig();
|
|
315
296
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
316
|
-
const addressHex =
|
|
297
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
317
298
|
return addressHex;
|
|
318
299
|
}
|
|
319
300
|
getNetworkConfig() {
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -74,10 +74,10 @@ class ZILClient {
|
|
|
74
74
|
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
77
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
77
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
78
78
|
token.tokenAddress.length == 40 &&
|
|
79
79
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)));
|
|
80
|
-
const requests = tokens.map(token => token.tokenAddress === zeroAddress ?
|
|
80
|
+
const requests = tokens.map(token => token.tokenAddress === zeroAddress ? exports.balanceBatchRequest(address.replace(/^0x/i, "")) : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
81
81
|
const response = yield fetch(this.getProviderUrl(), {
|
|
82
82
|
method: "post",
|
|
83
83
|
headers: { "content-type": "application/json" },
|
|
@@ -102,7 +102,7 @@ class ZILClient {
|
|
|
102
102
|
// if (!isValidAddress) {
|
|
103
103
|
// throw new Error("invalid address")
|
|
104
104
|
// }
|
|
105
|
-
return
|
|
105
|
+
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -148,7 +148,7 @@ class ZILClient {
|
|
|
148
148
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
149
149
|
}
|
|
150
150
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
151
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
151
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
152
152
|
if (balanceAndNonceResp.error !== undefined) {
|
|
153
153
|
throw new Error(balanceAndNonceResp.error.message);
|
|
154
154
|
}
|
|
@@ -166,7 +166,7 @@ class ZILClient {
|
|
|
166
166
|
vname: 'spender',
|
|
167
167
|
type: 'ByStr20',
|
|
168
168
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
169
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress :
|
|
169
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
vname: 'amount',
|
|
@@ -184,7 +184,7 @@ class ZILClient {
|
|
|
184
184
|
}
|
|
185
185
|
checkAllowanceZRC2(token, owner, spender) {
|
|
186
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const contractAddress =
|
|
187
|
+
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
188
188
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
189
189
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
190
190
|
if (resp.error !== undefined) {
|
|
@@ -204,13 +204,13 @@ class ZILClient {
|
|
|
204
204
|
throw new Error("Invalid recovery address");
|
|
205
205
|
}
|
|
206
206
|
const fromTokenId = fromToken.id;
|
|
207
|
-
const fromTokenAddr =
|
|
207
|
+
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
208
208
|
const toTokenDenom = toToken.denom;
|
|
209
|
-
const targetProxyHash =
|
|
209
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
210
210
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
211
211
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
212
212
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
213
|
-
const feeAddress =
|
|
213
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
214
214
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
215
215
|
let zilliqa;
|
|
216
216
|
if (typeof signer === 'string') {
|
|
@@ -225,7 +225,7 @@ class ZILClient {
|
|
|
225
225
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
226
226
|
}
|
|
227
227
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
228
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
228
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
229
229
|
if (balanceAndNonceResp.error !== undefined) {
|
|
230
230
|
throw new Error(balanceAndNonceResp.error.message);
|
|
231
231
|
}
|
|
@@ -302,13 +302,13 @@ class ZILClient {
|
|
|
302
302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
303
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
304
304
|
const networkConfig = this.getNetworkConfig();
|
|
305
|
-
const assetId =
|
|
306
|
-
const targetProxyHash =
|
|
307
|
-
const feeAddress =
|
|
305
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
306
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
307
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
308
308
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
309
309
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
310
310
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
311
|
-
const contractAddress =
|
|
311
|
+
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
312
312
|
let zilliqa;
|
|
313
313
|
if (typeof signer === 'string') {
|
|
314
314
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -322,7 +322,7 @@ class ZILClient {
|
|
|
322
322
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
323
323
|
}
|
|
324
324
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
325
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
325
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
326
326
|
if (balanceAndNonceResp.error !== undefined) {
|
|
327
327
|
throw new Error(balanceAndNonceResp.error.message);
|
|
328
328
|
}
|
|
@@ -407,7 +407,7 @@ class ZILClient {
|
|
|
407
407
|
getTargetProxyHash(token) {
|
|
408
408
|
const networkConfig = this.getNetworkConfig();
|
|
409
409
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
410
|
-
const addressHex =
|
|
410
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
411
411
|
return addressHex;
|
|
412
412
|
}
|
|
413
413
|
getNetworkConfig() {
|
|
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
|
|
|
159
159
|
const message = Object.assign({}, baseQueryProposalsRequest);
|
|
160
160
|
message.proposalStatus =
|
|
161
161
|
object.proposalStatus !== undefined && object.proposalStatus !== null
|
|
162
|
-
?
|
|
162
|
+
? gov_1.proposalStatusFromJSON(object.proposalStatus)
|
|
163
163
|
: 0;
|
|
164
164
|
message.voter =
|
|
165
165
|
object.voter !== undefined && object.voter !== null
|
|
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
|
|
|
178
178
|
toJSON(message) {
|
|
179
179
|
const obj = {};
|
|
180
180
|
message.proposalStatus !== undefined &&
|
|
181
|
-
(obj.proposalStatus =
|
|
181
|
+
(obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
|
|
182
182
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
183
183
|
message.depositor !== undefined && (obj.depositor = message.depositor);
|
|
184
184
|
message.pagination !== undefined &&
|
|
@@ -185,7 +185,7 @@ exports.MsgVote = {
|
|
|
185
185
|
: "";
|
|
186
186
|
message.option =
|
|
187
187
|
object.option !== undefined && object.option !== null
|
|
188
|
-
?
|
|
188
|
+
? gov_1.voteOptionFromJSON(object.option)
|
|
189
189
|
: 0;
|
|
190
190
|
return message;
|
|
191
191
|
},
|
|
@@ -195,7 +195,7 @@ exports.MsgVote = {
|
|
|
195
195
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
196
196
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
197
197
|
message.option !== undefined &&
|
|
198
|
-
(obj.option =
|
|
198
|
+
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
199
199
|
return obj;
|
|
200
200
|
},
|
|
201
201
|
fromPartial(object) {
|
|
@@ -618,13 +618,13 @@ exports.ModeInfo_Single = {
|
|
|
618
618
|
const message = Object.assign({}, baseModeInfo_Single);
|
|
619
619
|
message.mode =
|
|
620
620
|
object.mode !== undefined && object.mode !== null
|
|
621
|
-
?
|
|
621
|
+
? signing_1.signModeFromJSON(object.mode)
|
|
622
622
|
: 0;
|
|
623
623
|
return message;
|
|
624
624
|
},
|
|
625
625
|
toJSON(message) {
|
|
626
626
|
const obj = {};
|
|
627
|
-
message.mode !== undefined && (obj.mode =
|
|
627
|
+
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
628
628
|
return obj;
|
|
629
629
|
},
|
|
630
630
|
fromPartial(object) {
|
package/lib/constant/generic.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.DEFAULT_FEE_DENOM = "swth";
|
|
|
12
12
|
exports.DEFAULT_GAS_PRICE = new bignumber_js_1.default(10);
|
|
13
13
|
exports.DEFAULT_GAS = new bignumber_js_1.default(10000000);
|
|
14
14
|
exports.DEFAULT_FEE = {
|
|
15
|
-
amount:
|
|
15
|
+
amount: proto_signing_1.coins(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
|
|
16
16
|
gas: exports.DEFAULT_GAS.toString(10),
|
|
17
17
|
};
|
|
18
18
|
exports.CURRENT_GAS_PRICE = 769.23077;
|