debug swap message

This commit is contained in:
liangping 2021-12-11 11:31:24 +08:00
parent 87a24f8d21
commit 1176a727e9
6 changed files with 52 additions and 11 deletions

View File

@ -41,6 +41,7 @@
"echarts": "4.8.0", "echarts": "4.8.0",
"leaflet": "1.6.0", "leaflet": "1.6.0",
"ledger-cosmos-js": "2.1.8", "ledger-cosmos-js": "2.1.8",
"long": "^5.2.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"pako": "^1.0.11", "pako": "^1.0.11",
"portal-vue": "2.1.7", "portal-vue": "2.1.7",

View File

@ -338,7 +338,6 @@ function createDefaultTypes(prefix) {
"/ibc.applications.transfer.v1.MsgTransfer": { "/ibc.applications.transfer.v1.MsgTransfer": {
aminoType: "cosmos-sdk/MsgTransfer", aminoType: "cosmos-sdk/MsgTransfer",
toAmino: ({ sourcePort, sourceChannel, token, sender, receiver, timeoutHeight, timeoutTimestamp, }) => { toAmino: ({ sourcePort, sourceChannel, token, sender, receiver, timeoutHeight, timeoutTimestamp, }) => {
console.log('toAmino', sourceChannel, sourcePort)
var _a, _b, _c; var _a, _b, _c;
return ({ return ({
source_port: sourcePort, source_port: sourcePort,
@ -370,6 +369,31 @@ function createDefaultTypes(prefix) {
timeoutTimestamp: long_1.default.fromString(timeout_timestamp || "0", true), 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); this.register = Object.assign(Object.assign({}, filteredDefaultTypes), additions);
} }
toAmino({ typeUrl, value }) { toAmino({ typeUrl, value }) {
console.log('typeurl:', typeUrl, value)
const converter = this.register[typeUrl]; const converter = this.register[typeUrl];
if (!converter) { if (!converter) {
throw new Error("Type URL does not exist in the Amino message type register. " + throw new Error("Type URL does not exist in the Amino message type register. " +

View File

@ -171,7 +171,7 @@ export async function sign(device, chainId, signerAddress, messages, fee, memo,
// Ensure the address has some tokens to spend // Ensure the address has some tokens to spend
const client = await PingWalletClient.offline(signer) const client = await PingWalletClient.offline(signer)
// const client = await SigningStargateClient.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) // return signDirect(signer, signerAddress, messages, fee, memo, signerData)
} }

View File

@ -2,7 +2,8 @@
import { SigningStargateClient } from '@cosmjs/stargate' import { SigningStargateClient } from '@cosmjs/stargate'
// import { MsgTransfer } from './msg-transfer' // import { MsgTransfer } from './msg-transfer'
// import { AminoTypes } from './aminotypes' import { AminoTypes } from './aminotypes'
import { MsgSwapExactAmountIn } from '../msg'
const amino_1 = require('@cosmjs/amino') const amino_1 = require('@cosmjs/amino')
const encoding_1 = require('@cosmjs/encoding') const encoding_1 = require('@cosmjs/encoding')
@ -15,12 +16,12 @@ export default class PingWalletClient extends SigningStargateClient {
static async offline(signer, options = {}) { static async offline(signer, options = {}) {
const instance = new PingWalletClient(undefined, 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) // console.log('registory:', instance.registry, AminoTypes)
// const { aminoTypes = new AminoTypes({ prefix: options.prefix }) } = options const { aminoTypes = new AminoTypes({ prefix: options.prefix }) } = options
// instance.aminoTypes = aminoTypes instance.aminoTypes = aminoTypes
// console.log('aminoType:', instance.aminoTypes) console.log('aminoType:', instance.aminoTypes)
return instance return instance
} }
@ -32,13 +33,16 @@ export default class PingWalletClient extends SigningStargateClient {
} }
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey)) const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey))
const signMode = signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON const signMode = signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON
console.log('messages:', messages)
const msgs = messages.map(msg => this.aminoTypes.toAmino(msg)) 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 signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence)
const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc) const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc)
const signedTxBody = { const signedTxBody = {
messages: signed.msgs.map(msg => this.aminoTypes.fromAmino(msg)), messages: signed.msgs.map(msg => this.aminoTypes.fromAmino(msg)),
memo: signed.memo, memo: signed.memo,
} }
console.log(signedTxBody)
const signedTxBodyEncodeObject = { const signedTxBodyEncodeObject = {
typeUrl: '/cosmos.tx.v1beta1.TxBody', typeUrl: '/cosmos.tx.v1beta1.TxBody',
value: signedTxBody, value: signedTxBody,

View File

@ -8,6 +8,7 @@
<span class="font-weight-bolder">Balance </span> <span class="font-weight-bolder">Balance </span>
<span> <span>
<feather-icon <feather-icon
v-if="currentDenom.startsWith('ibc/')"
v-b-modal.trading-deposte-window v-b-modal.trading-deposte-window
icon="PlusSquareIcon" icon="PlusSquareIcon"
class="text-primary" class="text-primary"
@ -215,6 +216,11 @@
</template> </template>
<script> <script>
/* eslint-disable */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const long_1 = __importDefault(require("long"));
import { import {
BFormInput, BButton, BAlert, BFormGroup, BInputGroup, BInputGroupAppend, BFormRadio, BFormRadioGroup, BCard, BPopover, BFormInput, BButton, BAlert, BFormGroup, BInputGroup, BInputGroupAppend, BFormRadio, BFormRadioGroup, BCard, BPopover,
} from 'bootstrap-vue' } from 'bootstrap-vue'
@ -359,20 +365,20 @@ export default {
const { denom } = this.pool.poolAssets[this.type === 0 ? 1 : 0].token const { denom } = this.pool.poolAssets[this.type === 0 ? 1 : 0].token
const txMsgs = [ const txMsgs = [
{ {
type: '/osmosis.gamm.v1beta1.MsgSwapExactAmountIn', typeUrl: '/osmosis.gamm.v1beta1.MsgSwapExactAmountIn',
value: { value: {
sender: this.address, sender: this.address,
routes: [ routes: [
{ {
poolId: this.pool.id, poolId: long_1.default.fromString(this.pool.id),
tokenOutDenom, tokenOutDenom,
}, },
], ],
tokenIn: { tokenIn: {
denom, 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)),
}, },
}, },
] ]

View File

@ -7510,6 +7510,11 @@ long@^4.0.0:
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz" resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== 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: longest@^1.0.0:
version "1.0.1" version "1.0.1"
resolved "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz" resolved "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz"