carbon-js-sdk 0.3.45 → 0.3.47
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/constant/ibc.js +6 -0
- package/lib/modules/cdp.d.ts +13 -2
- package/lib/modules/cdp.js +47 -18
- package/lib/modules/cosmwasm.d.ts +16 -0
- package/lib/modules/cosmwasm.js +67 -0
- package/lib/util/ibc.js +10 -1
- package/package.json +1 -1
package/lib/constant/ibc.js
CHANGED
|
@@ -148,6 +148,12 @@ exports.EmbedChainInfosInit = {
|
|
|
148
148
|
coinDecimals: 6,
|
|
149
149
|
coinGeckoId: "ion",
|
|
150
150
|
},
|
|
151
|
+
{
|
|
152
|
+
coinDenom: "axlUSDC",
|
|
153
|
+
coinMinimalDenom: "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858",
|
|
154
|
+
coinDecimals: 6,
|
|
155
|
+
coinGeckoId: "usd-coin",
|
|
156
|
+
},
|
|
151
157
|
],
|
|
152
158
|
feeCurrencies: [
|
|
153
159
|
{
|
package/lib/modules/cdp.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="long" />
|
|
2
2
|
import { AssetParams, DebtInfo, RateStrategyParams, StablecoinDebtInfo } from "../codec";
|
|
3
|
+
import { Params } from "../codec/cdp/params";
|
|
3
4
|
import { CarbonTx } from "../util";
|
|
4
5
|
import { BigNumber } from "bignumber.js";
|
|
5
6
|
import { Debt } from "./../codec/cdp/query";
|
|
6
7
|
import BaseModule from "./base";
|
|
7
|
-
import { Params } from "../codec/cdp/params";
|
|
8
8
|
export declare class CDPModule extends BaseModule {
|
|
9
9
|
private cdpModuleAddress;
|
|
10
10
|
supplyAsset(params: CDPModule.SupplyAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
@@ -12,13 +12,19 @@ export declare class CDPModule extends BaseModule {
|
|
|
12
12
|
lockCollateral(params: CDPModule.LockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
13
13
|
unlockCollateral(params: CDPModule.UnlockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
14
14
|
borrowAsset(params: CDPModule.BorrowAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
15
|
-
repayAsset(params: CDPModule.RepayAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
16
15
|
supplyAssetAndLockCollateral(params: CDPModule.SupplyAssetAndLockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
17
16
|
unlockCollateralAndWithdrawAsset(params: CDPModule.UnlockCollateralAndWithdrawAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
18
17
|
liquidateCollateral(params: CDPModule.LiquidateCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
19
18
|
liquidateCollateralWithCdpTokens(params: CDPModule.LiquidateCollateralWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
20
19
|
liquidateCollateralWithCollateral(params: CDPModule.LiquidateCollateralWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
21
20
|
liquidateCollateralWithStablecoin(params: CDPModule.LiquidateCollateralWithStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
21
|
+
repayAsset(params: CDPModule.RepayAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Uses grouped token balance to repay for existing CDP asset debt.
|
|
24
|
+
* Calls 2 msg in 1 tx, MsgWithdrawFromGroup and MsgRepayAsset.
|
|
25
|
+
* Ensure that grouped token balance is sufficient.
|
|
26
|
+
*/
|
|
27
|
+
repayAssetWithGroupedToken(params: CDPModule.RepayAssetWithGroupedToken, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
22
28
|
repayAssetWithCdpTokens(params: CDPModule.RepayAssetWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
23
29
|
repayAssetWithCollateral(params: CDPModule.RepayAssetWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
24
30
|
mintStablecoin(params: CDPModule.MintStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
@@ -162,6 +168,11 @@ export declare namespace CDPModule {
|
|
|
162
168
|
cdpDenom: string;
|
|
163
169
|
cdpAmount: BigNumber;
|
|
164
170
|
}
|
|
171
|
+
interface RepayAssetWithGroupedToken {
|
|
172
|
+
denom: string;
|
|
173
|
+
amount: BigNumber;
|
|
174
|
+
debtor?: string;
|
|
175
|
+
}
|
|
165
176
|
interface RepayAssetWithCollateralParams {
|
|
166
177
|
debtor?: string;
|
|
167
178
|
debtDenom: string;
|
package/lib/modules/cdp.js
CHANGED
|
@@ -13,18 +13,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CDPModule = void 0;
|
|
16
|
+
const TokenClient_1 = __importDefault(require("../clients/TokenClient"));
|
|
16
17
|
const codec_1 = require("../codec");
|
|
17
18
|
const query_1 = require("../codec/cdp/query");
|
|
18
19
|
const tx_1 = require("../codec/cdp/tx");
|
|
19
20
|
const query_2 = require("../codec/cosmos/bank/v1beta1/query");
|
|
21
|
+
const constant_1 = require("../constant");
|
|
20
22
|
const util_1 = require("../util");
|
|
23
|
+
const address_1 = require("../util/address");
|
|
21
24
|
const number_1 = require("../util/number");
|
|
22
25
|
const bignumber_js_1 = require("bignumber.js");
|
|
23
26
|
const query_3 = require("./../codec/cdp/query");
|
|
24
27
|
const base_1 = __importDefault(require("./base"));
|
|
25
|
-
const constant_1 = require("../constant");
|
|
26
|
-
const TokenClient_1 = __importDefault(require("../clients/TokenClient"));
|
|
27
|
-
const address_1 = require("../util/address");
|
|
28
28
|
class CDPModule extends base_1.default {
|
|
29
29
|
supplyAsset(params, opts) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,21 +96,6 @@ class CDPModule extends base_1.default {
|
|
|
96
96
|
}, opts);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
repayAsset(params, opts) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const wallet = this.getWallet();
|
|
102
|
-
const value = tx_1.MsgRepayAsset.fromPartial({
|
|
103
|
-
creator: wallet.bech32Address,
|
|
104
|
-
denom: params.denom,
|
|
105
|
-
amount: params.amount.toString(10),
|
|
106
|
-
debtor: params.debtor,
|
|
107
|
-
});
|
|
108
|
-
return yield wallet.sendTx({
|
|
109
|
-
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
110
|
-
value,
|
|
111
|
-
}, opts);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
99
|
supplyAssetAndLockCollateral(params, opts) {
|
|
115
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
101
|
const wallet = this.getWallet();
|
|
@@ -215,6 +200,50 @@ class CDPModule extends base_1.default {
|
|
|
215
200
|
}, opts);
|
|
216
201
|
});
|
|
217
202
|
}
|
|
203
|
+
repayAsset(params, opts) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const wallet = this.getWallet();
|
|
206
|
+
const value = tx_1.MsgRepayAsset.fromPartial({
|
|
207
|
+
creator: wallet.bech32Address,
|
|
208
|
+
denom: params.denom,
|
|
209
|
+
amount: params.amount.toString(10),
|
|
210
|
+
debtor: params.debtor,
|
|
211
|
+
});
|
|
212
|
+
return yield wallet.sendTx({
|
|
213
|
+
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
214
|
+
value,
|
|
215
|
+
}, opts);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Uses grouped token balance to repay for existing CDP asset debt.
|
|
220
|
+
* Calls 2 msg in 1 tx, MsgWithdrawFromGroup and MsgRepayAsset.
|
|
221
|
+
* Ensure that grouped token balance is sufficient.
|
|
222
|
+
*/
|
|
223
|
+
repayAssetWithGroupedToken(params, opts) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const wallet = this.getWallet();
|
|
226
|
+
const debtor = params.debtor ? params.debtor : wallet.bech32Address;
|
|
227
|
+
return yield wallet.sendTxs([{
|
|
228
|
+
typeUrl: util_1.CarbonTx.Types.MsgWithdrawFromGroup,
|
|
229
|
+
value: codec_1.MsgWithdrawFromGroup.fromPartial({
|
|
230
|
+
creator: wallet.bech32Address,
|
|
231
|
+
sourceCoin: {
|
|
232
|
+
amount: params.amount.toString(10),
|
|
233
|
+
denom: params.denom,
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
}, {
|
|
237
|
+
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
238
|
+
value: tx_1.MsgRepayAsset.fromPartial({
|
|
239
|
+
creator: wallet.bech32Address,
|
|
240
|
+
debtor: debtor,
|
|
241
|
+
denom: params.denom,
|
|
242
|
+
amount: params.amount.toString(10),
|
|
243
|
+
}),
|
|
244
|
+
}], opts);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
218
247
|
repayAssetWithCdpTokens(params, opts) {
|
|
219
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
249
|
const wallet = this.getWallet();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SDKProvider } from "../provider";
|
|
2
|
+
import { TypeUtils } from "../util";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { QueryClientImpl as CosmWasmQueryClient } from "cosmjs-types/cosmwasm/wasm/v1/query";
|
|
5
|
+
import BaseModule from "./base";
|
|
6
|
+
export interface BalanceResponse {
|
|
7
|
+
contractAddress: string;
|
|
8
|
+
balance: BigNumber;
|
|
9
|
+
}
|
|
10
|
+
export declare class CosmWasmModule extends BaseModule {
|
|
11
|
+
private cosmWasmClient;
|
|
12
|
+
constructor(cosmClient: CosmWasmQueryClient, sdkProvider: SDKProvider);
|
|
13
|
+
static instance(tmRpcUrl: string, sdkProvider: SDKProvider): Promise<CosmWasmModule>;
|
|
14
|
+
queryCosmwasmBalance(walletAddress: string, contractAddr: string): Promise<BalanceResponse>;
|
|
15
|
+
queryCosmwasmBalances(walletAddress: string, contractAddresses: string[]): Promise<TypeUtils.SimpleMap<BigNumber>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CosmWasmModule = void 0;
|
|
16
|
+
const util_1 = require("../util");
|
|
17
|
+
const query_1 = require("cosmjs-types/cosmwasm/wasm/v1/query");
|
|
18
|
+
const stargate_1 = require("@cosmjs/stargate");
|
|
19
|
+
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
20
|
+
const base_1 = __importDefault(require("./base"));
|
|
21
|
+
class CosmWasmModule extends base_1.default {
|
|
22
|
+
constructor(cosmClient, sdkProvider) {
|
|
23
|
+
super(sdkProvider);
|
|
24
|
+
this.cosmWasmClient = cosmClient;
|
|
25
|
+
}
|
|
26
|
+
static instance(tmRpcUrl, sdkProvider) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const tmClient = util_1.GenericUtils.modifyTmClient(yield tendermint_rpc_1.Tendermint34Client.connect(tmRpcUrl));
|
|
29
|
+
const baseClient = new stargate_1.QueryClient(tmClient);
|
|
30
|
+
const rpcClient = stargate_1.createProtobufRpcClient(baseClient);
|
|
31
|
+
const cosmWasmClient = new query_1.QueryClientImpl(rpcClient);
|
|
32
|
+
return new CosmWasmModule(cosmWasmClient, sdkProvider);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
queryCosmwasmBalance(walletAddress, contractAddr) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const finalResult = {
|
|
38
|
+
contractAddress: contractAddr,
|
|
39
|
+
balance: util_1.NumberUtils.BN_ZERO,
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
const smartContract = yield this.cosmWasmClient.SmartContractState({
|
|
43
|
+
address: contractAddr,
|
|
44
|
+
queryData: Buffer.from(JSON.stringify({ balance: { address: walletAddress } }), 'utf-8'),
|
|
45
|
+
});
|
|
46
|
+
const result = Buffer.from(smartContract.data).toString("utf-8");
|
|
47
|
+
const balanceJson = JSON.parse(result);
|
|
48
|
+
finalResult.balance = util_1.NumberUtils.bnOrZero(balanceJson.balance);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.error(err);
|
|
52
|
+
}
|
|
53
|
+
return finalResult;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
queryCosmwasmBalances(walletAddress, contractAddresses) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const balancesMap = yield Promise.all(contractAddresses.map((contractAddr) => this.queryCosmwasmBalance(walletAddress, contractAddr)));
|
|
59
|
+
return balancesMap.reduce((prev, balance) => {
|
|
60
|
+
prev[balance.contractAddress] = balance.balance;
|
|
61
|
+
return prev;
|
|
62
|
+
}, {});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
;
|
|
66
|
+
}
|
|
67
|
+
exports.CosmWasmModule = CosmWasmModule;
|
package/lib/util/ibc.js
CHANGED
|
@@ -31,9 +31,13 @@ exports.totalAssetObj = Object.values(exports.EmbedChainInfos).reduce((prev, cha
|
|
|
31
31
|
const channelsObj = constant_1.swthChannels[chainInfo.chainId];
|
|
32
32
|
chainInfo.currencies.forEach((currency) => {
|
|
33
33
|
var _a;
|
|
34
|
-
|
|
34
|
+
let ibcAddr = currency.coinDenom.toLowerCase() === "swth"
|
|
35
35
|
? currency.coinMinimalDenom
|
|
36
36
|
: makeIBCMinimalDenom((_a = channelsObj === null || channelsObj === void 0 ? void 0 : channelsObj.sourceChannel) !== null && _a !== void 0 ? _a : "channel-0", currency.coinMinimalDenom);
|
|
37
|
+
// TODO: Remove when implementing dynamic ibc chain info
|
|
38
|
+
if (currency.coinMinimalDenom === "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858") {
|
|
39
|
+
ibcAddr = "ibc/7FBDBEEEBA9C50C4BCDF7BF438EAB99E64360833D240B32655C96E319559E911";
|
|
40
|
+
}
|
|
37
41
|
assetsObj[ibcAddr] = currency;
|
|
38
42
|
});
|
|
39
43
|
newAssetObj[chainInfo.chainId] = assetsObj;
|
|
@@ -76,6 +80,11 @@ exports.BlockchainMap = Object.values(exports.EmbedChainInfos).reduce((prev, cha
|
|
|
76
80
|
const channelsObj = constant_1.swthChannels[chainInfo.chainId];
|
|
77
81
|
chainInfo.currencies.forEach((currency) => {
|
|
78
82
|
var _a;
|
|
83
|
+
// TODO: Remove when implementing dynamic ibc chain info
|
|
84
|
+
if (currency.coinMinimalDenom === "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858") {
|
|
85
|
+
newPrev["ibc/7FBDBEEEBA9C50C4BCDF7BF438EAB99E64360833D240B32655C96E319559E911"] = exports.ChainIdBlockchainMap[chainInfo.chainId];
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
79
88
|
if (currency.coinDenom.toLowerCase() === "swth") {
|
|
80
89
|
newPrev[currency.coinMinimalDenom] = exports.ChainIdBlockchainMap[chainInfo.chainId];
|
|
81
90
|
}
|