debug swap message
This commit is contained in:
parent
87a24f8d21
commit
1176a727e9
@ -41,6 +41,7 @@
|
||||
"echarts": "4.8.0",
|
||||
"leaflet": "1.6.0",
|
||||
"ledger-cosmos-js": "2.1.8",
|
||||
"long": "^5.2.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"pako": "^1.0.11",
|
||||
"portal-vue": "2.1.7",
|
||||
|
@ -338,7 +338,6 @@ function createDefaultTypes(prefix) {
|
||||
"/ibc.applications.transfer.v1.MsgTransfer": {
|
||||
aminoType: "cosmos-sdk/MsgTransfer",
|
||||
toAmino: ({ sourcePort, sourceChannel, token, sender, receiver, timeoutHeight, timeoutTimestamp, }) => {
|
||||
console.log('toAmino', sourceChannel, sourcePort)
|
||||
var _a, _b, _c;
|
||||
return ({
|
||||
source_port: sourcePort,
|
||||
@ -370,6 +369,31 @@ function createDefaultTypes(prefix) {
|
||||
timeoutTimestamp: long_1.default.fromString(timeout_timestamp || "0", true),
|
||||
}),
|
||||
},
|
||||
// osmosis
|
||||
"/osmosis.gamm.v1beta1.MsgSwapExactAmountIn": {
|
||||
aminoType: "cosmos-sdk/MsgSwapExactAmountIn",
|
||||
toAmino: ({ sender, routes, tokenIn, tokenOutMinAmount}) => {
|
||||
utils_1.assertDefinedAndNotNull(tokenIn.amount, "missing amount");
|
||||
return {
|
||||
sender,
|
||||
routes: routes.map(({poolId, tokenOutDenom}) => ({pool_id: poolId, token_out_denom: tokenOutDenom})),
|
||||
token_in: {
|
||||
amount: tokenIn.amount,
|
||||
denom: tokenIn.denom,
|
||||
},
|
||||
token_out_min_amount: tokenOutMinAmount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({ sender, routes, token_in, token_out_min_amount }) => ({
|
||||
sender,
|
||||
routes: routes.map(({pool_id, token_out_denom})=>({poolId: long_1.default.fromString(pool_id), tokenOutDenom: token_out_denom})),
|
||||
tokenIn: {
|
||||
amount: long_1.default.fromString(token_in.amount),
|
||||
denom: token_in.denom,
|
||||
},
|
||||
tokenOutMinAmount: long_1.default.fromString(token_out_min_amount),
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
@ -385,6 +409,7 @@ class AminoTypes {
|
||||
this.register = Object.assign(Object.assign({}, filteredDefaultTypes), additions);
|
||||
}
|
||||
toAmino({ typeUrl, value }) {
|
||||
console.log('typeurl:', typeUrl, value)
|
||||
const converter = this.register[typeUrl];
|
||||
if (!converter) {
|
||||
throw new Error("Type URL does not exist in the Amino message type register. " +
|
||||
|
@ -171,7 +171,7 @@ export async function sign(device, chainId, signerAddress, messages, fee, memo,
|
||||
// Ensure the address has some tokens to spend
|
||||
const client = await PingWalletClient.offline(signer)
|
||||
// const client = await SigningStargateClient.offline(signer)
|
||||
return client.signAmino(device === 'keplr' ? signerAddress : toSignAddress(signerAddress), messages, fee, memo, signerData)
|
||||
return client.signAmino2(device === 'keplr' ? signerAddress : toSignAddress(signerAddress), messages, fee, memo, signerData)
|
||||
// return signDirect(signer, signerAddress, messages, fee, memo, signerData)
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
import { SigningStargateClient } from '@cosmjs/stargate'
|
||||
// import { MsgTransfer } from './msg-transfer'
|
||||
// import { AminoTypes } from './aminotypes'
|
||||
import { AminoTypes } from './aminotypes'
|
||||
import { MsgSwapExactAmountIn } from '../msg'
|
||||
|
||||
const amino_1 = require('@cosmjs/amino')
|
||||
const encoding_1 = require('@cosmjs/encoding')
|
||||
@ -15,12 +16,12 @@ export default class PingWalletClient extends SigningStargateClient {
|
||||
static async offline(signer, options = {}) {
|
||||
const instance = new PingWalletClient(undefined, signer, options)
|
||||
|
||||
// instance.registry.register('/ibc.applications.transfer.v1.MsgTransfer', MsgTransfer)
|
||||
instance.registry.register('/osmosis.gamm.v1beta1.MsgSwapExactAmountIn', MsgSwapExactAmountIn)
|
||||
|
||||
// console.log('registory:', instance.registry, AminoTypes)
|
||||
// const { aminoTypes = new AminoTypes({ prefix: options.prefix }) } = options
|
||||
// instance.aminoTypes = aminoTypes
|
||||
// console.log('aminoType:', instance.aminoTypes)
|
||||
const { aminoTypes = new AminoTypes({ prefix: options.prefix }) } = options
|
||||
instance.aminoTypes = aminoTypes
|
||||
console.log('aminoType:', instance.aminoTypes)
|
||||
return instance
|
||||
}
|
||||
|
||||
@ -32,13 +33,16 @@ export default class PingWalletClient extends SigningStargateClient {
|
||||
}
|
||||
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey))
|
||||
const signMode = signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON
|
||||
console.log('messages:', messages)
|
||||
const msgs = messages.map(msg => this.aminoTypes.toAmino(msg))
|
||||
console.log('msgs:', msgs)
|
||||
const signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence)
|
||||
const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc)
|
||||
const signedTxBody = {
|
||||
messages: signed.msgs.map(msg => this.aminoTypes.fromAmino(msg)),
|
||||
memo: signed.memo,
|
||||
}
|
||||
console.log(signedTxBody)
|
||||
const signedTxBodyEncodeObject = {
|
||||
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
||||
value: signedTxBody,
|
||||
|
@ -8,6 +8,7 @@
|
||||
<span class="font-weight-bolder">Balance </span>
|
||||
<span>
|
||||
<feather-icon
|
||||
v-if="currentDenom.startsWith('ibc/')"
|
||||
v-b-modal.trading-deposte-window
|
||||
icon="PlusSquareIcon"
|
||||
class="text-primary"
|
||||
@ -215,6 +216,11 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* eslint-disable */
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const long_1 = __importDefault(require("long"));
|
||||
import {
|
||||
BFormInput, BButton, BAlert, BFormGroup, BInputGroup, BInputGroupAppend, BFormRadio, BFormRadioGroup, BCard, BPopover,
|
||||
} from 'bootstrap-vue'
|
||||
@ -359,20 +365,20 @@ export default {
|
||||
const { denom } = this.pool.poolAssets[this.type === 0 ? 1 : 0].token
|
||||
const txMsgs = [
|
||||
{
|
||||
type: '/osmosis.gamm.v1beta1.MsgSwapExactAmountIn',
|
||||
typeUrl: '/osmosis.gamm.v1beta1.MsgSwapExactAmountIn',
|
||||
value: {
|
||||
sender: this.address,
|
||||
routes: [
|
||||
{
|
||||
poolId: this.pool.id,
|
||||
poolId: long_1.default.fromString(this.pool.id),
|
||||
tokenOutDenom,
|
||||
},
|
||||
],
|
||||
tokenIn: {
|
||||
denom,
|
||||
amount: String(this.amount),
|
||||
amount: long_1.default.fromNumber(parseInt(this.amount * 1000000, 10)),
|
||||
},
|
||||
tokenOutMinAmount: String(this.total),
|
||||
tokenOutMinAmount: long_1.default.fromNumber(parseInt(this.total * 1000000, 10)),
|
||||
},
|
||||
},
|
||||
]
|
||||
|
@ -7510,6 +7510,11 @@ long@^4.0.0:
|
||||
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz"
|
||||
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==
|
||||
|
||||
long@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/long/-/long-5.2.0.tgz#2696dadf4b4da2ce3f6f6b89186085d94d52fd61"
|
||||
integrity sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w==
|
||||
|
||||
longest@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz"
|
||||
|
Loading…
Reference in New Issue
Block a user