carbon-js-sdk 0.2.7-beta.2 → 0.2.7-beta.4
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 -60
- 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
|
@@ -37,8 +37,8 @@ const util_1 = require("../util");
|
|
|
37
37
|
const address_1 = require("../util/address");
|
|
38
38
|
const blockchain_1 = require("../util/blockchain");
|
|
39
39
|
const generic_1 = require("../util/generic");
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const plugin_1 = __importDefault(require("@cityofzion/neon-api/lib/plugin"));
|
|
41
|
+
const Neon = __importStar(require("@cityofzion/neon-core"));
|
|
42
42
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
43
|
const ethers_1 = require("ethers");
|
|
44
44
|
const lodash_1 = require("lodash");
|
|
@@ -57,26 +57,26 @@ class NEOClient {
|
|
|
57
57
|
if (!hex || typeof (hex) !== "string")
|
|
58
58
|
return "0";
|
|
59
59
|
const res = hex.length % 2 !== 0 ? `0${hex}` : hex;
|
|
60
|
-
return new bignumber_js_1.default(res ?
|
|
60
|
+
return new bignumber_js_1.default(res ? Neon.u.reverseHex(res) : "00", 16).shiftedBy(-exp).toString();
|
|
61
61
|
}
|
|
62
62
|
getExternalBalances(sdk, address, url, whitelistDenoms) {
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
65
|
-
const account = new
|
|
66
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
65
|
+
const account = new Neon.wallet.Account(address);
|
|
66
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
67
67
|
token.tokenAddress.length == 40 &&
|
|
68
68
|
token.bridgeAddress.length == 40);
|
|
69
|
-
const client = new
|
|
69
|
+
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
70
70
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
71
71
|
// the gas limit on the RPC node and error out otherwise
|
|
72
|
-
const promises =
|
|
72
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
73
73
|
var _a, _b, _c;
|
|
74
74
|
let acc = {};
|
|
75
75
|
for (const token of partition) {
|
|
76
76
|
if (whitelistDenoms && !whitelistDenoms.includes(token.denom))
|
|
77
77
|
continue;
|
|
78
|
-
const sb = new
|
|
79
|
-
sb.emitAppCall(
|
|
78
|
+
const sb = new Neon.sc.ScriptBuilder();
|
|
79
|
+
sb.emitAppCall(Neon.u.reverseHex(token.tokenAddress), "balanceOf", [Neon.u.reverseHex(account.scriptHash)]);
|
|
80
80
|
try {
|
|
81
81
|
const response = yield client.invokeScript(sb.str);
|
|
82
82
|
acc[token.denom.toUpperCase()] = ((_a = response.stack[0]) === null || _a === void 0 ? void 0 : _a.type) === "Integer" // Happens on polychain devnet
|
|
@@ -102,15 +102,15 @@ class NEOClient {
|
|
|
102
102
|
}
|
|
103
103
|
lockDeposit(token, feeAmountInput, swthAddress, neoPrivateKey) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const account =
|
|
105
|
+
const account = new Neon.wallet.Account(neoPrivateKey);
|
|
106
106
|
const networkConfig = this.getNetworkConfig();
|
|
107
|
-
const scriptHash =
|
|
107
|
+
const scriptHash = Neon.u.reverseHex(token.bridgeAddress);
|
|
108
108
|
const fromAssetHash = token.tokenAddress;
|
|
109
|
-
const fromAddress =
|
|
109
|
+
const fromAddress = Neon.u.reverseHex(account.scriptHash);
|
|
110
110
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
111
|
-
const toAssetHash =
|
|
111
|
+
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
112
112
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
113
|
-
const toAddress =
|
|
113
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
114
114
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
115
115
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
116
116
|
const feeAddress = networkConfig.feeAddress;
|
|
@@ -118,7 +118,7 @@ class NEOClient {
|
|
|
118
118
|
if (amount.lt(feeAmount)) {
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
|
-
const sb =
|
|
121
|
+
const sb = new Neon.sc.ScriptBuilder();
|
|
122
122
|
sb.emitAppCall(scriptHash, "lock", [
|
|
123
123
|
fromAssetHash,
|
|
124
124
|
fromAddress,
|
|
@@ -132,9 +132,9 @@ class NEOClient {
|
|
|
132
132
|
]);
|
|
133
133
|
const rpcUrl = yield this.getProviderUrl();
|
|
134
134
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
135
|
-
? new
|
|
136
|
-
: new
|
|
137
|
-
return
|
|
135
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
136
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
137
|
+
return plugin_1.default.doInvoke({
|
|
138
138
|
api: apiProvider,
|
|
139
139
|
url: rpcUrl,
|
|
140
140
|
account,
|
|
@@ -152,26 +152,26 @@ class NEOClient {
|
|
|
152
152
|
}
|
|
153
153
|
const publicKeyOutput = yield o3Wallet.getPublicKeyOutput();
|
|
154
154
|
const networkConfig = this.getNetworkConfig();
|
|
155
|
-
const scriptHash =
|
|
156
|
-
const fromAssetHash =
|
|
155
|
+
const scriptHash = Neon.u.reverseHex(token.bridgeAddress);
|
|
156
|
+
const fromAssetHash = Neon.u.reverseHex(token.tokenAddress);
|
|
157
157
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
158
158
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
159
|
-
const toAssetHash =
|
|
160
|
-
const toAddress =
|
|
159
|
+
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
160
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
161
161
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
162
162
|
if (amount.lt(feeAmount)) {
|
|
163
163
|
throw new Error("Invalid amount");
|
|
164
164
|
}
|
|
165
165
|
const data = [
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
Neon.sc.ContractParam.hash160(fromAssetHash),
|
|
167
|
+
Neon.sc.ContractParam.hash160(fromAddress),
|
|
168
|
+
Neon.sc.ContractParam.byteArray(targetProxyHash, "hex"),
|
|
169
|
+
Neon.sc.ContractParam.byteArray(toAssetHash, "hex"),
|
|
170
|
+
Neon.sc.ContractParam.byteArray(toAddress, "hex"),
|
|
171
|
+
Neon.sc.ContractParam.integer(amount.toNumber()),
|
|
172
|
+
Neon.sc.ContractParam.integer(feeAmount.toNumber()),
|
|
173
|
+
Neon.sc.ContractParam.byteArray(networkConfig.feeAddress, "hex"),
|
|
174
|
+
Neon.sc.ContractParam.integer(nonce),
|
|
175
175
|
];
|
|
176
176
|
const tx = yield o3Wallet.getDAPI().invoke({
|
|
177
177
|
scriptHash,
|
|
@@ -186,20 +186,20 @@ class NEOClient {
|
|
|
186
186
|
var _a;
|
|
187
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
188
|
const { feeAmount, address, amount, token, ledger, signCompleteCallback, } = params;
|
|
189
|
-
const compressedPublicKey =
|
|
189
|
+
const compressedPublicKey = Neon.wallet.getPublicKeyEncoded(ledger.publicKey);
|
|
190
190
|
const networkConfig = this.getNetworkConfig();
|
|
191
|
-
const scriptHash =
|
|
191
|
+
const scriptHash = Neon.u.reverseHex(token.bridgeAddress);
|
|
192
192
|
const fromAssetHash = token.tokenAddress;
|
|
193
193
|
const fromAddress = ledger.scriptHash;
|
|
194
194
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
195
|
-
const toAssetHash =
|
|
196
|
-
const toAddress =
|
|
195
|
+
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
196
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
197
197
|
const feeAddress = networkConfig.feeAddress;
|
|
198
198
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
199
199
|
if (amount.lt(feeAmount)) {
|
|
200
200
|
throw new Error("Invalid amount");
|
|
201
201
|
}
|
|
202
|
-
const sb =
|
|
202
|
+
const sb = new Neon.sc.ScriptBuilder();
|
|
203
203
|
const data = [
|
|
204
204
|
fromAssetHash,
|
|
205
205
|
fromAddress,
|
|
@@ -214,15 +214,15 @@ class NEOClient {
|
|
|
214
214
|
sb.emitAppCall(scriptHash, "lock", data);
|
|
215
215
|
const rpcUrl = yield this.getProviderUrl();
|
|
216
216
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
217
|
-
? new
|
|
218
|
-
: new
|
|
217
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
218
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
219
219
|
let invokeTxConfig = {
|
|
220
|
-
account: Object.assign(Object.assign({},
|
|
220
|
+
account: Object.assign(Object.assign({}, new Neon.wallet.Account("")), {
|
|
221
221
|
// overwrite the address and public key to values provided by the ledger.
|
|
222
222
|
address: ledger.displayAddress, publicKey: compressedPublicKey }),
|
|
223
223
|
signingFunction: (tx, publicKey) => __awaiter(this, void 0, void 0, function* () {
|
|
224
224
|
const signature = yield ledger.sign(tx);
|
|
225
|
-
const witness =
|
|
225
|
+
const witness = Neon.tx.Witness.fromSignature(signature, publicKey);
|
|
226
226
|
return witness.serialize();
|
|
227
227
|
}),
|
|
228
228
|
api: apiProvider,
|
|
@@ -233,16 +233,16 @@ class NEOClient {
|
|
|
233
233
|
};
|
|
234
234
|
// similar to Neon.doInvoke(invokeTxConfig), but
|
|
235
235
|
// separates out sendTx to broadcast to several nodes
|
|
236
|
-
invokeTxConfig = yield
|
|
237
|
-
invokeTxConfig = yield
|
|
238
|
-
invokeTxConfig = yield
|
|
239
|
-
invokeTxConfig = yield
|
|
236
|
+
invokeTxConfig = yield plugin_1.default.fillBalance(invokeTxConfig);
|
|
237
|
+
invokeTxConfig = yield plugin_1.default.createInvocationTx(invokeTxConfig);
|
|
238
|
+
invokeTxConfig = yield plugin_1.default.modifyTransactionForEmptyTransaction(invokeTxConfig);
|
|
239
|
+
invokeTxConfig = yield plugin_1.default.signTx(invokeTxConfig);
|
|
240
240
|
// provide notification to caller that signature is
|
|
241
241
|
// done and proceeding to broadcasting tx
|
|
242
242
|
if (signCompleteCallback) {
|
|
243
243
|
signCompleteCallback();
|
|
244
244
|
}
|
|
245
|
-
yield
|
|
245
|
+
yield plugin_1.default.sendTx(Object.assign(Object.assign({}, invokeTxConfig), { rpcUrl }));
|
|
246
246
|
return (_a = invokeTxConfig.tx) === null || _a === void 0 ? void 0 : _a.hash;
|
|
247
247
|
});
|
|
248
248
|
}
|
|
@@ -250,37 +250,37 @@ class NEOClient {
|
|
|
250
250
|
var _a, _b, _c, _d, _e;
|
|
251
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
252
|
const url = this.getProviderUrl();
|
|
253
|
-
const sb =
|
|
253
|
+
const sb = new Neon.sc.ScriptBuilder();
|
|
254
254
|
sb.emitAppCall(scriptHash, "symbol", []);
|
|
255
255
|
sb.emitAppCall(scriptHash, "name", []);
|
|
256
256
|
sb.emitAppCall(scriptHash, "decimals", []);
|
|
257
|
-
const response = yield
|
|
257
|
+
const response = yield Neon.rpc.Query.invokeScript(sb.str).execute(url);
|
|
258
258
|
if (((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.state) !== "HALT")
|
|
259
259
|
throw new Error("retrieve failed");
|
|
260
|
-
const symbol =
|
|
261
|
-
const name =
|
|
260
|
+
const symbol = Neon.u.hexstring2str((_b = response.result.stack) === null || _b === void 0 ? void 0 : _b[0].value);
|
|
261
|
+
const name = Neon.u.hexstring2str((_c = response.result.stack) === null || _c === void 0 ? void 0 : _c[1].value);
|
|
262
262
|
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
263
|
return { address: scriptHash, decimals, name, symbol };
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
wrapNeoToNneo(neoAmount, neoPrivateKey) {
|
|
267
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
const account =
|
|
268
|
+
const account = new Neon.wallet.Account(neoPrivateKey);
|
|
269
269
|
const rpcUrl = yield this.getProviderUrl();
|
|
270
270
|
const wrapperContractScriptHash = this.getConfig().wrapperScriptHash;
|
|
271
|
-
const wrapperContractAddress =
|
|
271
|
+
const wrapperContractAddress = Neon.wallet.getAddressFromScriptHash(wrapperContractScriptHash);
|
|
272
272
|
// Build config
|
|
273
|
-
const intent =
|
|
273
|
+
const intent = plugin_1.default.makeIntent({ NEO: neoAmount.toNumber() }, wrapperContractAddress);
|
|
274
274
|
const props = {
|
|
275
275
|
scriptHash: wrapperContractScriptHash,
|
|
276
276
|
operation: "mintTokens",
|
|
277
277
|
args: []
|
|
278
278
|
};
|
|
279
|
-
const script =
|
|
279
|
+
const script = Neon.sc.createScript(props);
|
|
280
280
|
const networkConfig = this.getNetworkConfig();
|
|
281
281
|
const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
|
|
282
|
-
? new
|
|
283
|
-
: new
|
|
282
|
+
? new plugin_1.default.neonDB.instance("https://api.switcheo.network")
|
|
283
|
+
: new plugin_1.default.neoCli.instance(rpcUrl);
|
|
284
284
|
const config = {
|
|
285
285
|
api: apiProvider,
|
|
286
286
|
url: rpcUrl,
|
|
@@ -289,19 +289,19 @@ class NEOClient {
|
|
|
289
289
|
script: script
|
|
290
290
|
};
|
|
291
291
|
// Neon API
|
|
292
|
-
const response = yield
|
|
292
|
+
const response = yield plugin_1.default.doInvoke(config);
|
|
293
293
|
return response;
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
296
|
formatWithdrawalAddress(address) {
|
|
297
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
const isValidAddress =
|
|
298
|
+
const isValidAddress = Neon.wallet.isAddress(address);
|
|
299
299
|
if (!isValidAddress) {
|
|
300
300
|
throw new Error("invalid address");
|
|
301
301
|
}
|
|
302
|
-
const scriptHash =
|
|
302
|
+
const scriptHash = Neon.wallet.getScriptHashFromAddress(address);
|
|
303
303
|
// return the little endian version of the address
|
|
304
|
-
return
|
|
304
|
+
return Neon.u.reverseHex(scriptHash);
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
307
|
/**
|
|
@@ -313,7 +313,7 @@ class NEOClient {
|
|
|
313
313
|
getTargetProxyHash(token) {
|
|
314
314
|
const networkConfig = this.getNetworkConfig();
|
|
315
315
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
316
|
-
const addressHex =
|
|
316
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
317
317
|
return addressHex;
|
|
318
318
|
}
|
|
319
319
|
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;
|