carbon-js-sdk 0.3.33 → 0.3.35-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/clients/ETHClient.js +5 -4
- package/lib/clients/ZILClient.js +4 -3
- package/lib/codec/bank/query.d.ts +2 -0
- package/lib/codec/bank/query.js +35 -6
- package/lib/constant/ibc.js +1 -0
- package/lib/constant/network.js +1 -1
- package/lib/util/blockchain.d.ts +2 -1
- package/lib/util/blockchain.js +95 -62
- package/package.json +1 -1
package/lib/clients/ETHClient.js
CHANGED
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ETHClient = exports.FEE_MULTIPLIER = void 0;
|
|
16
|
-
const CarbonSDK_1 = __importDefault(require("../CarbonSDK"));
|
|
17
16
|
const constant_1 = require("../constant");
|
|
18
17
|
const eth_1 = require("../eth");
|
|
19
18
|
const util_1 = require("../util");
|
|
@@ -91,20 +90,22 @@ class ETHClient {
|
|
|
91
90
|
const { fromToken, toToken, amount, toAddress, fromAddress, recoveryAddress, signer, gasPriceGwei, gasLimit, feeAmount, signCompleteCallback, } = params;
|
|
92
91
|
const networkConfig = this.getNetworkConfig();
|
|
93
92
|
const rpcProvider = this.getProvider();
|
|
94
|
-
|
|
93
|
+
const recoveryAddrRegex = new RegExp(`^${networkConfig.Bech32Prefix}[a-z0-9]{39}$`);
|
|
94
|
+
if (!recoveryAddress.match(recoveryAddrRegex)) {
|
|
95
95
|
throw new Error("Invalid recovery address");
|
|
96
96
|
}
|
|
97
|
+
const carbonNetwork = networkConfig.network;
|
|
97
98
|
const fromTokenId = fromToken.id;
|
|
98
99
|
const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
|
|
99
100
|
const toTokenDenom = toToken.denom;
|
|
100
|
-
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress,
|
|
101
|
+
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
101
102
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
102
103
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
103
104
|
const nonce = yield rpcProvider.getTransactionCount(fromAddress);
|
|
104
105
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
105
106
|
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
106
107
|
const tokenCreator = fromToken.creator;
|
|
107
|
-
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator,
|
|
108
|
+
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
|
|
108
109
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
109
110
|
const ethAmount = fromToken.tokenAddress === constant_1.NativeTokenHash ? amount : number_1.BN_ZERO;
|
|
110
111
|
const bridgeResultTx = yield contract.connect(signer).lock(fromTokenAddress, // the asset to deposit (from) (0x00 if eth)
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ZILClient = exports.balanceBatchRequest = exports.tokenBalanceBatchRequest = exports.BatchRequestType = void 0;
|
|
16
|
-
const CarbonSDK_1 = __importDefault(require("../CarbonSDK"));
|
|
17
16
|
const index_1 = require("../index");
|
|
18
17
|
const address_1 = require("../util/address");
|
|
19
18
|
const blockchain_1 = require("../util/blockchain");
|
|
@@ -201,14 +200,16 @@ class ZILClient {
|
|
|
201
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
201
|
const { fromToken, toToken, amount, fromAddress, recoveryAddress, toAddress, signer, gasPrice, gasLimit, feeAmount, signCompleteCallback, } = params;
|
|
203
202
|
const networkConfig = this.getNetworkConfig();
|
|
204
|
-
|
|
203
|
+
const recoveryAddrRegex = new RegExp(`^${networkConfig.Bech32Prefix}[a-z0-9]{39}$`);
|
|
204
|
+
if (!recoveryAddress.match(recoveryAddrRegex)) {
|
|
205
205
|
throw new Error("Invalid recovery address");
|
|
206
206
|
}
|
|
207
|
+
const carbonNetwork = networkConfig.network;
|
|
207
208
|
const fromTokenId = fromToken.id;
|
|
208
209
|
const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
|
|
209
210
|
const toTokenDenom = toToken.denom;
|
|
210
211
|
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
|
|
211
|
-
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress,
|
|
212
|
+
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
212
213
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
213
214
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
214
215
|
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
package/lib/codec/bank/query.js
CHANGED
|
@@ -109,17 +109,28 @@ exports.InternalTransfer = {
|
|
|
109
109
|
return message;
|
|
110
110
|
},
|
|
111
111
|
};
|
|
112
|
-
const baseQueryInternalTransfersRequest = {
|
|
112
|
+
const baseQueryInternalTransfersRequest = {
|
|
113
|
+
address: "",
|
|
114
|
+
sender: "",
|
|
115
|
+
receiver: "",
|
|
116
|
+
denom: "",
|
|
117
|
+
};
|
|
113
118
|
exports.QueryInternalTransfersRequest = {
|
|
114
119
|
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
115
120
|
if (message.address !== "") {
|
|
116
121
|
writer.uint32(10).string(message.address);
|
|
117
122
|
}
|
|
123
|
+
if (message.sender !== "") {
|
|
124
|
+
writer.uint32(18).string(message.sender);
|
|
125
|
+
}
|
|
126
|
+
if (message.receiver !== "") {
|
|
127
|
+
writer.uint32(26).string(message.receiver);
|
|
128
|
+
}
|
|
118
129
|
if (message.denom !== "") {
|
|
119
|
-
writer.uint32(
|
|
130
|
+
writer.uint32(34).string(message.denom);
|
|
120
131
|
}
|
|
121
132
|
if (message.pagination !== undefined) {
|
|
122
|
-
pagination_1.PageRequest.encode(message.pagination, writer.uint32(
|
|
133
|
+
pagination_1.PageRequest.encode(message.pagination, writer.uint32(42).fork()).ldelim();
|
|
123
134
|
}
|
|
124
135
|
return writer;
|
|
125
136
|
},
|
|
@@ -134,9 +145,15 @@ exports.QueryInternalTransfersRequest = {
|
|
|
134
145
|
message.address = reader.string();
|
|
135
146
|
break;
|
|
136
147
|
case 2:
|
|
137
|
-
message.
|
|
148
|
+
message.sender = reader.string();
|
|
138
149
|
break;
|
|
139
150
|
case 3:
|
|
151
|
+
message.receiver = reader.string();
|
|
152
|
+
break;
|
|
153
|
+
case 4:
|
|
154
|
+
message.denom = reader.string();
|
|
155
|
+
break;
|
|
156
|
+
case 5:
|
|
140
157
|
message.pagination = pagination_1.PageRequest.decode(reader, reader.uint32());
|
|
141
158
|
break;
|
|
142
159
|
default:
|
|
@@ -152,6 +169,14 @@ exports.QueryInternalTransfersRequest = {
|
|
|
152
169
|
object.address !== undefined && object.address !== null
|
|
153
170
|
? String(object.address)
|
|
154
171
|
: "";
|
|
172
|
+
message.sender =
|
|
173
|
+
object.sender !== undefined && object.sender !== null
|
|
174
|
+
? String(object.sender)
|
|
175
|
+
: "";
|
|
176
|
+
message.receiver =
|
|
177
|
+
object.receiver !== undefined && object.receiver !== null
|
|
178
|
+
? String(object.receiver)
|
|
179
|
+
: "";
|
|
155
180
|
message.denom =
|
|
156
181
|
object.denom !== undefined && object.denom !== null
|
|
157
182
|
? String(object.denom)
|
|
@@ -165,6 +190,8 @@ exports.QueryInternalTransfersRequest = {
|
|
|
165
190
|
toJSON(message) {
|
|
166
191
|
const obj = {};
|
|
167
192
|
message.address !== undefined && (obj.address = message.address);
|
|
193
|
+
message.sender !== undefined && (obj.sender = message.sender);
|
|
194
|
+
message.receiver !== undefined && (obj.receiver = message.receiver);
|
|
168
195
|
message.denom !== undefined && (obj.denom = message.denom);
|
|
169
196
|
message.pagination !== undefined &&
|
|
170
197
|
(obj.pagination = message.pagination
|
|
@@ -173,10 +200,12 @@ exports.QueryInternalTransfersRequest = {
|
|
|
173
200
|
return obj;
|
|
174
201
|
},
|
|
175
202
|
fromPartial(object) {
|
|
176
|
-
var _a, _b;
|
|
203
|
+
var _a, _b, _c, _d;
|
|
177
204
|
const message = Object.assign({}, baseQueryInternalTransfersRequest);
|
|
178
205
|
message.address = (_a = object.address) !== null && _a !== void 0 ? _a : "";
|
|
179
|
-
message.
|
|
206
|
+
message.sender = (_b = object.sender) !== null && _b !== void 0 ? _b : "";
|
|
207
|
+
message.receiver = (_c = object.receiver) !== null && _c !== void 0 ? _c : "";
|
|
208
|
+
message.denom = (_d = object.denom) !== null && _d !== void 0 ? _d : "";
|
|
180
209
|
message.pagination =
|
|
181
210
|
object.pagination !== undefined && object.pagination !== null
|
|
182
211
|
? pagination_1.PageRequest.fromPartial(object.pagination)
|
package/lib/constant/ibc.js
CHANGED
package/lib/constant/network.js
CHANGED
|
@@ -125,7 +125,7 @@ exports.NetworkConfigs = {
|
|
|
125
125
|
networkMagic: neon_core_next_1.CONST.MAGIC_NUMBER.TestNet,
|
|
126
126
|
},
|
|
127
127
|
zil: {
|
|
128
|
-
rpcURL: "",
|
|
128
|
+
rpcURL: "https://dev-api.zilliqa.com",
|
|
129
129
|
lockProxyAddr: "0xe7bef341044f1b8d5ab1a25172e2678a1e75479a",
|
|
130
130
|
bridgeEntranceAddr: "0xccf798e633d6fb6505b494fc010903f9be3bc99b",
|
|
131
131
|
chainId: 111,
|
package/lib/util/blockchain.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Network } from "../constant/network";
|
|
1
2
|
import { SimpleMap } from "./type";
|
|
2
3
|
export declare enum Blockchain {
|
|
3
4
|
Neo = "neo",
|
|
@@ -54,4 +55,4 @@ export declare const chainIdsByBlockchain: SimpleMap<ChainIds>;
|
|
|
54
55
|
export declare function parseBlockchain(value: string | null): Blockchain | null;
|
|
55
56
|
export declare function getChainFromID(id: number): string | undefined;
|
|
56
57
|
export declare const getBlockchainFromChain: (chainId?: number | undefined) => Blockchain.Ethereum | Blockchain.BinanceSmartChain | Blockchain.Zilliqa | Blockchain.Arbitrum | undefined;
|
|
57
|
-
export declare const blockchainForChainId: (chainId?: number | undefined) => Blockchain | undefined;
|
|
58
|
+
export declare const blockchainForChainId: (chainId?: number | undefined, network?: Network) => Blockchain | undefined;
|
package/lib/util/blockchain.js
CHANGED
|
@@ -127,68 +127,101 @@ const getBlockchainFromChain = (chainId) => {
|
|
|
127
127
|
return undefined;
|
|
128
128
|
};
|
|
129
129
|
exports.getBlockchainFromChain = getBlockchainFromChain;
|
|
130
|
-
const blockchainForChainId = (chainId) => {
|
|
131
|
-
switch (
|
|
132
|
-
case
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
130
|
+
const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
131
|
+
switch (network) {
|
|
132
|
+
case network_1.Network.MainNet:
|
|
133
|
+
switch (chainId) {
|
|
134
|
+
case 0:
|
|
135
|
+
return Blockchain.Native;
|
|
136
|
+
case 1:
|
|
137
|
+
return Blockchain.Btc;
|
|
138
|
+
case 2:
|
|
139
|
+
return Blockchain.Ethereum;
|
|
140
|
+
case 4:
|
|
141
|
+
return Blockchain.Neo;
|
|
142
|
+
case 6:
|
|
143
|
+
return Blockchain.BinanceSmartChain;
|
|
144
|
+
case 14:
|
|
145
|
+
return Blockchain.Neo3;
|
|
146
|
+
case 9: /* FALLTHROUGH */
|
|
147
|
+
case 18:
|
|
148
|
+
return Blockchain.Zilliqa;
|
|
149
|
+
case 244:
|
|
150
|
+
return Blockchain.Osmosis;
|
|
151
|
+
case 13: /* FALLTHROUGH */
|
|
152
|
+
case 245:
|
|
153
|
+
return Blockchain.Terra;
|
|
154
|
+
case 246:
|
|
155
|
+
return Blockchain.CosmosHub;
|
|
156
|
+
case 5: /* FALLTHROUGH */
|
|
157
|
+
case 247:
|
|
158
|
+
return Blockchain.Juno;
|
|
159
|
+
case 7: /* FALLTHROUGH */
|
|
160
|
+
case 248:
|
|
161
|
+
return Blockchain.Evmos;
|
|
162
|
+
case 8: /* FALLTHROUGH */
|
|
163
|
+
case 249:
|
|
164
|
+
return Blockchain.Axelar;
|
|
165
|
+
case 313:
|
|
166
|
+
return Blockchain.Stride;
|
|
167
|
+
case 314:
|
|
168
|
+
return Blockchain.Kujira;
|
|
169
|
+
case 315:
|
|
170
|
+
return Blockchain.Terra2;
|
|
171
|
+
case 316:
|
|
172
|
+
return Blockchain.Quicksilver;
|
|
173
|
+
case 12: /* FALLTHROUGH */
|
|
174
|
+
case 317:
|
|
175
|
+
return Blockchain.Comdex;
|
|
176
|
+
case 318:
|
|
177
|
+
return Blockchain.StafiHub;
|
|
178
|
+
case 15: /* FALLTHROUGH */
|
|
179
|
+
case 319:
|
|
180
|
+
return Blockchain.Persistence;
|
|
181
|
+
case 16: /* FALLTHROUGH */
|
|
182
|
+
case 320:
|
|
183
|
+
return Blockchain.Stargaze;
|
|
184
|
+
case 321:
|
|
185
|
+
return Blockchain.Canto;
|
|
186
|
+
case 322:
|
|
187
|
+
return Blockchain.OmniFlixHub;
|
|
188
|
+
case 323:
|
|
189
|
+
return Blockchain.Agoric;
|
|
190
|
+
case 19: /* FALLTHROUGH */
|
|
191
|
+
case 42161:
|
|
192
|
+
return Blockchain.Arbitrum;
|
|
193
|
+
default:
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
case network_1.Network.TestNet:
|
|
197
|
+
switch (chainId) {
|
|
198
|
+
case 1:
|
|
199
|
+
return Blockchain.Btc;
|
|
200
|
+
case 5:
|
|
201
|
+
return Blockchain.Carbon;
|
|
202
|
+
case 79:
|
|
203
|
+
return Blockchain.BinanceSmartChain;
|
|
204
|
+
case 88:
|
|
205
|
+
return Blockchain.Neo3;
|
|
206
|
+
case 111:
|
|
207
|
+
return Blockchain.Zilliqa;
|
|
208
|
+
case 2: /* FALLTHROUGH */
|
|
209
|
+
case 502:
|
|
210
|
+
return Blockchain.Ethereum;
|
|
211
|
+
default:
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
case network_1.Network.DevNet:
|
|
215
|
+
switch (chainId) {
|
|
216
|
+
case 350:
|
|
217
|
+
return Blockchain.Ethereum;
|
|
218
|
+
case 5:
|
|
219
|
+
return Blockchain.Neo;
|
|
220
|
+
case 79:
|
|
221
|
+
return Blockchain.BinanceSmartChain;
|
|
222
|
+
}
|
|
223
|
+
case network_1.Network.LocalHost:
|
|
224
|
+
return undefined;
|
|
192
225
|
default:
|
|
193
226
|
return undefined;
|
|
194
227
|
}
|