Skip to content

Commit

Permalink
Merge pull request #4 from polywrap/pileks/checksum-address
Browse files Browse the repository at this point in the history
use checksum addresses when providing API Kit with an ethereum address
  • Loading branch information
Niraj-Kamdar authored Oct 11, 2023
2 parents 047a1f9 + 8527225 commit 7f43e83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@polywrap/safe-api-plugin",
"description": "Safe API Plugin for Polywrap",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/e2e/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EthersAdapter } from "@safe-global/protocol-kit";
import { PolywrapClient } from "@polywrap/client-js";
import { PolywrapClientConfigBuilder } from "@polywrap/client-config-builder-js";
import { Safe } from "../types";
import { safeApiPlugin } from "../..";
import { ethers } from "ethers";
import { EthersAdapter } from "@safe-global/protocol-kit";
import { safeApiPlugin } from "../..";

jest.setTimeout(500000);

Expand Down
84 changes: 54 additions & 30 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import SafeApiKit from "@safe-global/api-kit";
import { SafeApiKitConfig } from "@safe-global/api-kit";
import { OperationType as CoreOperationType } from "@safe-global/safe-core-sdk-types";
import { Signer } from "ethers";

import { CoreClient, Module, manifest } from "./wrap";

import * as Types from "./wrap";

import { CoreClient, Module, manifest } from "./wrap";
import { PluginFactory, PluginPackage } from "@polywrap/plugin-js";
import { Signer, utils } from "ethers";

import { OperationType as CoreOperationType } from "@safe-global/safe-core-sdk-types";
import SafeApiKit from "@safe-global/api-kit";
import { SafeApiKitConfig } from "@safe-global/api-kit";

type SafeApiConfig = SafeApiKitConfig & {
signer: Signer;
Expand Down Expand Up @@ -65,15 +64,15 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.OwnerResponse> {
return this.safe.getSafesByOwner(args.ownerAddress);
return this.safe.getSafesByOwner(utils.getAddress(args.ownerAddress));
}

async getSafesByModule(
args: Types.Args_getSafesByModule,
client: CoreClient,
env?: null
): Promise<Types.ModulesResponse> {
return this.safe.getSafesByModule(args.moduleAddress);
return this.safe.getSafesByModule(utils.getAddress(args.moduleAddress));
}

async getTransaction(
Expand Down Expand Up @@ -105,7 +104,7 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.SafeInfoResponse> {
return this.safe.getSafeInfo(args.safeAddress);
return this.safe.getSafeInfo(utils.getAddress(args.safeAddress));
}

async getSafeDelegates(
Expand All @@ -114,9 +113,15 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
env?: null
): Promise<Types.SafeDelegateListResponse> {
return this.safe.getSafeDelegates({
safeAddress: args.safeAddress || undefined,
delegateAddress: args.delegateAddress || undefined,
delegatorAddress: args.delegatorAddress || undefined,
safeAddress: args.safeAddress
? utils.getAddress(args.safeAddress)
: undefined,
delegateAddress: args.delegateAddress
? utils.getAddress(args.delegateAddress)
: undefined,
delegatorAddress: args.delegatorAddress
? utils.getAddress(args.delegatorAddress)
: undefined,
label: args.label || undefined,
offset: args.offset || undefined,
limit: args.limit || undefined,
Expand All @@ -130,6 +135,9 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
): Promise<Types.SafeDelegateResponse> {
return this.safe.addSafeDelegate({
...args,
safeAddress: utils.getAddress(args.safeAddress),
delegateAddress: utils.getAddress(args.delegateAddress),
delegatorAddress: utils.getAddress(args.delegatorAddress),
signer: this.config.signer,
});
}
Expand All @@ -141,6 +149,8 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
): Promise<Types.Boolean> {
await this.safe.removeSafeDelegate({
...args,
delegateAddress: utils.getAddress(args.delegateAddress),
delegatorAddress: utils.getAddress(args.delegatorAddress),
signer: this.config.signer,
});
return true;
Expand All @@ -151,18 +161,22 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.SafeCreationInfoResponse> {
return this.safe.getSafeCreationInfo(args.safeAddress);
return this.safe.getSafeCreationInfo(utils.getAddress(args.safeAddress));
}

async estimateSafeTransaction(
args: Types.Args_estimateSafeTransaction,
client: CoreClient,
env?: null
): Promise<Types.SafeMultisigTransactionEstimateResponse> {
return this.safe.estimateSafeTransaction(args.safeAddress, {
...args.safeTransaction,
data: args.safeTransaction.data || undefined,
});
return this.safe.estimateSafeTransaction(
utils.getAddress(args.safeAddress),
{
...args.safeTransaction,
to: utils.getAddress(args.safeTransaction.to),
data: args.safeTransaction.data || undefined,
}
);
}

async proposeTransaction(
Expand All @@ -172,8 +186,11 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
): Promise<Types.Boolean> {
await this.safe.proposeTransaction({
...args,
safeAddress: utils.getAddress(args.safeAddress),
senderAddress: utils.getAddress(args.senderAddress),
safeTransactionData: {
...args.safeTransactionData,
to: utils.getAddress(args.safeTransactionData.to),
operation: toCoreOperationType(args.safeTransactionData.operation),
},
origin: args.origin || undefined,
Expand All @@ -186,23 +203,27 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.TransferListResponse> {
return this.safe.getIncomingTransactions(args.safeAddress);
return this.safe.getIncomingTransactions(
utils.getAddress(args.safeAddress)
);
}

async getModuleTransactions(
args: Types.Args_getModuleTransactions,
client: CoreClient,
env?: null
): Promise<Types.SafeModuleTransactionListResponse> {
return this.safe.getModuleTransactions(args.safeAddress);
return this.safe.getModuleTransactions(utils.getAddress(args.safeAddress));
}

async getMultisigTransactions(
args: Types.Args_getMultisigTransactions,
client: CoreClient,
env?: null
): Promise<Types.SafeMultisigTransactionListResponse> {
return this.safe.getMultisigTransactions(args.safeAddress);
return this.safe.getMultisigTransactions(
utils.getAddress(args.safeAddress)
);
}

async getPendingTransactions(
Expand All @@ -211,7 +232,7 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
env?: null
): Promise<Types.SafeMultisigTransactionListResponse> {
return this.safe.getPendingTransactions(
args.safeAddress,
utils.getAddress(args.safeAddress),
args.currentNonce || undefined
);
}
Expand All @@ -221,25 +242,28 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.AllTransactionsListResponse> {
const result = await this.safe.getAllTransactions(args.safeAddress, {
executed: args.options?.executed || undefined,
queued: args.options?.queued || undefined,
trusted: args.options?.trusted || undefined,
});
const result = await this.safe.getAllTransactions(
utils.getAddress(args.safeAddress),
{
executed: args.options?.executed || undefined,
queued: args.options?.queued || undefined,
trusted: args.options?.trusted || undefined,
}
);
return {
count: result.count,
next: result.next,
previous: result.previous,
results: result.results.map((res) => JSON.stringify(res)),
}
};
}

async getNextNonce(
args: Types.Args_getNextNonce,
client: CoreClient,
env?: null
): Promise<Types.Int> {
return this.safe.getNextNonce(args.safeAddress);
return this.safe.getNextNonce(utils.getAddress(args.safeAddress));
}

async getTokenList(
Expand All @@ -255,7 +279,7 @@ export class SafeApiPlugin extends Module<SafeApiConfig> {
client: CoreClient,
env?: null
): Promise<Types.TokenInfoResponse> {
return this.safe.getToken(args.tokenAddress);
return this.safe.getToken(utils.getAddress(args.tokenAddress));
}
}

Expand Down

0 comments on commit 7f43e83

Please sign in to comment.