Skip to content

Commit

Permalink
Merge branch 'feat/add-eip1193-provider' into fixes-for-1193
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanra committed Apr 29, 2024
2 parents 333dd51 + f03d793 commit 6199b3b
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 167 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/api-kit-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: |
yarn install --frozen-lockfile
yarn build
- name: Yarn install
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Test
run: |
cd packages/api-kit
yarn test:ci:ethers
yarn test:ci:web3
Expand Down
5 changes: 1 addition & 4 deletions guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ In the examples below, you can see `provider` and `signer` properties, which rep
- `provider`: You can provide an EIP-1193 compatible provider or an HTTP/WebSocket RPC URL.
- `signer`: This is optional. If not provided, we will try to get the connected account of the provider. If you provide it, it represents either the provider's address you want to use or a private key, which we will use internally to retrieve the provider's address.

````js


### Initialize the Safe API Kit

As stated in the introduction, the [Safe API Kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/api-kit) consumes the [Safe Transaction Service API](https://github.com/safe-global/safe-transaction-service). To start using this library, create a new instance of the `SafeApiKit` class, imported from `@safe-global/api-kit` and pass the URL to the constructor of the Safe Transaction Service you want to use depending on the network.
Expand All @@ -44,7 +41,7 @@ As stated in the introduction, the [Safe API Kit](https://github.com/safe-global
import SafeApiKit from '@safe-global/api-kit'

const safeService = new SafeApiKit({ chainId })
````
```

Using the `chainId` is enough for chains where Safe runs a Transaction Service. For those chains where Safe doesn't run a service, use the `txServiceUrl` parameter to set the custom service endpoint.

Expand Down
7 changes: 1 addition & 6 deletions packages/protocol-kit/src/contracts/BaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import {
EncodeFunction,
EstimateGasFunction,
EthersTransactionOptions,
GetAddressFunction,
SafeVersion
} from '@safe-global/safe-core-sdk-types'
Expand Down Expand Up @@ -93,11 +92,7 @@ class BaseContract<ContractAbiType extends InterfaceAbi & Abi> {
return this.contract.interface.encodeFunctionData(functionToEncode, args as ReadonlyArray<[]>)
}

estimateGas: EstimateGasFunction<ContractAbiType, EthersTransactionOptions> = (
functionToEstimate,
args,
options = {}
) => {
estimateGas: EstimateGasFunction<ContractAbiType> = (functionToEstimate, args, options = {}) => {
const contractMethodToEstimate = this.contract.getFunction(functionToEstimate)
return contractMethodToEstimate.estimateGas(...(args as ReadonlyArray<[]>), options)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
CreateCallContract_v1_3_0_Abi,
CreateCallContract_v1_3_0_Contract,
createCall_1_3_0_ContractArtifacts,
AdapterSpecificContractFunction,
EthersTransactionOptions
SafeContractFunction
} from '@safe-global/safe-core-sdk-types'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
Expand Down Expand Up @@ -48,14 +47,13 @@ class CreateCallContract_v1_3_0

/**
* @param args - Array[value, deploymentData]
* @param options - EthersTransactionOptions
* @returns Promise<EthersTransactionResult>
* @param options - TransactionOptions
* @returns Promise<TransactionResult>
*/
performCreate: AdapterSpecificContractFunction<
CreateCallContract_v1_3_0_Abi,
'performCreate',
EthersTransactionOptions
> = async (args, options) => {
performCreate: SafeContractFunction<CreateCallContract_v1_3_0_Abi, 'performCreate'> = async (
args,
options
) => {
if (options && !options.gasLimit) {
options.gasLimit = (
await this.estimateGas('performCreate', [...args], { ...options })
Expand All @@ -67,14 +65,13 @@ class CreateCallContract_v1_3_0

/**
* @param args - Array[value, deploymentData, salt]
* @param options - EthersTransactionOptions
* @returns Promise<EthersTransactionResult>
* @param options - TransactionOptions
* @returns Promise<TransactionResult>
*/
performCreate2: AdapterSpecificContractFunction<
CreateCallContract_v1_3_0_Abi,
'performCreate2',
EthersTransactionOptions
> = async (args, options) => {
performCreate2: SafeContractFunction<CreateCallContract_v1_3_0_Abi, 'performCreate2'> = async (
args,
options
) => {
if (options && !options.gasLimit) {
options.gasLimit = (await this.estimateGas('performCreate2', args, options)).toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
CreateCallContract_v1_4_1_Abi,
CreateCallContract_v1_4_1_Contract,
createCall_1_4_1_ContractArtifacts,
AdapterSpecificContractFunction,
EthersTransactionOptions
SafeContractFunction
} from '@safe-global/safe-core-sdk-types'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'

Expand Down Expand Up @@ -48,14 +47,13 @@ class CreateCallContract_v1_4_1

/**
* @param args - Array[value, deploymentData]
* @param options - EthersTransactionOptions
* @returns Promise<EthersTransactionResult>
* @param options - TransactionOptions
* @returns Promise<TransactionResult>
*/
performCreate: AdapterSpecificContractFunction<
CreateCallContract_v1_4_1_Abi,
'performCreate',
EthersTransactionOptions
> = async (args, options) => {
performCreate: SafeContractFunction<CreateCallContract_v1_4_1_Abi, 'performCreate'> = async (
args,
options
) => {
if (options && !options.gasLimit) {
options.gasLimit = (await this.estimateGas('performCreate', args, options)).toString()
}
Expand All @@ -65,14 +63,13 @@ class CreateCallContract_v1_4_1

/**
* @param args - Array[value, deploymentData, salt]
* @param options - EthersTransactionOptions
* @returns Promise<EthersTransactionResult>
* @param options - TransactionOptions
* @returns Promise<TransactionResult>
*/
performCreate2: AdapterSpecificContractFunction<
CreateCallContract_v1_4_1_Abi,
'performCreate2',
EthersTransactionOptions
> = async (args, options) => {
performCreate2: SafeContractFunction<CreateCallContract_v1_4_1_Abi, 'performCreate2'> = async (
args,
options
) => {
if (options && !options.gasLimit) {
options.gasLimit = (
await this.estimateGas('performCreate2', [...args], { ...options })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SafeTransaction,
SafeContract_v1_0_0_Contract,
safe_1_0_0_ContractArtifacts,
EthersTransactionOptions,
EthersTransactionResult
TransactionOptions,
TransactionResult
} from '@safe-global/safe-core-sdk-types'
import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/utils/constants'

Expand Down Expand Up @@ -194,10 +194,7 @@ class SafeContract_v1_0_0
* @param options - Optional transaction options.
* @returns Transaction result.
*/
async approveHash(
hash: string,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
async approveHash(hash: string, options?: TransactionOptions): Promise<TransactionResult> {
const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options))
const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit })

Expand All @@ -212,8 +209,8 @@ class SafeContract_v1_0_0
*/
async execTransaction(
safeTransaction: SafeTransaction,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
options?: TransactionOptions
): Promise<TransactionResult> {
const gasLimit =
options?.gasLimit ||
(await this.estimateGas(
Expand Down Expand Up @@ -283,7 +280,7 @@ class SafeContract_v1_0_0
*/
async isValidTransaction(
safeTransaction: SafeTransaction,
options: EthersTransactionOptions = {}
options: TransactionOptions = {}
): Promise<boolean> {
try {
const gasLimit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SafeContract_v1_1_1_Function,
SafeTransaction,
safe_1_1_1_ContractArtifacts,
EthersTransactionOptions,
EthersTransactionResult
TransactionOptions,
TransactionResult
} from '@safe-global/safe-core-sdk-types'

/**
Expand Down Expand Up @@ -180,10 +180,7 @@ class SafeContract_v1_1_1
* @param options - Optional transaction options.
* @returns Transaction result.
*/
async approveHash(
hash: string,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
async approveHash(hash: string, options?: TransactionOptions): Promise<TransactionResult> {
const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options))
const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit })

Expand All @@ -198,8 +195,8 @@ class SafeContract_v1_1_1
*/
async execTransaction(
safeTransaction: SafeTransaction,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
options?: TransactionOptions
): Promise<TransactionResult> {
const gasLimit =
options?.gasLimit ||
(await this.estimateGas(
Expand Down Expand Up @@ -257,7 +254,7 @@ class SafeContract_v1_1_1
*/
async isValidTransaction(
safeTransaction: SafeTransaction,
options: EthersTransactionOptions = {}
options: TransactionOptions = {}
): Promise<boolean> {
try {
const gasLimit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
SafeContract_v1_2_0_Function,
SafeTransaction,
safe_1_2_0_ContractArtifacts,
EthersTransactionOptions,
EthersTransactionResult
TransactionOptions,
TransactionResult
} from '@safe-global/safe-core-sdk-types'

/**
Expand Down Expand Up @@ -189,10 +189,7 @@ class SafeContract_v1_2_0
* @param options - Optional transaction options.
* @returns Transaction result.
*/
async approveHash(
hash: string,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
async approveHash(hash: string, options?: TransactionOptions): Promise<TransactionResult> {
const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options))
const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit })

Expand All @@ -207,8 +204,8 @@ class SafeContract_v1_2_0
*/
async execTransaction(
safeTransaction: SafeTransaction,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
options?: TransactionOptions
): Promise<TransactionResult> {
const gasLimit =
options?.gasLimit ||
(await this.estimateGas(
Expand Down Expand Up @@ -259,10 +256,7 @@ class SafeContract_v1_2_0
* @param options - Optional transaction options.
* @returns True, if the given transactions is valid.
*/
async isValidTransaction(
safeTransaction: SafeTransaction,
options: EthersTransactionOptions = {}
) {
async isValidTransaction(safeTransaction: SafeTransaction, options: TransactionOptions = {}) {
try {
const gasLimit =
options?.gasLimit ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SafeContract_v1_3_0_Function,
SafeTransaction,
safe_1_3_0_ContractArtifacts,
EthersTransactionOptions,
EthersTransactionResult
TransactionOptions,
TransactionResult
} from '@safe-global/safe-core-sdk-types'
/**
* SafeContract_v1_3_0 is the implementation specific to the Safe contract version 1.3.0.
Expand Down Expand Up @@ -194,10 +194,7 @@ class SafeContract_v1_3_0
* @param options - Optional transaction options.
* @returns True, if the given transactions is valid.
*/
async isValidTransaction(
safeTransaction: SafeTransaction,
options: EthersTransactionOptions = {}
) {
async isValidTransaction(safeTransaction: SafeTransaction, options: TransactionOptions = {}) {
try {
const gasLimit =
options?.gasLimit ||
Expand Down Expand Up @@ -244,8 +241,8 @@ class SafeContract_v1_3_0
*/
async execTransaction(
safeTransaction: SafeTransaction,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
options?: TransactionOptions
): Promise<TransactionResult> {
const gasLimit =
options?.gasLimit ||
(await this.estimateGas(
Expand Down Expand Up @@ -297,10 +294,7 @@ class SafeContract_v1_3_0
* @param options - Optional transaction options.
* @returns Transaction result.
*/
async approveHash(
hash: string,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
async approveHash(hash: string, options?: TransactionOptions): Promise<TransactionResult> {
const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options))
const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SafeContract_v1_4_1_Function,
SafeTransaction,
safe_1_4_1_ContractArtifacts,
EthersTransactionOptions,
EthersTransactionResult
TransactionOptions,
TransactionResult
} from '@safe-global/safe-core-sdk-types'

/**
Expand Down Expand Up @@ -195,10 +195,7 @@ class SafeContract_v1_4_1
* @param options - Optional transaction options.
* @returns True, if the given transactions is valid.
*/
async isValidTransaction(
safeTransaction: SafeTransaction,
options: EthersTransactionOptions = {}
) {
async isValidTransaction(safeTransaction: SafeTransaction, options: TransactionOptions = {}) {
try {
const gasLimit =
options?.gasLimit ||
Expand Down Expand Up @@ -245,8 +242,8 @@ class SafeContract_v1_4_1
*/
async execTransaction(
safeTransaction: SafeTransaction,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
options?: TransactionOptions
): Promise<TransactionResult> {
const gasLimit =
options?.gasLimit ||
(await this.estimateGas(
Expand Down Expand Up @@ -298,10 +295,7 @@ class SafeContract_v1_4_1
* @param options - Optional transaction options.
* @returns Transaction result.
*/
async approveHash(
hash: string,
options?: EthersTransactionOptions
): Promise<EthersTransactionResult> {
async approveHash(hash: string, options?: TransactionOptions): Promise<TransactionResult> {
const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options))
const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit })

Expand Down
Loading

0 comments on commit 6199b3b

Please sign in to comment.