defi-kit 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2737,14 +2737,20 @@ var Operator;
2737
2737
  // node_modules/zodiac-roles-sdk/build/esm/sdk/src/permissions/utils.js
2738
2738
  import { keccak256, ParamType, toUtf8Bytes } from "ethers/lib/utils";
2739
2739
  var sighash = (signature) => keccak256(toUtf8Bytes(signature)).substring(0, 10);
2740
- var coerceFunctionPermission = (permission) => {
2741
- return {
2742
- targetAddress: permission.targetAddress.toLowerCase(),
2743
- selector: "selector" in permission ? permission.selector.toLowerCase() : sighash(permission.signature),
2744
- condition: typeof permission.condition === "function" ? permission.condition(ParamType.from("bytes")) : permission.condition,
2745
- send: permission.send,
2746
- delegatecall: permission.delegatecall
2747
- };
2740
+ var coercePermission = (permission) => {
2741
+ if (isFunctionScoped(permission)) {
2742
+ return {
2743
+ targetAddress: permission.targetAddress.toLowerCase(),
2744
+ selector: "selector" in permission ? permission.selector.toLowerCase() : sighash(permission.signature),
2745
+ condition: typeof permission.condition === "function" ? permission.condition(ParamType.from("bytes")) : permission.condition,
2746
+ send: permission.send,
2747
+ delegatecall: permission.delegatecall
2748
+ };
2749
+ }
2750
+ return permission;
2751
+ };
2752
+ var isFunctionScoped = (permission) => {
2753
+ return "selector" in permission || "signature" in permission;
2748
2754
  };
2749
2755
 
2750
2756
  // node_modules/zodiac-roles-sdk/build/esm/sdk/src/permissions/authoring/conditions/allowances.js
@@ -2777,7 +2783,7 @@ var makeAllowFunction = (contract, name) => {
2777
2783
  signature: functionFragment.format("sighash"),
2778
2784
  condition: scopings.length > 0 ? c.calldataMatches(scopings, functionInputs)() : void 0
2779
2785
  };
2780
- return applyOptions(coerceFunctionPermission(presetFunction), options);
2786
+ return applyOptions(coercePermission(presetFunction), options);
2781
2787
  };
2782
2788
  };
2783
2789
  var applyOptions = (entry, options) => {
@@ -15565,39 +15571,50 @@ var filterPoolsByTokens2 = (sell, buy, pools) => {
15565
15571
  // src/protocols/lido/index.ts
15566
15572
  import { c as c11 } from "zodiac-roles-sdk";
15567
15573
  var eth9 = {
15568
- deposit: () => [
15569
- ...allowErc20Approve(
15570
- [contracts.mainnet.lido.steth],
15571
- [contracts.mainnet.lido.wsteth]
15572
- ),
15573
- ...allowErc20Approve(
15574
- [contracts.mainnet.lido.steth, contracts.mainnet.lido.wsteth],
15575
- [contracts.mainnet.lido.unsteth]
15576
- ),
15577
- allow.mainnet.lido.wsteth.wrap(),
15578
- allow.mainnet.lido.wsteth.unwrap(),
15579
- allow.mainnet.lido.steth.submit(void 0, { send: true }),
15580
- // Request stETH Withdrawal - Locks your stETH in the queue. In exchange you receive an NFT, that represents your position
15581
- // in the queue
15582
- allow.mainnet.lido.unsteth.requestWithdrawals(void 0, c11.avatar),
15583
- // When the unstETH has no allowance over the owner's stETH
15584
- allow.mainnet.lido.unsteth.requestWithdrawalsWithPermit(
15585
- void 0,
15586
- c11.avatar
15587
- ),
15588
- // Request wstETH Withdrawal - Transfers the wstETH to the unstETH to be burned in exchange for stETH. Then it locks your stETH
15589
- // in the queue. In exchange you receive an NFT, that represents your position in the queue
15590
- allow.mainnet.lido.unsteth.requestWithdrawalsWstETH(void 0, c11.avatar),
15591
- // When the unstETH has no allowance over the owner's wstETH
15592
- allow.mainnet.lido.unsteth.requestWithdrawalsWstETHWithPermit(
15593
- void 0,
15594
- c11.avatar
15595
- ),
15596
- // Claim ETH - Once the request is finalized by the oracle report and becomes claimable,
15597
- // this function claims your ether and burns the NFT
15598
- allow.mainnet.lido.unsteth.claimWithdrawal(),
15599
- allow.mainnet.lido.unsteth.claimWithdrawals()
15600
- ]
15574
+ deposit: () => Object.assign(
15575
+ [
15576
+ ...allowErc20Approve(
15577
+ [contracts.mainnet.lido.steth],
15578
+ [contracts.mainnet.lido.wsteth]
15579
+ ),
15580
+ ...allowErc20Approve(
15581
+ [contracts.mainnet.lido.steth, contracts.mainnet.lido.wsteth],
15582
+ [contracts.mainnet.lido.unsteth]
15583
+ ),
15584
+ allow.mainnet.lido.wsteth.wrap(),
15585
+ allow.mainnet.lido.wsteth.unwrap(),
15586
+ allow.mainnet.lido.steth.submit(void 0, { send: true }),
15587
+ // Request stETH Withdrawal - Locks your stETH in the queue. In exchange you receive an NFT, that represents your position
15588
+ // in the queue
15589
+ allow.mainnet.lido.unsteth.requestWithdrawals(void 0, c11.avatar),
15590
+ // When the unstETH has no allowance over the owner's stETH
15591
+ allow.mainnet.lido.unsteth.requestWithdrawalsWithPermit(
15592
+ void 0,
15593
+ c11.avatar
15594
+ ),
15595
+ // Request wstETH Withdrawal - Transfers the wstETH to the unstETH to be burned in exchange for stETH. Then it locks your stETH
15596
+ // in the queue. In exchange you receive an NFT, that represents your position in the queue
15597
+ allow.mainnet.lido.unsteth.requestWithdrawalsWstETH(
15598
+ void 0,
15599
+ c11.avatar
15600
+ ),
15601
+ // When the unstETH has no allowance over the owner's wstETH
15602
+ allow.mainnet.lido.unsteth.requestWithdrawalsWstETHWithPermit(
15603
+ void 0,
15604
+ c11.avatar
15605
+ ),
15606
+ // Claim ETH - Once the request is finalized by the oracle report and becomes claimable,
15607
+ // this function claims your ether and burns the NFT
15608
+ allow.mainnet.lido.unsteth.claimWithdrawal(),
15609
+ allow.mainnet.lido.unsteth.claimWithdrawals()
15610
+ ],
15611
+ {
15612
+ annotation: {
15613
+ uri: "https://kit.karpatkey.com/permissions/eth/lido/deposit",
15614
+ schema: "https://kit.karpatkey.com/api/v1/openapi.json"
15615
+ }
15616
+ }
15617
+ )
15601
15618
  };
15602
15619
 
15603
15620
  // src/protocols/spark/_info.ts
@@ -15821,23 +15838,60 @@ var eth10 = {
15821
15838
  // },
15822
15839
  };
15823
15840
 
15824
- // src/protocols/index.ts
15825
- var eth11 = {
15826
- aave_v2: eth,
15827
- aave_v3: eth2,
15828
- aura: eth4,
15829
- balancer: eth3,
15830
- compound_v2: eth5,
15831
- compound_v3: eth6,
15832
- convex: eth7,
15833
- curve: eth8,
15834
- lido: eth9,
15835
- spark: eth10
15841
+ // src/protocols/annotate.ts
15842
+ var annotate = (actionFunction, path) => {
15843
+ const annotated = (params) => {
15844
+ const result = actionFunction(params);
15845
+ const queryString = new URLSearchParams(params).toString();
15846
+ const joinedPath = path.join("/");
15847
+ Object.assign(result, {
15848
+ annotation: {
15849
+ uri: `https://kit.karpatkey.com/permissions/${joinedPath}?${queryString}`,
15850
+ schema: "https://kit.karpatkey.com/api/v1/openapi.json"
15851
+ }
15852
+ });
15853
+ return result;
15854
+ };
15855
+ return annotated;
15836
15856
  };
15837
- var gor2 = {
15838
- cowswap: gor
15857
+ var annotateAll = (actions, chainPrefix) => {
15858
+ const annotated = {};
15859
+ for (const [protocolKey, protocolActions] of Object.entries(actions)) {
15860
+ annotated[protocolKey] = {};
15861
+ for (const [actionKey, action] of Object.entries(protocolActions)) {
15862
+ annotated[protocolKey][actionKey] = annotate(action, [
15863
+ chainPrefix,
15864
+ protocolKey,
15865
+ actionKey
15866
+ ]);
15867
+ }
15868
+ }
15869
+ return annotated;
15839
15870
  };
15840
15871
 
15872
+ // src/protocols/index.ts
15873
+ var eth11 = annotateAll(
15874
+ {
15875
+ aave_v2: eth,
15876
+ aave_v3: eth2,
15877
+ aura: eth4,
15878
+ balancer: eth3,
15879
+ compound_v2: eth5,
15880
+ compound_v3: eth6,
15881
+ convex: eth7,
15882
+ curve: eth8,
15883
+ lido: eth9,
15884
+ spark: eth10
15885
+ },
15886
+ "eth"
15887
+ );
15888
+ var gor2 = annotateAll(
15889
+ {
15890
+ cowswap: gor
15891
+ },
15892
+ "gor"
15893
+ );
15894
+
15841
15895
  // src/protocols/aave/v2/schema.ts
15842
15896
  import { z } from "zod";
15843
15897
  var zToken = z.enum([
@@ -16087,40 +16141,54 @@ var gor4 = {
16087
16141
 
16088
16142
  // src/apply.ts
16089
16143
  import {
16090
- processPermissions as processPermissionsBase,
16144
+ processPermissions,
16091
16145
  checkIntegrity,
16092
- applyTargets
16146
+ applyTargets,
16147
+ applyAnnotations
16093
16148
  } from "zodiac-roles-sdk";
16094
16149
  var createApply = (chainId) => {
16095
16150
  return async function apply(roleKey, permissions, options) {
16096
- const targets = processPermissionsBase(permissions);
16151
+ const { targets, annotations } = processPermissions(permissions);
16097
16152
  checkIntegrity(targets);
16153
+ let rolesModCalls = [];
16154
+ let posterCalls = [];
16098
16155
  try {
16099
- return await applyTargets(
16100
- roleKey,
16101
- targets,
16102
- "address" in options ? { ...options, chainId } : options
16103
- );
16156
+ rolesModCalls = await applyTargets(roleKey, targets, {
16157
+ ...options,
16158
+ chainId
16159
+ });
16160
+ posterCalls = await applyAnnotations(roleKey, annotations, {
16161
+ ...options,
16162
+ chainId
16163
+ });
16104
16164
  } catch (e) {
16105
16165
  if (e instanceof Error && e.message.indexOf("not found") !== -1) {
16106
16166
  throw new NotFoundError(e.message);
16107
16167
  }
16108
16168
  throw e;
16109
16169
  }
16170
+ const value = 0n;
16171
+ return [
16172
+ ...rolesModCalls.map((data) => ({
16173
+ to: options.address,
16174
+ data,
16175
+ value
16176
+ })),
16177
+ ...posterCalls.map((data) => ({
16178
+ to: POSTER_ADDRESS,
16179
+ data,
16180
+ value
16181
+ }))
16182
+ ];
16110
16183
  };
16111
16184
  };
16185
+ var POSTER_ADDRESS = "0x000000000000cd17345801aa8147b8D3950260FF";
16112
16186
 
16113
- // src/json.ts
16187
+ // src/export.ts
16114
16188
  import { Interface } from "ethers/lib/utils";
16115
- import { rolesAbi } from "zodiac-roles-sdk";
16116
- var createExportJson = (chainId) => {
16117
- return function exportJson(address, calls, meta) {
16118
- const transactions = calls.map((data) => ({
16119
- to: address,
16120
- value: "0",
16121
- data,
16122
- ...(meta == null ? void 0 : meta.includeAbi) ? getAbiInfo(data) : {}
16123
- }));
16189
+ import { posterAbi, rolesAbi } from "zodiac-roles-sdk";
16190
+ var createExportToSafeTransactionBuilder = (chainId) => {
16191
+ return function exportToSafeTransactionBuilder(transactions, meta) {
16124
16192
  return {
16125
16193
  version: "1.0",
16126
16194
  chainId: chainId.toString(10),
@@ -16130,18 +16198,23 @@ var createExportJson = (chainId) => {
16130
16198
  description: (meta == null ? void 0 : meta.description) || "",
16131
16199
  txBuilderVersion: "1.16.2"
16132
16200
  },
16133
- transactions
16201
+ transactions: transactions.map((tx) => ({
16202
+ ...tx,
16203
+ value: tx.value.toString(10),
16204
+ ...getAbiInfo(tx)
16205
+ }))
16134
16206
  };
16135
16207
  };
16136
16208
  };
16137
- var rolesInterface = new Interface(rolesAbi);
16138
- var getAbiInfo = (data) => {
16139
- const selector = data.slice(0, 10);
16140
- const functionFragment = rolesInterface.getFunction(selector);
16209
+ var getAbiInfo = (transaction) => {
16210
+ const abi = transaction.to === POSTER_ADDRESS ? posterAbi : rolesAbi;
16211
+ const iface = new Interface(abi);
16212
+ const selector = transaction.data.slice(0, 10);
16213
+ const functionFragment = iface.getFunction(selector);
16141
16214
  if (!functionFragment) {
16142
- throw new Error(`Could not find a Roles function with selector ${selector}`);
16215
+ throw new Error(`Could not find a function with selector ${selector}`);
16143
16216
  }
16144
- const contractMethod = rolesAbi.find(
16217
+ const contractMethod = abi.find(
16145
16218
  (fragment) => fragment.type === "function" && fragment.name === functionFragment.name
16146
16219
  );
16147
16220
  if (!contractMethod) {
@@ -16150,7 +16223,7 @@ var getAbiInfo = (data) => {
16150
16223
  );
16151
16224
  }
16152
16225
  const contractInputsValues = asObject(
16153
- rolesInterface.decodeFunctionData(functionFragment, data)
16226
+ iface.decodeFunctionData(functionFragment, transaction.data)
16154
16227
  );
16155
16228
  return {
16156
16229
  contractMethod,
@@ -16173,6 +16246,6 @@ export {
16173
16246
  eth23 as eth2,
16174
16247
  gor4 as gor2,
16175
16248
  createApply,
16176
- createExportJson
16249
+ createExportToSafeTransactionBuilder
16177
16250
  };
16178
- //# sourceMappingURL=chunk-MPJKCJ3K.mjs.map
16251
+ //# sourceMappingURL=chunk-QGWTWURU.mjs.map