Skip to content

Commit

Permalink
Merge pull request #233 from skip-mev/feat/find-gasTokenUsed-on-stride-1
Browse files Browse the repository at this point in the history
feat: find gasTokenUsed on stride-1
  • Loading branch information
codingki authored Jun 15, 2024
2 parents 873c522 + 2483069 commit ac73adc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-hairs-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skip-router/core": patch
---

find gasTokenUsed on stride-1 even validateGasBalance off
41 changes: 41 additions & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,41 @@ export class SkipRouter {
`executeRoute error: invalid address for chain '${cosmosTx.chainID}'`,
);
}

if (cosmosTx.chainID === "stride-1" && !gasTokenUsed) {
const getOfflineSigner =
options.getCosmosSigner || this.getCosmosSigner;
if (!getOfflineSigner) {
throw new Error(
"executeRoute error: 'getCosmosSigner' is not provided or configured in skip router",
);
}
const signer = await getOfflineSigner(tx.cosmosTx.chainID);

const endpoint = await this.getRpcEndpointForChain(
tx.cosmosTx.chainID,
);
// @note: A new client is created for both the gasbalance validation here as the execution later...
const client = await SigningStargateClient.connectWithSigner(
endpoint,
signer,
{
aminoTypes: this.aminoTypes,
registry: this.registry,
accountParser,
},
);
gasTokenUsed = await this.validateCosmosGasBalance({
chainID: cosmosTx.chainID,
messages: cosmosTx.msgs,
signerAddress: currentUserAddress,
getGasPrice,
gasAmountMultiplier,
getFallbackGasAmount,
client,
});
}

const txResponse = await this.executeCosmosMessage({
messages: cosmosTx.msgs,
chainID: cosmosTx.chainID,
Expand Down Expand Up @@ -430,6 +465,12 @@ export class SkipRouter {
fee.amount = [_fee] as Coin[];
}
}

if (fee.amount.length > 1) {
// @ts-expect-error - fee amount is readonly
fee.amount = [fee.amount[0]];
}

const { accountNumber, sequence } = await this.getAccountNumberAndSequence(
signerAddress,
chainID,
Expand Down

0 comments on commit ac73adc

Please sign in to comment.