carbon-js-sdk 0.4.21 → 0.4.23
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 +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/EvmIbcClient.d.ts +86 -0
- package/lib/clients/EvmIbcClient.js +90 -0
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/TokenClient.js +4 -4
- package/lib/clients/ZILClient.js +17 -17
- package/lib/codec/alliance/alliance.d.ts +65 -0
- package/lib/codec/alliance/alliance.js +354 -0
- package/lib/codec/alliance/delegations.d.ts +86 -0
- package/lib/codec/alliance/delegations.js +489 -0
- package/lib/codec/alliance/events.d.ts +61 -0
- package/lib/codec/alliance/events.js +403 -0
- package/lib/codec/alliance/genesis.d.ts +74 -0
- package/lib/codec/alliance/genesis.js +469 -0
- package/lib/codec/alliance/gov.d.ts +78 -0
- package/lib/codec/alliance/gov.js +380 -0
- package/lib/codec/{perpsliquidity → alliance}/params.d.ts +18 -8
- package/lib/codec/alliance/params.js +182 -0
- package/lib/codec/alliance/query.d.ts +312 -0
- package/lib/codec/alliance/query.js +1497 -0
- package/lib/codec/alliance/tx.d.ts +111 -0
- package/lib/codec/alliance/tx.js +495 -0
- package/lib/codec/broker/incoming_pool_swap.d.ts +23 -0
- package/lib/codec/broker/incoming_pool_swap.js +136 -0
- package/lib/codec/cosmos/gov/v1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1/tx.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/group/v1/events.js +2 -2
- package/lib/codec/cosmos/group/v1/tx.js +4 -4
- package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
- package/lib/codec/google/protobuf/any.d.ts +4 -1
- package/lib/codec/google/protobuf/timestamp.d.ts +0 -2
- package/lib/codec/index.d.ts +58 -35
- package/lib/codec/index.js +788 -697
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/gov.js +12 -12
- 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 +27 -27
- 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 +25 -25
- package/lib/provider/amino/types/coin.js +4 -4
- 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 +2 -2
- 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/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/ethermint/evm-ibc.d.ts +97 -0
- package/lib/util/ethermint/evm-ibc.js +134 -0
- package/lib/util/ethermint/index.d.ts +3 -0
- package/lib/util/ethermint/index.js +12 -0
- package/lib/util/ethermint/keys.d.ts +39 -0
- package/lib/util/ethermint/keys.js +138 -0
- package/lib/util/ethermint/web3.d.ts +36 -0
- package/lib/util/ethermint/web3.js +124 -0
- 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 +51 -34
- 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 +1 -1
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.d.ts +0 -1
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.js +0 -6
- package/lib/codec/ethermint/evm/v1/export.d.ts +0 -5
- package/lib/codec/ethermint/evm/v1/export.js +0 -53
- package/lib/codec/ethermint/feemarket/v1/export.d.ts +0 -4
- package/lib/codec/ethermint/feemarket/v1/export.js +0 -18
- package/lib/codec/ethermint/types/v1/export.d.ts +0 -4
- package/lib/codec/ethermint/types/v1/export.js +0 -11
- package/lib/codec/ethermint-models.d.ts +0 -4
- package/lib/codec/ethermint-models.js +0 -26
- package/lib/codec/market/fee.d.ts +0 -123
- package/lib/codec/market/fee.js +0 -334
- package/lib/codec/perpsliquidity/event.d.ts +0 -102
- package/lib/codec/perpsliquidity/event.js +0 -581
- package/lib/codec/perpsliquidity/genesis.d.ts +0 -35
- package/lib/codec/perpsliquidity/genesis.js +0 -162
- package/lib/codec/perpsliquidity/params.js +0 -103
- package/lib/codec/perpsliquidity/pool.d.ts +0 -137
- package/lib/codec/perpsliquidity/pool.js +0 -747
- package/lib/codec/perpsliquidity/query.d.ts +0 -167
- package/lib/codec/perpsliquidity/query.js +0 -719
- package/lib/codec/perpsliquidity/tx.d.ts +0 -199
- package/lib/codec/perpsliquidity/tx.js +0 -940
- package/lib/constant/eip712.d.ts +0 -46
- package/lib/constant/eip712.js +0 -106
- package/lib/modules/evm.d.ts +0 -46
- package/lib/modules/evm.js +0 -127
- package/lib/modules/evmmerge.d.ts +0 -12
- package/lib/modules/evmmerge.js +0 -35
- package/lib/modules/feemarket.d.ts +0 -20
- package/lib/modules/feemarket.js +0 -45
- package/lib/modules/vault.d.ts +0 -44
- package/lib/modules/vault.js +0 -95
- package/lib/provider/amino/types/evm.d.ts +0 -4
- package/lib/provider/amino/types/evm.js +0 -40
- package/lib/provider/amino/types/evmmerge.d.ts +0 -4
- package/lib/provider/amino/types/evmmerge.js +0 -34
- package/lib/provider/amino/types/feemarket.d.ts +0 -4
- package/lib/provider/amino/types/feemarket.js +0 -34
- package/lib/provider/metamask/legacy-accounts.d.ts +0 -6
- package/lib/provider/metamask/legacy-accounts.js +0 -44
- package/lib/util/eip712.d.ts +0 -10
- package/lib/util/eip712.js +0 -195
- package/lib/util/ethermint.d.ts +0 -8
- package/lib/util/ethermint.js +0 -68
- package/lib/util/legacyEIP712.d.ts +0 -20
- package/lib/util/legacyEIP712.js +0 -98
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const CarbonTx = __importStar(require("../../../util/tx"));
|
|
23
|
-
const utils_1 = require("../utils");
|
|
24
|
-
const TxTypes = {
|
|
25
|
-
UpdateParams: "ethermint/feemarket/MsgUpdateParams",
|
|
26
|
-
};
|
|
27
|
-
const MsgUpdateParams = {
|
|
28
|
-
aminoType: TxTypes.UpdateParams,
|
|
29
|
-
valueMap: {},
|
|
30
|
-
};
|
|
31
|
-
const FeeMarketAmino = {
|
|
32
|
-
[CarbonTx.Types.MsgUpdateParams]: utils_1.generateAminoType(MsgUpdateParams),
|
|
33
|
-
};
|
|
34
|
-
exports.default = FeeMarketAmino;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LEGACY_ACCOUNTS_MAINNET = exports.LEGACY_ACCOUNTS_TESTNET = void 0;
|
|
4
|
-
// As of 16 May 2023
|
|
5
|
-
exports.LEGACY_ACCOUNTS_TESTNET = {
|
|
6
|
-
"Ethereum": [
|
|
7
|
-
"0x32c1069dcf38a7294ee9633fcb897c18cabd1668",
|
|
8
|
-
"0x6a8247bc77084acf32901f6a29369bc702d25769",
|
|
9
|
-
"0xe3f544b81a8e60087b25b1e6f0e71d579686c798",
|
|
10
|
-
"0xc6a53d96f92be41b9a7ccd9daa5d52cb7a8fdb92",
|
|
11
|
-
"0x8440a2e6e763ee99b29dcf663a72896817d6a6fd",
|
|
12
|
-
"0x04d40c9e02e0f793c25d2e4c993b853f6a1c7b6c",
|
|
13
|
-
"0x1e9eb8d2320a52dcd91a4016b1471947844ed903",
|
|
14
|
-
"0x7d831dd3a6f1553b9b995f499f4d31d4935b34f8",
|
|
15
|
-
"0xb88cb290efff1017a27db762fba8f15e754fdd67",
|
|
16
|
-
"0xc120adde16e45c1a36e65fb9bdb5bd8b1f620c19",
|
|
17
|
-
"0x0897fbc3eb27992cadbffa506e1403d180c94735",
|
|
18
|
-
"0x49367893FF5e5481312159D1EC7dfFd1bCD082B7",
|
|
19
|
-
"0x6fC1b1665BF2EC94d3d936EAb45ACa6b58eE2797",
|
|
20
|
-
"0x3619d35d2ca763d63387138Fff3a13A5fFE7c8Ce",
|
|
21
|
-
"0xEEe3c236312a81f3CC3CB78763968e24355b513F",
|
|
22
|
-
"0x184268C2eA4332234d6Ee5b0bA1C212E63fa55Cc",
|
|
23
|
-
"0x05a2F90551Dcba19C42c6E85FB00843C0859a427",
|
|
24
|
-
"0xad045ec15DbBe6FebE8e7D1EC85Eb7D496c4ebe1",
|
|
25
|
-
"0xcFa83a56f1479BB9CD5a25f36a0C3E44EE08D7DB",
|
|
26
|
-
"0x8e2C2E908195F87Bc6C14fAEC31F7726d094b3c6"
|
|
27
|
-
]
|
|
28
|
-
};
|
|
29
|
-
// To be updated
|
|
30
|
-
exports.LEGACY_ACCOUNTS_MAINNET = {
|
|
31
|
-
"Ethereum": [
|
|
32
|
-
"0x32c1069dcf38a7294ee9633fcb897c18cabd1668",
|
|
33
|
-
"0x6a8247bc77084acf32901f6a29369bc702d25769",
|
|
34
|
-
"0xe3f544b81a8e60087b25b1e6f0e71d579686c798",
|
|
35
|
-
"0xc6a53d96f92be41b9a7ccd9daa5d52cb7a8fdb92",
|
|
36
|
-
"0x8440a2e6e763ee99b29dcf663a72896817d6a6fd",
|
|
37
|
-
"0x04d40c9e02e0f793c25d2e4c993b853f6a1c7b6c",
|
|
38
|
-
"0x1e9eb8d2320a52dcd91a4016b1471947844ed903",
|
|
39
|
-
"0x7d831dd3a6f1553b9b995f499f4d31d4935b34f8",
|
|
40
|
-
"0xb88cb290efff1017a27db762fba8f15e754fdd67",
|
|
41
|
-
"0xc120adde16e45c1a36e65fb9bdb5bd8b1f620c19",
|
|
42
|
-
"0x0897fbc3eb27992cadbffa506e1403d180c94735"
|
|
43
|
-
]
|
|
44
|
-
};
|
package/lib/util/eip712.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TypedDataDomain, TypedDataField } from "@ethersproject/abstract-signer";
|
|
2
|
-
import { TypeUtils } from ".";
|
|
3
|
-
import { CarbonTx } from "../util";
|
|
4
|
-
export interface EIP712Tx {
|
|
5
|
-
readonly types: TypeUtils.SimpleMap<TypedDataField[]>;
|
|
6
|
-
readonly primaryType: string;
|
|
7
|
-
readonly domain: TypedDataDomain;
|
|
8
|
-
readonly message: any;
|
|
9
|
-
}
|
|
10
|
-
export declare function constructEIP712Tx(doc: CarbonTx.StdSignDoc): EIP712Tx;
|
package/lib/util/eip712.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.constructEIP712Tx = void 0;
|
|
7
|
-
const eip712_1 = require("../constant/eip712");
|
|
8
|
-
const ethermint_1 = require("../util/ethermint");
|
|
9
|
-
const codec_1 = require("../codec");
|
|
10
|
-
const AminoTypesMap_1 = __importDefault(require("../provider/amino/AminoTypesMap"));
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
-
function getTypes(msgs) {
|
|
13
|
-
let types = Object.assign({}, eip712_1.DEFAULT_EIP712_TYPES);
|
|
14
|
-
const includedTypes = [];
|
|
15
|
-
let valueIndex = 0;
|
|
16
|
-
msgs.forEach((msg, index) => {
|
|
17
|
-
const typeUrl = AminoTypesMap_1.default.fromAmino(msg).typeUrl;
|
|
18
|
-
const msgType = msg.type.split('/')[1];
|
|
19
|
-
const msgTypeIndex = getLatestMsgTypeIndex(`Type${msgType}`, types);
|
|
20
|
-
//cosmos-sdk/MsgSend => TypeMsgSend1
|
|
21
|
-
const typeKey = `Type${msgType}${msgTypeIndex}`;
|
|
22
|
-
if (!includedTypes.includes(msg.type)) {
|
|
23
|
-
types['Tx'] = [...types['Tx'], { name: `msg${index}`, type: typeKey }];
|
|
24
|
-
types[typeKey] = [{ name: 'value', type: `TypeValue${valueIndex}` }, { name: 'type', type: 'string' }];
|
|
25
|
-
//cosmos-sdk/MsgSend => Msg_Send
|
|
26
|
-
types = Object.assign(Object.assign({}, types), sortByNameDescending(getMsgValueType(typeUrl, msg.value, `TypeValue${valueIndex}`, valueIndex, types)));
|
|
27
|
-
includedTypes.push(msg.type);
|
|
28
|
-
valueIndex++;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const typeFound = matchingType(msg, types);
|
|
32
|
-
if (typeFound) {
|
|
33
|
-
types['Tx'] = [...types['Tx'], { name: `msg${index}`, type: typeFound }];
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
//same type, but different fields populated, so new type defnition is required
|
|
37
|
-
types['Tx'] = [...types['Tx'], { name: `msg${index}`, type: typeKey }];
|
|
38
|
-
types[typeKey] = [{ name: 'value', type: `TypeValue${valueIndex}` }, { name: 'type', type: 'string' }];
|
|
39
|
-
types = Object.assign(Object.assign({}, types), sortByNameDescending(getMsgValueType(typeUrl, msg.value, `TypeValue${valueIndex}`, valueIndex, types)));
|
|
40
|
-
valueIndex++;
|
|
41
|
-
});
|
|
42
|
-
return types;
|
|
43
|
-
}
|
|
44
|
-
function getLatestMsgTypeIndex(typeName, types) {
|
|
45
|
-
let index = 0;
|
|
46
|
-
Object.entries(types).forEach(([key, _]) => {
|
|
47
|
-
if (key.includes(typeName)) {
|
|
48
|
-
index++;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return index;
|
|
52
|
-
}
|
|
53
|
-
function sortByNameDescending(types) {
|
|
54
|
-
Object.entries(types).forEach(([key, _]) => {
|
|
55
|
-
types[key].sort((a, b) => b.name.localeCompare(a.name));
|
|
56
|
-
});
|
|
57
|
-
return types;
|
|
58
|
-
}
|
|
59
|
-
// Checks if there is a need to create new type for the same message type because of different populated fields
|
|
60
|
-
function matchingType(msg, eipTypes) {
|
|
61
|
-
const msgType = msg.type.split('/')[1];
|
|
62
|
-
let match = false;
|
|
63
|
-
for (const key in eipTypes) {
|
|
64
|
-
if (key.includes(msgType)) {
|
|
65
|
-
match = compareValues(msg, key, eipTypes);
|
|
66
|
-
}
|
|
67
|
-
if (match) {
|
|
68
|
-
return key;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
73
|
-
function compareValues(msg, key, eipTypes) {
|
|
74
|
-
let match = true;
|
|
75
|
-
for (let { name, type } of eipTypes[key]) {
|
|
76
|
-
if (Object.keys(msg).length > eipTypes[key].length) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
let value = msg[name];
|
|
80
|
-
if (!isNonZeroField(value)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
const typeIsArray = type.includes('[]');
|
|
84
|
-
if (typeIsArray) {
|
|
85
|
-
type = type.split('[]')[0];
|
|
86
|
-
//Assumption: Take first value in array to determine which fields are populated
|
|
87
|
-
value = value[0];
|
|
88
|
-
}
|
|
89
|
-
if (eipTypes[type]) {
|
|
90
|
-
match = compareValues(value, type, eipTypes);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return match;
|
|
94
|
-
}
|
|
95
|
-
function getMsgValueType(msgTypeUrl, msgValue, msgTypeName, msgTypeIndex, types, objectName, nestedType = false, msgTypeDefinitions = {}) {
|
|
96
|
-
const packageName = msgTypeUrl.split(".").slice(0, -1).join(".");
|
|
97
|
-
const msgFieldType = msgTypeUrl.split(".").pop();
|
|
98
|
-
const typeName = getTypeName(msgTypeName, msgTypeIndex, objectName, nestedType, false);
|
|
99
|
-
const fieldsDefinition = codec_1.EIP712Types[packageName][msgFieldType];
|
|
100
|
-
if (isNonZeroField(msgValue)) {
|
|
101
|
-
if (!msgTypeDefinitions[typeName]) {
|
|
102
|
-
msgTypeDefinitions[typeName] = [];
|
|
103
|
-
}
|
|
104
|
-
fieldsDefinition.forEach(({ packageName, name, type }) => {
|
|
105
|
-
if (Array.isArray(msgValue) && msgValue.length === 0) {
|
|
106
|
-
msgTypeDefinitions[typeName] = [...msgTypeDefinitions[typeName], { name, type: 'string[]' }];
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
//Assumption: Take first value in array to determine which fields are populated
|
|
110
|
-
const fieldValue = Array.isArray(msgValue) && msgValue.length > 0 ? msgValue[0][name] : msgValue[name];
|
|
111
|
-
if (isNonZeroField(fieldValue)) {
|
|
112
|
-
//For nested structs
|
|
113
|
-
if (packageName) {
|
|
114
|
-
const isArray = type.includes('[]') ? true : false;
|
|
115
|
-
// TypeValue0 --> Value
|
|
116
|
-
const objectName = typeName.split('Type')[1].split(`${msgTypeIndex}`)[0];
|
|
117
|
-
const nestedTypeName = `Type${objectName ? objectName : ''}${name.split('_').map((subName) => lodash_1.capitalize(subName)).join('')}`;
|
|
118
|
-
const nestedMsgTypeIndex = getLatestMsgTypeIndex(nestedTypeName, types);
|
|
119
|
-
const nestedType = getTypeName(name, nestedMsgTypeIndex, objectName, true, isArray);
|
|
120
|
-
msgTypeDefinitions[typeName] = [...msgTypeDefinitions[typeName], { name, type: nestedType }];
|
|
121
|
-
//Special logic if nested struct is google protobuf's Any type
|
|
122
|
-
if (isGoogleProtobufAnyPackage(packageName, type)) {
|
|
123
|
-
const nestedAnyTypeName = isArray ? nestedType.split('[]')[0].split(`${msgTypeIndex}`)[0] : nestedType.split(`${msgTypeIndex}`)[0];
|
|
124
|
-
const nestedMsgTypeIndex = getLatestMsgTypeIndex(`${nestedAnyTypeName}Value`, types);
|
|
125
|
-
const nestedAnyValueType = `${nestedAnyTypeName}Value${nestedMsgTypeIndex}`;
|
|
126
|
-
msgTypeDefinitions[`${nestedAnyTypeName}${msgTypeIndex}`] = [{ name: "type", type: "string" }, { name: "value", type: nestedAnyValueType }];
|
|
127
|
-
const anyObjectTypeNameSplit = nestedAnyTypeName.split('Type')[1].split(`${msgTypeIndex}`)[0];
|
|
128
|
-
const messageTypeUrl = AminoTypesMap_1.default.fromAmino(fieldValue).typeUrl;
|
|
129
|
-
getMsgValueType(messageTypeUrl, fieldValue.value, "value", nestedMsgTypeIndex, types, anyObjectTypeNameSplit, true, msgTypeDefinitions);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
const typeStructName = type.includes('[]') ? type.split('[]')[0].split(`${nestedMsgTypeIndex}`)[0] : type.split(`${nestedMsgTypeIndex}`)[0];
|
|
133
|
-
const messageTypeUrl = `${packageName}.${typeStructName}`;
|
|
134
|
-
getMsgValueType(messageTypeUrl, fieldValue, name, nestedMsgTypeIndex, types, objectName, true, msgTypeDefinitions);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
msgTypeDefinitions[typeName] = [...msgTypeDefinitions[typeName], { name, type: getGjsonPrimitiveType(fieldValue) }];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return msgTypeDefinitions;
|
|
144
|
-
}
|
|
145
|
-
function getGjsonPrimitiveType(value) {
|
|
146
|
-
if (typeof value === 'number') {
|
|
147
|
-
return 'int64';
|
|
148
|
-
}
|
|
149
|
-
if (typeof value === 'boolean') {
|
|
150
|
-
return 'bool';
|
|
151
|
-
}
|
|
152
|
-
return 'string';
|
|
153
|
-
}
|
|
154
|
-
function getTypeName(name, index, objectName, nestedType = false, isArray = false) {
|
|
155
|
-
if (nestedType) {
|
|
156
|
-
return `Type${objectName ? objectName : ''}${name.split('_').map(subName => lodash_1.capitalize(subName)).join('')}${index}${isArray ? '[]' : ''}`;
|
|
157
|
-
}
|
|
158
|
-
return name;
|
|
159
|
-
}
|
|
160
|
-
function isGoogleProtobufAnyPackage(packageName, type) {
|
|
161
|
-
return packageName === '/google.protobuf' && type == 'Any';
|
|
162
|
-
}
|
|
163
|
-
function isNonZeroField(fieldValue) {
|
|
164
|
-
// zero fields are considered falsey,except if it is string "0"
|
|
165
|
-
if (fieldValue == "0" && typeof fieldValue !== "string") {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
// empty arrays are considered truthy
|
|
169
|
-
if (Array.isArray(fieldValue)) {
|
|
170
|
-
return fieldValue.length !== 0;
|
|
171
|
-
}
|
|
172
|
-
// empty objects are considered truthy
|
|
173
|
-
if (fieldValue && typeof fieldValue === 'object' && Object.keys(fieldValue).length === 0) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
return fieldValue;
|
|
177
|
-
}
|
|
178
|
-
function constructEIP712Tx(doc) {
|
|
179
|
-
const { account_number, chain_id, fee, memo, sequence } = doc;
|
|
180
|
-
const eip712Tx = {
|
|
181
|
-
types: getTypes(doc.msgs),
|
|
182
|
-
primaryType: "Tx",
|
|
183
|
-
domain: Object.assign(Object.assign({}, eip712_1.DEFAULT_CARBON_DOMAIN_FIELDS), { chainId: ethermint_1.parseChainId(doc.chain_id) }),
|
|
184
|
-
message: Object.assign({ account_number, chain_id, fee, memo, sequence }, convertMsgs(doc.msgs))
|
|
185
|
-
};
|
|
186
|
-
return eip712Tx;
|
|
187
|
-
}
|
|
188
|
-
exports.constructEIP712Tx = constructEIP712Tx;
|
|
189
|
-
function convertMsgs(msgs) {
|
|
190
|
-
const convertedMsgs = {};
|
|
191
|
-
msgs.forEach((msg, index) => {
|
|
192
|
-
convertedMsgs[`msg${index}`] = msg;
|
|
193
|
-
});
|
|
194
|
-
return convertedMsgs;
|
|
195
|
-
}
|
package/lib/util/ethermint.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import CarbonSDK from "../CarbonSDK";
|
|
2
|
-
import { Any } from "../codec";
|
|
3
|
-
import { ethers } from "ethers";
|
|
4
|
-
export declare const ETH_SECP256K1_TYPE = "/ethermint.crypto.v1.ethsecp256k1.PubKey";
|
|
5
|
-
export declare const PUBLIC_KEY_SIGNING_TEXT = "Sign your public key to merge your Carbon account: ";
|
|
6
|
-
export declare function encodeAnyEthSecp256k1PubKey(pubkey: Uint8Array): Any;
|
|
7
|
-
export declare function parseChainId(evmChainId: string): string;
|
|
8
|
-
export declare function populateEvmTransactionDetails(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionRequest>;
|
package/lib/util/ethermint.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.populateEvmTransactionDetails = exports.parseChainId = exports.encodeAnyEthSecp256k1PubKey = exports.PUBLIC_KEY_SIGNING_TEXT = exports.ETH_SECP256K1_TYPE = void 0;
|
|
13
|
-
const codec_1 = require("../codec");
|
|
14
|
-
const keys_1 = require("../codec/ethermint/crypto/v1/ethsecp256k1/keys");
|
|
15
|
-
exports.ETH_SECP256K1_TYPE = '/ethermint.crypto.v1.ethsecp256k1.PubKey';
|
|
16
|
-
exports.PUBLIC_KEY_SIGNING_TEXT = 'Sign your public key to merge your Carbon account: ';
|
|
17
|
-
function encodeAnyEthSecp256k1PubKey(pubkey) {
|
|
18
|
-
const ethPubKey = keys_1.PubKey.fromPartial({
|
|
19
|
-
key: pubkey,
|
|
20
|
-
});
|
|
21
|
-
return codec_1.Any.fromPartial({
|
|
22
|
-
typeUrl: exports.ETH_SECP256K1_TYPE,
|
|
23
|
-
value: keys_1.PubKey.encode(ethPubKey).finish(),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.encodeAnyEthSecp256k1PubKey = encodeAnyEthSecp256k1PubKey;
|
|
27
|
-
function parseChainId(evmChainId) {
|
|
28
|
-
const chainId = evmChainId.trim();
|
|
29
|
-
if (chainId.length > 48) {
|
|
30
|
-
throw new Error(`chain-id '${chainId}' cannot exceed 48 chars`);
|
|
31
|
-
}
|
|
32
|
-
if (!chainId.match(/^[a-z]+_\d+-\d+$/)) {
|
|
33
|
-
throw new Error(`chain-id '${chainId}' does not conform to the required format`);
|
|
34
|
-
}
|
|
35
|
-
return chainId.split("_")[1].split("-")[0];
|
|
36
|
-
}
|
|
37
|
-
exports.parseChainId = parseChainId;
|
|
38
|
-
function populateEvmTransactionDetails(api, req) {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const provider = api.evmJsonRpc;
|
|
42
|
-
const evmHexAddress = (_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.evmHexAddress) !== null && _b !== void 0 ? _b : '';
|
|
43
|
-
let request = {
|
|
44
|
-
to: (_c = req.to) !== null && _c !== void 0 ? _c : '',
|
|
45
|
-
from: (_d = req.from) !== null && _d !== void 0 ? _d : (_e = api.wallet) === null || _e === void 0 ? void 0 : _e.evmHexAddress,
|
|
46
|
-
nonce: (_f = req.nonce) !== null && _f !== void 0 ? _f : (yield provider.getTransactionCount(evmHexAddress)),
|
|
47
|
-
data: req.data,
|
|
48
|
-
value: `0x${Number(req.value).toString(16)}`,
|
|
49
|
-
chainId: (_g = req.chainId) !== null && _g !== void 0 ? _g : Number(parseChainId(yield ((_h = api.wallet) === null || _h === void 0 ? void 0 : _h.getEvmChainId()))),
|
|
50
|
-
// type = 0, 1 or 2 where 0 = legacyTx, 1 = AccessListTx, 2 = DynamicTx. Defaults to DynamicTx
|
|
51
|
-
type: (_j = req.type) !== null && _j !== void 0 ? _j : 2,
|
|
52
|
-
accessList: req.accessList,
|
|
53
|
-
};
|
|
54
|
-
const gasLimit = (yield provider.estimateGas(request)).toHexString();
|
|
55
|
-
const gasFee = yield provider.getFeeData();
|
|
56
|
-
if (!req.gasPrice) {
|
|
57
|
-
// Dynamic Tx
|
|
58
|
-
return Object.assign(Object.assign({}, request), { maxPriorityFeePerGas: (_k = req.maxPriorityFeePerGas) !== null && _k !== void 0 ? _k : (_l = gasFee.maxPriorityFeePerGas) === null || _l === void 0 ? void 0 : _l.toHexString(), maxFeePerGas: (_m = req.maxFeePerGas) !== null && _m !== void 0 ? _m : (_o = gasFee.maxFeePerGas) === null || _o === void 0 ? void 0 : _o.toHexString(), gasLimit, type: 2 });
|
|
59
|
-
}
|
|
60
|
-
if (req.accessList) {
|
|
61
|
-
// AccessList Tx
|
|
62
|
-
return Object.assign(Object.assign({}, request), { gasLimit, type: 1 });
|
|
63
|
-
}
|
|
64
|
-
// LegacyTx
|
|
65
|
-
return Object.assign(Object.assign({}, request), { gasLimit, type: 0 });
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
exports.populateEvmTransactionDetails = populateEvmTransactionDetails;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StdSignDoc } from "@cosmjs/amino/build";
|
|
2
|
-
import { TypedDataDomain, TypedDataField } from "@ethersproject/abstract-signer";
|
|
3
|
-
import { TypeUtils } from ".";
|
|
4
|
-
import { Coin } from "@cosmjs/proto-signing";
|
|
5
|
-
export interface LegacyEIP712Tx {
|
|
6
|
-
readonly types: TypeUtils.SimpleMap<TypedDataField[]>;
|
|
7
|
-
readonly primaryType: string;
|
|
8
|
-
readonly domain: TypedDataDomain;
|
|
9
|
-
readonly message: LegacyEIP712StdSignDoc;
|
|
10
|
-
}
|
|
11
|
-
export declare type EIP712Fee = {
|
|
12
|
-
readonly amount: readonly Coin[];
|
|
13
|
-
readonly gas: string;
|
|
14
|
-
readonly feePayer: string;
|
|
15
|
-
};
|
|
16
|
-
declare type LegacyEIP712StdSignDoc = StdSignDoc & {
|
|
17
|
-
fee: EIP712Fee;
|
|
18
|
-
};
|
|
19
|
-
export declare function legacyConstructEIP712Tx(doc: LegacyEIP712StdSignDoc): LegacyEIP712Tx;
|
|
20
|
-
export {};
|
package/lib/util/legacyEIP712.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.legacyConstructEIP712Tx = void 0;
|
|
7
|
-
const eip712_1 = require("../constant/eip712");
|
|
8
|
-
const ethermint_1 = require("../util/ethermint");
|
|
9
|
-
const codec_1 = require("../codec");
|
|
10
|
-
const AminoTypesMap_1 = __importDefault(require("../provider/amino/AminoTypesMap"));
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
-
function getTypes(msgTypeUrl, aminoMsgValue) {
|
|
13
|
-
return Object.assign(Object.assign({}, eip712_1.LEGACY_DEFAULT_EIP712_TYPES), getMsgValueType(msgTypeUrl, aminoMsgValue, "MsgValue"));
|
|
14
|
-
}
|
|
15
|
-
function getMsgValueType(msgTypeUrl, msgValue, msgTypeName, objectName, nestedType = false, msgTypeDefinitions = {}) {
|
|
16
|
-
const packageName = msgTypeUrl.split(".").slice(0, -1).join(".");
|
|
17
|
-
const msgFieldType = msgTypeUrl.split(".").pop();
|
|
18
|
-
const typeName = getTypeName(msgTypeName, objectName, nestedType, false);
|
|
19
|
-
const fieldsDefinition = codec_1.EIP712Types[packageName][msgFieldType];
|
|
20
|
-
if (isNonZeroField(msgValue)) {
|
|
21
|
-
if (!msgTypeDefinitions[typeName]) {
|
|
22
|
-
msgTypeDefinitions[typeName] = [];
|
|
23
|
-
}
|
|
24
|
-
fieldsDefinition.forEach(({ packageName, name, type }) => {
|
|
25
|
-
let fieldValue;
|
|
26
|
-
if (Array.isArray(msgValue)) {
|
|
27
|
-
//Assumption: Take first value in array to determine which fields are populated
|
|
28
|
-
fieldValue = msgValue.length > 0 ? msgValue[0][name] : [];
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
fieldValue = msgValue[name];
|
|
32
|
-
}
|
|
33
|
-
if (isNonZeroField(fieldValue)) {
|
|
34
|
-
//For nested structs
|
|
35
|
-
if (packageName) {
|
|
36
|
-
const isArray = type.includes('[]') ? true : false;
|
|
37
|
-
const objectName = typeName === 'MsgValue' ? 'MsgValue' : typeName.split('Type')[1];
|
|
38
|
-
const nestedType = getTypeName(name, objectName, true, isArray);
|
|
39
|
-
msgTypeDefinitions[typeName] = [...msgTypeDefinitions[typeName], { name, type: nestedType }];
|
|
40
|
-
//Special logic if nested struct is google protobuf's Any type
|
|
41
|
-
if (isGoogleProtobufAnyPackage(packageName, type)) {
|
|
42
|
-
const nestedAnyTypeName = isArray ? nestedType.split('[]')[0] : nestedType;
|
|
43
|
-
const nestedAnyValueType = `${nestedAnyTypeName}Value`;
|
|
44
|
-
msgTypeDefinitions[nestedAnyTypeName] = [{ name: "type", type: "string" }, { name: "value", type: nestedAnyValueType }];
|
|
45
|
-
const anyObjectTypeNameSplit = nestedAnyTypeName.split('Type')[1];
|
|
46
|
-
const messageTypeUrl = AminoTypesMap_1.default.fromAmino(fieldValue).typeUrl;
|
|
47
|
-
getMsgValueType(messageTypeUrl, fieldValue.value, "value", anyObjectTypeNameSplit, true, msgTypeDefinitions);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const typeStructName = type.includes('[]') ? type.split('[]')[0] : type;
|
|
51
|
-
const messageTypeUrl = `${packageName}.${typeStructName}`;
|
|
52
|
-
getMsgValueType(messageTypeUrl, fieldValue, name, objectName, true, msgTypeDefinitions);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
msgTypeDefinitions[typeName] = [...msgTypeDefinitions[typeName], { name, type }];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return msgTypeDefinitions;
|
|
62
|
-
}
|
|
63
|
-
function getTypeName(name, objectName, nestedType = false, isArray = false) {
|
|
64
|
-
if (nestedType) {
|
|
65
|
-
return `Type${objectName === 'MsgValue' ? '' : objectName}${name.split('_').map(subName => lodash_1.capitalize(subName)).join('')}${isArray ? '[]' : ''}`;
|
|
66
|
-
}
|
|
67
|
-
return name;
|
|
68
|
-
}
|
|
69
|
-
function isGoogleProtobufAnyPackage(packageName, type) {
|
|
70
|
-
return packageName === '/google.protobuf' && type == 'Any';
|
|
71
|
-
}
|
|
72
|
-
function isNonZeroField(fieldValue) {
|
|
73
|
-
// zero fields are considered falsey
|
|
74
|
-
if (fieldValue == "0") {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
// empty arrays are considered truthy
|
|
78
|
-
if (Array.isArray(fieldValue)) {
|
|
79
|
-
return fieldValue.length !== 0;
|
|
80
|
-
}
|
|
81
|
-
// empty objects are considered truthy
|
|
82
|
-
if (fieldValue && typeof fieldValue === 'object' && Object.keys(fieldValue).length === 0) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return fieldValue;
|
|
86
|
-
}
|
|
87
|
-
function legacyConstructEIP712Tx(doc) {
|
|
88
|
-
// Legacy EIP-712 can only accept batch msgs of the same type
|
|
89
|
-
const msg = doc.msgs[0];
|
|
90
|
-
const eip712Tx = {
|
|
91
|
-
types: getTypes(AminoTypesMap_1.default.fromAmino(msg).typeUrl, msg.value),
|
|
92
|
-
primaryType: "Tx",
|
|
93
|
-
domain: Object.assign(Object.assign({}, eip712_1.DEFAULT_CARBON_DOMAIN_FIELDS), { chainId: ethermint_1.parseChainId(doc.chain_id) }),
|
|
94
|
-
message: doc
|
|
95
|
-
};
|
|
96
|
-
return eip712Tx;
|
|
97
|
-
}
|
|
98
|
-
exports.legacyConstructEIP712Tx = legacyConstructEIP712Tx;
|