Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defender-admin-client

Package Overview
Dependencies
Maintainers
9
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defender-admin-client - npm Package Compare versions

Comparing version 1.38.0 to 1.38.1-rc.0

6

lib/api.d.ts

@@ -30,3 +30,2 @@ import { BaseApiClient } from 'defender-base-client';

url: string;
simulation?: SimulationResponse;
}

@@ -40,6 +39,3 @@ export declare class AdminClient extends BaseApiClient {

listContracts(): Promise<Omit<Contract, 'abi'>[]>;
createProposal(proposal: CreateProposalRequest & {
simulate?: boolean;
overrideSimulationOpts?: SimulationTransaction;
}): Promise<ProposalResponseWithUrl>;
createProposal(proposal: CreateProposalRequest): Promise<ProposalResponseWithUrl>;
listProposals(opts?: {

@@ -46,0 +42,0 @@ includeArchived?: boolean;

@@ -6,4 +6,3 @@ "use strict";

const lodash_1 = require("lodash");
const utils_1 = require("ethers/lib/utils");
const utils_2 = require("./utils");
const utils_1 = require("./utils");
class AdminClient extends defender_base_client_1.BaseApiClient {

@@ -34,55 +33,6 @@ getPoolId() {

}
// added separate from CreateProposalRequest type as the `simulate` boolean is contained within defender-client
async createProposal(proposal) {
return this.apiCall(async (api) => {
var _a, _b, _c, _d, _e;
let simulation = undefined;
let simulationData = '0x';
const isBatchProposal = (contract) => lodash_1.isArray(contract);
// handle simulation checks before creating proposal
if (proposal.simulate) {
// we do not support simulating batch proposals from the client.
if (isBatchProposal(proposal.contract)) {
throw new Error('Simulating a batch proposal is currently not supported from the API. Use the Defender UI to manually trigger a simulation.');
}
const overrideData = (_a = proposal.overrideSimulationOpts) === null || _a === void 0 ? void 0 : _a.transactionData.data;
simulationData = overrideData !== null && overrideData !== void 0 ? overrideData : '0x';
// only check if we haven't overridden the simulation data property
if (!overrideData) {
// Check if ABI is provided so we can encode the function
if (!proposal.contract.abi) {
// no ABI found, request user to pass in `data` in overrideSimulationOpts
throw new Error('Simulation requested without providing ABI. Please provide the contract ABI or use the `overrideSimulationOpts` to provide the data property directly.');
}
const contractInterface = new utils_1.Interface(proposal.contract.abi);
// this is defensive and should never happen since createProposal schema validation will fail without this property defined.
if (!proposal.functionInterface) {
// no function selected, request user to pass in `data` in overrideSimulationOpts
throw new Error('Simulation requested without providing function interface. Please provide the function interface or use the `overrideSimulationOpts` to provide the data property directly.');
}
simulationData = contractInterface.encodeFunctionData(proposal.functionInterface.name, proposal.functionInputs);
}
}
// create proposal
const response = (await api.post('/proposals', proposal));
// create simulation
if (proposal.simulate && !isBatchProposal(proposal.contract)) {
try {
simulation = await this.simulateProposal(response.contractId, response.proposalId, {
transactionData: {
from: proposal.via,
to: proposal.contract.address,
data: simulationData,
value: (_c = (_b = proposal.metadata) === null || _b === void 0 ? void 0 : _b.sendValue) !== null && _c !== void 0 ? _c : '0',
...(_d = proposal.overrideSimulationOpts) === null || _d === void 0 ? void 0 : _d.transactionData,
},
blockNumber: (_e = proposal.overrideSimulationOpts) === null || _e === void 0 ? void 0 : _e.blockNumber,
});
}
catch (e) {
// simply log so we don't block createProposal response
console.warn('Simulation Failed:', e);
}
}
return { ...response, url: utils_2.getProposalUrl(response), simulation };
return { ...response, url: utils_1.getProposalUrl(response) };
});

@@ -93,3 +43,3 @@ }

const response = (await api.get('/proposals', { params: opts }));
return response.map((proposal) => ({ ...proposal, url: utils_2.getProposalUrl(proposal) }));
return response.map((proposal) => ({ ...proposal, url: utils_1.getProposalUrl(proposal) }));
});

@@ -100,3 +50,3 @@ }

const response = (await api.get(`/contracts/${contractId}/proposals/${proposalId}`));
return { ...response, url: utils_2.getProposalUrl(response) };
return { ...response, url: utils_1.getProposalUrl(response) };
});

@@ -109,3 +59,3 @@ }

}));
return { ...response, url: utils_2.getProposalUrl(response) };
return { ...response, url: utils_1.getProposalUrl(response) };
});

@@ -118,3 +68,3 @@ }

}));
return { ...response, url: utils_2.getProposalUrl(response) };
return { ...response, url: utils_1.getProposalUrl(response) };
});

@@ -121,0 +71,0 @@ }

7

package.json
{
"name": "defender-admin-client",
"version": "1.38.0",
"version": "1.38.1-rc.0",
"description": "",

@@ -25,8 +25,7 @@ "main": "./lib/index.js",

"axios": "^0.21.2",
"defender-base-client": "1.38.0",
"ethers": "^5.7.2",
"defender-base-client": "1.38.1-rc.0",
"lodash": "^4.17.19",
"node-fetch": "^2.6.0"
},
"gitHead": "b0af2e95b86c888501e3bd6d3acaeebd9a3de99f"
"gitHead": "e828861fdd32bcc19811d307b245986240e6c494"
}

@@ -32,3 +32,3 @@ # Defender Admin Client

await client.createProposal({
contract: { address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E', network: 'goerli' }, // Target contract
contract: { address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E', network: 'rinkeby' }, // Target contract
title: 'Adjust fee to 10%', // Title of the proposal

@@ -44,41 +44,2 @@ description: 'Adjust the contract fee collected per action to 10%', // Description of the proposal

You can also optionally set the `simulate` flag as part of the `createProposal` request (as long as this is not a batch proposal) to simulate the proposal within the same request. You can override simulation parameters by setting the `overrideSimulationOpts` property, which is a `SimulationRequest` object.
```js
const proposalWithSimulation = await client.createProposal({
contract: {
address: '0xA91382E82fB676d4c935E601305E5253b3829dCD',
network: 'mainnet',
// provide abi OR overrideSimulationOpts.transactionData.data
abi: JSON.stringify(contractABI),
},
title: 'Flash',
description: 'Call the Flash() function',
type: 'custom',
metadata: {
sendTo: '0xA91382E82fB676d4c935E601305E5253b3829dCD',
sendValue: '10000000000000000',
sendCurrency: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
type: 'native',
},
},
functionInterface: { name: 'flash', inputs: [] },
functionInputs: [],
via: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
viaType: 'EOA',
// set simulate to true
simulate: true,
// optional
overrideSimulationOpts: {
transactionData: {
// or instead of ABI, you can provide data
data: '0xd336c82d',
},
},
});
```
#### Issuing DELEGATECALLs

@@ -106,3 +67,3 @@

const newImplementationAbi = '[...]';
const contract = { network: 'goerli', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
const contract = { network: 'rinkeby', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
await client.proposeUpgrade({ newImplementation, newImplementationAbi }, contract);

@@ -119,3 +80,3 @@ ```

const newImplementationAbi = '[...]';
const contract = { network: 'goerli', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
const contract = { network: 'rinkeby', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
await client.proposeUpgrade({ newImplementation, newImplementationAbi, proxyAdmin }, contract);

@@ -130,3 +91,3 @@ ```

const viaType = 'Gnosis Safe'; // or 'Gnosis Multisig', or 'EOA'
const contract = { network: 'goerli', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
const contract = { network: 'rinkeby', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
const newImplementationAbi = '[...]';

@@ -141,3 +102,3 @@ await client.proposeUpgrade({ newImplementation, newImplementationAbi, via, viaType }, contract);

```js
const contract = { network: 'goerli', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };
const contract = { network: 'rinkeby', address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E' };

@@ -304,3 +265,3 @@ // Create a pause proposal

const contract = {
network: 'goerli',
network: 'rinkeby',
address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E',

@@ -317,3 +278,3 @@ name: 'My contract', // Name of the contract if it is created along with this proposal

await client.addContract({
network: 'goerli',
network: 'rinkeby',
address: '0x28a8746e75304c0780E011BEd21C72cD78cd535E',

@@ -320,0 +281,0 @@ name: 'My contract',

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc