-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor abi handling for write transactions (#80)
* use strong types on transaction write abis * add changeset
- Loading branch information
1 parent
94cba4c
commit 9e56447
Showing
11 changed files
with
307 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@treasure-dev/tdk-core": patch | ||
--- | ||
|
||
Added strict typing on Magicswap argument utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as Sentry from "@sentry/node"; | ||
import type { Engine } from "@thirdweb-dev/engine"; | ||
import type { | ||
Abi, | ||
AbiParametersToPrimitiveTypes, | ||
ExtractAbiFunction, | ||
ExtractAbiFunctionNames, | ||
} from "abitype"; | ||
|
||
import type { TransactionArguments, TransactionOverrides } from "../schema"; | ||
|
||
export const writeTransaction = async < | ||
TAbi extends Abi, | ||
TFunctionName extends ExtractAbiFunctionNames< | ||
TAbi, | ||
"nonpayable" | "payable" | ||
> = string, | ||
>({ | ||
engine, | ||
chainId, | ||
contractAddress, | ||
backendWallet, | ||
smartAccountAddress, | ||
functionName, | ||
args, | ||
txOverrides, | ||
simulateTransaction = false, | ||
idempotencyKey, | ||
...rest | ||
}: { | ||
engine: Engine; | ||
chainId: number; | ||
contractAddress: string; | ||
backendWallet: string; | ||
smartAccountAddress: string; | ||
txOverrides?: TransactionOverrides; | ||
simulateTransaction?: boolean; | ||
idempotencyKey?: string; | ||
} & ( | ||
| { | ||
abi: TAbi; | ||
functionName: TFunctionName; | ||
args: AbiParametersToPrimitiveTypes< | ||
ExtractAbiFunction<TAbi, TFunctionName>["inputs"], | ||
"inputs" | ||
>; | ||
} | ||
| { | ||
functionName: string; | ||
args: TransactionArguments | Readonly<TransactionArguments>; | ||
} | ||
)) => { | ||
const abi = "abi" in rest ? rest.abi : undefined; | ||
Sentry.setExtra( | ||
"transaction", | ||
JSON.stringify( | ||
{ | ||
contractAddress, | ||
functionName, | ||
abi: !!abi, | ||
args, | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
const { result } = await engine.contract.write( | ||
chainId.toString(), | ||
contractAddress, | ||
backendWallet, | ||
{ | ||
// @ts-ignore: stronger type-checking than Engine | ||
abi, | ||
functionName, | ||
// @ts-ignore: stronger type-checking than Engine | ||
args, | ||
txOverrides, | ||
}, | ||
simulateTransaction, | ||
idempotencyKey, | ||
smartAccountAddress, | ||
); | ||
return result; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -797,4 +797,4 @@ export const magicSwapV2RouterABI = [ | |
stateMutability: "nonpayable", | ||
type: "function", | ||
}, | ||
]; | ||
] as const; |
Oops, something went wrong.