Skip to content

Commit

Permalink
Chore/cosmos exec condition (#301)
Browse files Browse the repository at this point in the history
* chore: temp cosmos condition & signer parsing to handle more cosmos providers

* chore: branch cut release for sdk v1.14.16-beta.0 (#297)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: add option to use signAndBroadcast instead of sign (#299)

Co-authored-by: pilot <8565879+odcey@users.noreply.github.com>

* chore: remove console.log

* refactor: extract fees constants

---------

Co-authored-by: pilot <8565879+odcey@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 8, 2024
1 parent a31711e commit 400445d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@


## [1.14.16-beta.0](https://github.com/0xsquid/api-sdk/compare/v1.14.1...v1.14.16-beta.0) (2024-03-27)


### Features

* add chainId property to evm balances response ([#239](https://github.com/0xsquid/api-sdk/issues/239)) ([e5166c0](https://github.com/0xsquid/api-sdk/commit/e5166c01790ad18f4517e83b20698d190fa60759))
* support injective network ([#279](https://github.com/0xsquid/api-sdk/issues/279)) ([42f09e6](https://github.com/0xsquid/api-sdk/commit/42f09e64b6dbff391278f27e4acd8172c1edae1a))


### Bug Fixes

* bignumber formatting ([#255](https://github.com/0xsquid/api-sdk/issues/255)) ([ea7a775](https://github.com/0xsquid/api-sdk/commit/ea7a7756767f4dd2c0a8b6ca23666e116b6fa0a6))
* handle ledger amino messages ([#215](https://github.com/0xsquid/api-sdk/issues/215)) ([2ef50f7](https://github.com/0xsquid/api-sdk/commit/2ef50f76d2429cca74c71a1fd1324beff9a90f0c)), closes [#216](https://github.com/0xsquid/api-sdk/issues/216) [#224](https://github.com/0xsquid/api-sdk/issues/224)
* handle possible undefined value that could throw bignumber error ([#261](https://github.com/0xsquid/api-sdk/issues/261)) ([5886f43](https://github.com/0xsquid/api-sdk/commit/5886f436faef9797d544a94d0200208fd716a363))
* parse undefined memo sent from api ([#237](https://github.com/0xsquid/api-sdk/issues/237)) ([6d42fdd](https://github.com/0xsquid/api-sdk/commit/6d42fdd45afc33bb81b192fa3e1c42694f1c6ca7))
* use a different rpc url for each chain ([#230](https://github.com/0xsquid/api-sdk/issues/230)) ([53bfa60](https://github.com/0xsquid/api-sdk/commit/53bfa60b9b314a7412b265fdea6e7de4454e49ea))
* use all chains when no chains are specified ([#233](https://github.com/0xsquid/api-sdk/issues/233)) ([ca638dd](https://github.com/0xsquid/api-sdk/commit/ca638dd1aaa3395272788880fd0a195be55db525))


### Reverts

* Revert "chore: branch cut release for sdk v1.14.9" ([7497aaa](https://github.com/0xsquid/api-sdk/commit/7497aaade74c5af75b12291d8be57f10aa022601))

## [1.14.15](https://github.com/0xsquid/api-sdk/compare/v1.14.1...v1.14.15) (2024-03-10)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xsquid/sdk",
"version": "1.14.15",
"version": "1.14.16-beta.0",
"description": "🛠 An SDK for building applications on top of 0xsquid",
"repository": {
"type": "git",
Expand Down
47 changes: 30 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toUtf8 } from "@cosmjs/encoding";
import {
AminoTypes,
Coin,
DeliverTxResponse,
GasPrice,
SigningStargateClient,
calculateFee,
Expand Down Expand Up @@ -313,8 +314,11 @@ export class Squid {
signerAddress,
route,
executionSettings,
overrides
}: ExecuteRoute): Promise<ethers.providers.TransactionResponse | TxRaw> {
overrides,
useBroadcast = false
}: ExecuteRoute): Promise<
ethers.providers.TransactionResponse | TxRaw | DeliverTxResponse
> {
this.validateInit();

if (!route.transactionRequest) {
Expand All @@ -326,17 +330,15 @@ export class Squid {
});
}

const isEvmChainId = Number(route.params.fromChain) > 0;

// handle cosmos case
if (
signer instanceof SigningStargateClient ||
signer.constructor.name === "SigningStargateClient" ||
signer instanceof SigningCosmWasmClient ||
signer.constructor.name === "SigningCosmWasmClient"
) {
if (!isEvmChainId) {
return await this.executeRouteCosmos(
signer as SigningStargateClient,
signerAddress!,
route
route,
useBroadcast
);
}

Expand Down Expand Up @@ -382,7 +384,7 @@ export class Squid {
fromAmount: params.fromAmount,
fromChain,
infiniteApproval: executionSettings?.infiniteApproval,
signer,
signer: signer as ethers.Signer,
overrides: _overrides
});
}
Expand All @@ -402,7 +404,7 @@ export class Squid {
};
}

return await signer.sendTransaction(tx);
return await (signer as ethers.Signer).sendTransaction(tx);
}

public getRawTxHex({
Expand Down Expand Up @@ -463,8 +465,9 @@ export class Squid {
private async executeRouteCosmos(
signer: SigningStargateClient | SigningCosmWasmClient,
signerAddress: string,
route: RouteData
): Promise<TxRaw> {
route: RouteData,
useBroadcast = false
): Promise<TxRaw | DeliverTxResponse> {
const cosmosMsg: CosmosMsg = JSON.parse(route.transactionRequest!.data);
const msgs = [];
switch (cosmosMsg.msgTypeUrl) {
Expand Down Expand Up @@ -532,14 +535,24 @@ export class Squid {
""
);
const gasMultiplier = Number(route.transactionRequest!.maxFeePerGas) || 1.3;
const fee = calculateFee(
Math.trunc(estimatedGas * gasMultiplier),
GasPrice.fromString(route.transactionRequest!.gasPrice)
);

if (useBroadcast) {
return (signer as SigningCosmWasmClient).signAndBroadcast(
signerAddress,
[fromAminoMsg],
fee,
""
);
}

return (signer as SigningCosmWasmClient).sign(
signerAddress,
[fromAminoMsg],
calculateFee(
Math.trunc(estimatedGas * gasMultiplier),
GasPrice.fromString(route.transactionRequest!.gasPrice)
),
fee,
""
);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export type ExecuteRoute = {
setGasPrice?: boolean;
};
overrides?: OverrideParams;
useBroadcast?: boolean;
};

export type Allowance = {
Expand Down

0 comments on commit 400445d

Please sign in to comment.