carbon-js-sdk 0.3.16 → 0.3.17-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/CarbonSDK.d.ts +5 -1
- package/lib/CarbonSDK.js +24 -4
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/cdp/tx.d.ts +57 -1
- package/lib/codec/cdp/tx.js +367 -1
- 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/codec/index.d.ts +5 -1
- package/lib/codec/index.js +23 -11
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.js +41 -41
- package/lib/constant/network.d.ts +6 -0
- package/lib/constant/network.js +7 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/modules/cdp.d.ts +20 -0
- package/lib/modules/cdp.js +81 -43
- 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 +30 -30
- 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 +22 -22
- 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/index.d.ts +1 -0
- package/lib/provider/index.js +3 -1
- package/lib/provider/keplr/KeplrStore.d.ts +9 -3
- package/lib/provider/keplr/KeplrStore.js +69 -18
- package/lib/provider/leap/LeapAccount.d.ts +10 -0
- package/lib/provider/leap/LeapAccount.js +45 -0
- package/lib/provider/leap/index.d.ts +3 -0
- package/lib/provider/leap/index.js +8 -0
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/o3/O3Wallet.js +2 -2
- 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/util/tx.d.ts +4 -0
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.d.ts +3 -0
- package/lib/wallet/CarbonWallet.js +12 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +8 -4
package/lib/CarbonSDK.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as clients from "./clients";
|
|
|
6
6
|
import N3Client from "./clients/N3Client";
|
|
7
7
|
import { AdminModule, BankModule, BrokerModule, CDPModule, CoinModule, FeeModule, GovModule, IBCModule, LeverageModule, LiquidityPoolModule, MarketModule, OracleModule, OrderModule, PositionModule, ProfileModule, SubAccountModule, XChainModule } from "./modules";
|
|
8
8
|
import { StakingModule } from "./modules/staking";
|
|
9
|
-
import { CosmosLedger, Keplr } from "./provider";
|
|
9
|
+
import { CosmosLedger, Keplr, Leap } from "./provider";
|
|
10
10
|
import { CarbonSigner, CarbonWallet, CarbonWalletGenericOpts } from "./wallet";
|
|
11
11
|
export { CarbonTx } from "./util";
|
|
12
12
|
export { CarbonSigner, CarbonSignerTypes, CarbonWallet, CarbonWalletGenericOpts, CarbonWalletInitOpts } from "./wallet";
|
|
@@ -14,6 +14,7 @@ export { DenomPrefix } from "./constant";
|
|
|
14
14
|
export interface CarbonSDKOpts {
|
|
15
15
|
network: Network;
|
|
16
16
|
tmClient: Tendermint34Client;
|
|
17
|
+
chainId?: string;
|
|
17
18
|
token?: TokenClient;
|
|
18
19
|
config?: Partial<NetworkConfig>;
|
|
19
20
|
defaultTimeoutBlocks?: number;
|
|
@@ -69,6 +70,7 @@ declare class CarbonSDK {
|
|
|
69
70
|
bsc: ETHClient;
|
|
70
71
|
zil: ZILClient;
|
|
71
72
|
n3: N3Client;
|
|
73
|
+
chainId: string;
|
|
72
74
|
constructor(opts: CarbonSDKOpts);
|
|
73
75
|
static instance(opts?: CarbonSDKInitOpts): Promise<CarbonSDK>;
|
|
74
76
|
static instanceWithWallet(wallet: CarbonWallet, sdkOpts?: CarbonSDKInitOpts): Promise<ConnectedCarbonSDK>;
|
|
@@ -77,6 +79,7 @@ declare class CarbonSDK {
|
|
|
77
79
|
static instanceWithSigner(signer: CarbonSigner, publicKeyBase64: string, sdkOpts?: CarbonSDKInitOpts, walletOpts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
78
80
|
static instanceWithLedger(ledger: CosmosLedger, sdkOpts?: CarbonSDKInitOpts, walletOpts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
79
81
|
static instanceWithKeplr(keplr: Keplr, sdkOpts?: CarbonSDKInitOpts, walletOpts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
82
|
+
static instanceWithLeap(leap: Leap, sdkOpts?: CarbonSDKInitOpts, walletOpts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
80
83
|
static instanceViewOnly(bech32Address: string, sdkOpts?: CarbonSDKInitOpts, walletOpts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
81
84
|
initialize(): Promise<CarbonSDK>;
|
|
82
85
|
clone(): CarbonSDK;
|
|
@@ -88,6 +91,7 @@ declare class CarbonSDK {
|
|
|
88
91
|
connectWithSigner(signer: CarbonSigner, publicKeyBase64: string, opts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
89
92
|
connectWithLedger(ledger: CosmosLedger, opts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
90
93
|
connectWithKeplr(keplr: Keplr, opts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
94
|
+
connectWithLeap(leap: Leap, opts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
91
95
|
connectViewOnly(bech32Address: string, opts?: CarbonWalletGenericOpts): Promise<ConnectedCarbonSDK>;
|
|
92
96
|
getConfig(): NetworkConfig;
|
|
93
97
|
getTokenClient(): TokenClient;
|
package/lib/CarbonSDK.js
CHANGED
|
@@ -60,15 +60,16 @@ const DEFAULT_SDK_INIT_OPTS = {
|
|
|
60
60
|
*/
|
|
61
61
|
class CarbonSDK {
|
|
62
62
|
constructor(opts) {
|
|
63
|
-
var _a, _b, _c;
|
|
63
|
+
var _a, _b, _c, _d, _e;
|
|
64
64
|
this.network = (_a = opts.network) !== null && _a !== void 0 ? _a : constant_1.DEFAULT_NETWORK;
|
|
65
65
|
this.configOverride = (_b = opts.config) !== null && _b !== void 0 ? _b : {};
|
|
66
66
|
this.networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[this.network], this.configOverride);
|
|
67
67
|
this.tmClient = opts.tmClient;
|
|
68
|
+
this.chainId = (_d = (_c = opts.chainId) !== null && _c !== void 0 ? _c : constant_1.CarbonChainIDs[this.network]) !== null && _d !== void 0 ? _d : constant_1.CarbonChainIDs[constant_1.Network.MainNet];
|
|
68
69
|
this.query = new clients_1.CarbonQueryClient(opts.tmClient);
|
|
69
70
|
this.insights = new clients_1.InsightsQueryClient(this.networkConfig);
|
|
70
71
|
this.hydrogen = new clients_1.HydrogenClient(this.networkConfig);
|
|
71
|
-
this.token = (
|
|
72
|
+
this.token = (_e = opts.token) !== null && _e !== void 0 ? _e : clients_1.TokenClient.instance(this.query, this);
|
|
72
73
|
this.admin = new modules_1.AdminModule(this);
|
|
73
74
|
this.order = new modules_1.OrderModule(this);
|
|
74
75
|
this.lp = new modules_1.LiquidityPoolModule(this);
|
|
@@ -111,14 +112,15 @@ class CarbonSDK {
|
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
static instance(opts = DEFAULT_SDK_INIT_OPTS) {
|
|
114
|
-
var _a, _b, _c;
|
|
115
|
+
var _a, _b, _c, _d;
|
|
115
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
117
|
const network = (_a = opts.network) !== null && _a !== void 0 ? _a : constant_1.DEFAULT_NETWORK;
|
|
117
118
|
const configOverride = (_b = opts.config) !== null && _b !== void 0 ? _b : {};
|
|
118
119
|
const networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[network], configOverride);
|
|
119
120
|
const tmClient = (_c = opts.tmClient) !== null && _c !== void 0 ? _c : util_1.GenericUtils.modifyTmClient(yield tendermint_rpc_1.Tendermint34Client.connect(networkConfig.tmRpcUrl));
|
|
120
121
|
const defaultTimeoutBlocks = opts.defaultTimeoutBlocks;
|
|
121
|
-
const
|
|
122
|
+
const chainId = (_d = (yield tmClient.status())) === null || _d === void 0 ? void 0 : _d.nodeInfo.network;
|
|
123
|
+
const sdk = new CarbonSDK({ network, config: configOverride, tmClient, defaultTimeoutBlocks, chainId });
|
|
122
124
|
if (opts.wallet) {
|
|
123
125
|
yield sdk.connect(opts.wallet);
|
|
124
126
|
}
|
|
@@ -164,6 +166,12 @@ class CarbonSDK {
|
|
|
164
166
|
return sdk.connectWithKeplr(keplr, walletOpts);
|
|
165
167
|
});
|
|
166
168
|
}
|
|
169
|
+
static instanceWithLeap(leap, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const sdk = yield CarbonSDK.instance(sdkOpts);
|
|
172
|
+
return sdk.connectWithLeap(leap, walletOpts);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
167
175
|
static instanceViewOnly(bech32Address, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
168
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
177
|
const sdk = yield CarbonSDK.instance(sdkOpts);
|
|
@@ -172,6 +180,8 @@ class CarbonSDK {
|
|
|
172
180
|
}
|
|
173
181
|
initialize() {
|
|
174
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
const chainId = yield this.query.chain.getChainId();
|
|
184
|
+
this.chainId = chainId;
|
|
175
185
|
yield this.token.initialize();
|
|
176
186
|
if (this.wallet) {
|
|
177
187
|
yield this.wallet.initialize(this.query);
|
|
@@ -187,6 +197,7 @@ class CarbonSDK {
|
|
|
187
197
|
network: this.network,
|
|
188
198
|
config: this.configOverride,
|
|
189
199
|
tmClient: this.tmClient,
|
|
200
|
+
chainId: this.chainId,
|
|
190
201
|
};
|
|
191
202
|
}
|
|
192
203
|
connect(wallet) {
|
|
@@ -249,6 +260,15 @@ class CarbonSDK {
|
|
|
249
260
|
return this.connect(wallet);
|
|
250
261
|
});
|
|
251
262
|
}
|
|
263
|
+
connectWithLeap(leap, opts) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
const chainId = this.chainId;
|
|
266
|
+
const leapKey = yield leap.getKey(chainId);
|
|
267
|
+
yield leap.enable(chainId);
|
|
268
|
+
const wallet = wallet_1.CarbonWallet.withLeap(leap, chainId, leapKey, Object.assign(Object.assign({}, opts), { network: this.network, config: this.configOverride }));
|
|
269
|
+
return this.connect(wallet);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
252
272
|
connectViewOnly(bech32Address, opts) {
|
|
253
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
274
|
const wallet = wallet_1.CarbonWallet.withAddress(bech32Address, Object.assign(Object.assign({}, opts), { network: this.network, config: this.configOverride }));
|
|
@@ -44,7 +44,7 @@ class CarbonQueryClient {
|
|
|
44
44
|
constructor(tmClient) {
|
|
45
45
|
this.tmClient = tmClient;
|
|
46
46
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
47
|
-
const rpcClient =
|
|
47
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
48
48
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
49
49
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
50
50
|
this.book = new query_2.QueryClientImpl(rpcClient);
|
|
@@ -85,7 +85,7 @@ class CarbonQueryClient {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
getProtobufRpcClient() {
|
|
88
|
-
return
|
|
88
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
exports.default = CarbonQueryClient;
|
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.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.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
|
@@ -64,13 +64,13 @@ class NEOClient {
|
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
65
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
66
66
|
const account = new Neon.wallet.Account(address);
|
|
67
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
67
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
68
68
|
token.tokenAddress.length == 40 &&
|
|
69
69
|
token.bridgeAddress.length == 40);
|
|
70
70
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
71
71
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
72
72
|
// the gas limit on the RPC node and error out otherwise
|
|
73
|
-
const promises =
|
|
73
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
74
74
|
var _a, _b, _c;
|
|
75
75
|
let acc = {};
|
|
76
76
|
for (const token of partition) {
|
|
@@ -111,8 +111,8 @@ class NEOClient {
|
|
|
111
111
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
112
112
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
113
113
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
114
|
-
const toAddress =
|
|
115
|
-
const zeroAddressHex =
|
|
114
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
115
|
+
const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
|
|
116
116
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
117
117
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
118
118
|
const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
|
|
@@ -159,7 +159,7 @@ class NEOClient {
|
|
|
159
159
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
160
160
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
161
161
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
162
|
-
const toAddress =
|
|
162
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
163
163
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
164
164
|
if (amount.lt(feeAmount)) {
|
|
165
165
|
throw new Error("Invalid amount");
|
|
@@ -195,7 +195,7 @@ class NEOClient {
|
|
|
195
195
|
const fromAddress = ledger.scriptHash;
|
|
196
196
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
197
197
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
198
|
-
const toAddress =
|
|
198
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
199
199
|
const feeAddress = networkConfig.feeAddress;
|
|
200
200
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
201
201
|
if (amount.lt(feeAmount)) {
|
|
@@ -315,7 +315,7 @@ class NEOClient {
|
|
|
315
315
|
getTargetProxyHash(token) {
|
|
316
316
|
const networkConfig = this.getNetworkConfig();
|
|
317
317
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
318
|
-
const addressHex =
|
|
318
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
319
319
|
return addressHex;
|
|
320
320
|
}
|
|
321
321
|
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() {
|
package/lib/codec/cdp/tx.d.ts
CHANGED
|
@@ -266,6 +266,30 @@ export interface MsgReturnStablecoinWithInterestInCdpTokens {
|
|
|
266
266
|
}
|
|
267
267
|
export interface MsgReturnStablecoinWithInterestInCdpTokensResponse {
|
|
268
268
|
}
|
|
269
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens {
|
|
270
|
+
creator: string;
|
|
271
|
+
debtor: string;
|
|
272
|
+
collateralDenom: string;
|
|
273
|
+
minCollateralAmount: string;
|
|
274
|
+
debtDenom: string;
|
|
275
|
+
debtAmount: string;
|
|
276
|
+
interestCdpDenom: string;
|
|
277
|
+
interestCdpAmount: string;
|
|
278
|
+
}
|
|
279
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse {
|
|
280
|
+
}
|
|
281
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCollateral {
|
|
282
|
+
creator: string;
|
|
283
|
+
debtor: string;
|
|
284
|
+
collateralDenom: string;
|
|
285
|
+
minCollateralAmount: string;
|
|
286
|
+
debtDenom: string;
|
|
287
|
+
debtAmount: string;
|
|
288
|
+
interestCdpDenom: string;
|
|
289
|
+
interestCdpAmount: string;
|
|
290
|
+
}
|
|
291
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse {
|
|
292
|
+
}
|
|
269
293
|
export declare const MsgAddRateStrategy: {
|
|
270
294
|
encode(message: MsgAddRateStrategy, writer?: _m0.Writer): _m0.Writer;
|
|
271
295
|
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgAddRateStrategy;
|
|
@@ -756,6 +780,34 @@ export declare const MsgReturnStablecoinWithInterestInCdpTokensResponse: {
|
|
|
756
780
|
toJSON(_: MsgReturnStablecoinWithInterestInCdpTokensResponse): unknown;
|
|
757
781
|
fromPartial(_: DeepPartial<MsgReturnStablecoinWithInterestInCdpTokensResponse>): MsgReturnStablecoinWithInterestInCdpTokensResponse;
|
|
758
782
|
};
|
|
783
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens: {
|
|
784
|
+
encode(message: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens, writer?: _m0.Writer): _m0.Writer;
|
|
785
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
786
|
+
fromJSON(object: any): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
787
|
+
toJSON(message: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): unknown;
|
|
788
|
+
fromPartial(object: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens>): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
789
|
+
};
|
|
790
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse: {
|
|
791
|
+
encode(_: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse, writer?: _m0.Writer): _m0.Writer;
|
|
792
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
793
|
+
fromJSON(_: any): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
794
|
+
toJSON(_: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse): unknown;
|
|
795
|
+
fromPartial(_: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
796
|
+
};
|
|
797
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCollateral: {
|
|
798
|
+
encode(message: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral, writer?: _m0.Writer): _m0.Writer;
|
|
799
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
800
|
+
fromJSON(object: any): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
801
|
+
toJSON(message: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): unknown;
|
|
802
|
+
fromPartial(object: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCollateral>): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
803
|
+
};
|
|
804
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse: {
|
|
805
|
+
encode(_: MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse, writer?: _m0.Writer): _m0.Writer;
|
|
806
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
807
|
+
fromJSON(_: any): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
808
|
+
toJSON(_: MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse): unknown;
|
|
809
|
+
fromPartial(_: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
810
|
+
};
|
|
759
811
|
/** Msg defines the Msg service. */
|
|
760
812
|
export interface Msg {
|
|
761
813
|
AddRateStrategy(request: MsgAddRateStrategy): Promise<MsgAddRateStrategyResponse>;
|
|
@@ -792,8 +844,10 @@ export interface Msg {
|
|
|
792
844
|
SetStalePriceGracePeriod(request: MsgSetStalePriceGracePeriod): Promise<MsgSetStalePriceGracePeriodResponse>;
|
|
793
845
|
SetCdpPaused(request: MsgSetCdpPaused): Promise<MsgSetCdpPausedResponse>;
|
|
794
846
|
ReturnStablecoinWithInterestInCdpTokens(request: MsgReturnStablecoinWithInterestInCdpTokens): Promise<MsgReturnStablecoinWithInterestInCdpTokensResponse>;
|
|
795
|
-
/** this line is used by starport scaffolding # proto/tx/rpc */
|
|
796
847
|
ReturnStablecoinWithInterestInCollateral(request: MsgReturnStablecoinWithInterestInCollateral): Promise<MsgReturnStablecoinWithInterestInCollateralResponse>;
|
|
848
|
+
LiquidateCollateralWithStablecoinAndInterestInCdpTokens(request: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>;
|
|
849
|
+
/** this line is used by starport scaffolding # proto/tx/rpc */
|
|
850
|
+
LiquidateCollateralWithStablecoinAndInterestInCollateral(request: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>;
|
|
797
851
|
}
|
|
798
852
|
export declare class MsgClientImpl implements Msg {
|
|
799
853
|
private readonly rpc;
|
|
@@ -833,6 +887,8 @@ export declare class MsgClientImpl implements Msg {
|
|
|
833
887
|
SetCdpPaused(request: MsgSetCdpPaused): Promise<MsgSetCdpPausedResponse>;
|
|
834
888
|
ReturnStablecoinWithInterestInCdpTokens(request: MsgReturnStablecoinWithInterestInCdpTokens): Promise<MsgReturnStablecoinWithInterestInCdpTokensResponse>;
|
|
835
889
|
ReturnStablecoinWithInterestInCollateral(request: MsgReturnStablecoinWithInterestInCollateral): Promise<MsgReturnStablecoinWithInterestInCollateralResponse>;
|
|
890
|
+
LiquidateCollateralWithStablecoinAndInterestInCdpTokens(request: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>;
|
|
891
|
+
LiquidateCollateralWithStablecoinAndInterestInCollateral(request: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>;
|
|
836
892
|
}
|
|
837
893
|
interface Rpc {
|
|
838
894
|
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|