defender-admin-client
Advanced tools
Comparing version 1.38.0 to 1.38.1-rc.0
@@ -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 @@ } |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
4
0
147231
462
2
286
1
+ Addedamazon-cognito-identity-js@4.6.3(transitive)
+ Addedcrypto-js@4.2.0(transitive)
+ Addeddefender-base-client@1.38.1-rc.0(transitive)
- Removedethers@^5.7.2
- Removed@aws-crypto/sha256-js@1.2.2(transitive)
- Removed@aws-crypto/util@1.2.2(transitive)
- Removed@aws-sdk/types@3.686.0(transitive)
- Removed@aws-sdk/util-utf8-browser@3.259.0(transitive)
- Removed@ethersproject/abi@5.7.0(transitive)
- Removed@ethersproject/abstract-provider@5.7.0(transitive)
- Removed@ethersproject/abstract-signer@5.7.0(transitive)
- Removed@ethersproject/address@5.7.0(transitive)
- Removed@ethersproject/base64@5.7.0(transitive)
- Removed@ethersproject/basex@5.7.0(transitive)
- Removed@ethersproject/bignumber@5.7.0(transitive)
- Removed@ethersproject/bytes@5.7.0(transitive)
- Removed@ethersproject/constants@5.7.0(transitive)
- Removed@ethersproject/contracts@5.7.0(transitive)
- Removed@ethersproject/hash@5.7.0(transitive)
- Removed@ethersproject/hdnode@5.7.0(transitive)
- Removed@ethersproject/json-wallets@5.7.0(transitive)
- Removed@ethersproject/keccak256@5.7.0(transitive)
- Removed@ethersproject/logger@5.7.0(transitive)
- Removed@ethersproject/networks@5.7.1(transitive)
- Removed@ethersproject/pbkdf2@5.7.0(transitive)
- Removed@ethersproject/properties@5.7.0(transitive)
- Removed@ethersproject/providers@5.7.2(transitive)
- Removed@ethersproject/random@5.7.0(transitive)
- Removed@ethersproject/rlp@5.7.0(transitive)
- Removed@ethersproject/sha2@5.7.0(transitive)
- Removed@ethersproject/signing-key@5.7.0(transitive)
- Removed@ethersproject/solidity@5.7.0(transitive)
- Removed@ethersproject/strings@5.7.0(transitive)
- Removed@ethersproject/transactions@5.7.0(transitive)
- Removed@ethersproject/units@5.7.0(transitive)
- Removed@ethersproject/wallet@5.7.0(transitive)
- Removed@ethersproject/web@5.7.1(transitive)
- Removed@ethersproject/wordlists@5.7.0(transitive)
- Removed@smithy/types@3.6.0(transitive)
- Removedaes-js@3.0.0(transitive)
- Removedamazon-cognito-identity-js@6.3.14(transitive)
- Removedbech32@1.1.4(transitive)
- Removedbn.js@4.12.15.2.1(transitive)
- Removedbrorand@1.1.0(transitive)
- Removeddefender-base-client@1.38.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethers@5.7.2(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-sha3@0.8.0(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@3.0.1(transitive)
- Removedtslib@1.14.12.8.1(transitive)
- Removedws@7.4.6(transitive)