@pufferfinance/puffer-sdk 1.12.2 → 1.13.1
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.
- package/dist/api/puffer-client-helpers.cjs +1 -1
- package/dist/api/puffer-client-helpers.cjs.map +1 -1
- package/dist/api/puffer-client-helpers.js +70 -65
- package/dist/api/puffer-client-helpers.js.map +1 -1
- package/dist/api/puffer-client.cjs +1 -1
- package/dist/api/puffer-client.cjs.map +1 -1
- package/dist/api/puffer-client.d.ts +3 -0
- package/dist/api/puffer-client.js +20 -13
- package/dist/api/puffer-client.js.map +1 -1
- package/dist/{ccip-BO_b9tFc.cjs → ccip-C0xwQhXU.cjs} +2 -2
- package/dist/ccip-C0xwQhXU.cjs.map +1 -0
- package/dist/{ccip-DLDO0_x2.js → ccip-K-z2PL4P.js} +3 -3
- package/dist/ccip-K-z2PL4P.js.map +1 -0
- package/dist/chains/constants.cjs +1 -1
- package/dist/chains/constants.js +1 -1
- package/dist/constants-BcPRVxdH.cjs +9 -0
- package/dist/constants-BcPRVxdH.cjs.map +1 -0
- package/dist/{constants-BjRNQpT2.js → constants-CH7Tz5jz.js} +745 -694
- package/dist/constants-CH7Tz5jz.js.map +1 -0
- package/dist/contracts/abis/l1-reward-manager-abis.cjs +1 -1
- package/dist/contracts/abis/l1-reward-manager-abis.d.ts +527 -1
- package/dist/contracts/abis/l1-reward-manager-abis.js +1 -1
- package/dist/contracts/abis/l2-reward-manager-abis.cjs +1 -1
- package/dist/contracts/abis/l2-reward-manager-abis.d.ts +1416 -1
- package/dist/contracts/abis/l2-reward-manager-abis.js +1 -1
- package/dist/contracts/abis/mainnet/Distributor.cjs +2 -0
- package/dist/contracts/abis/mainnet/Distributor.cjs.map +1 -0
- package/dist/contracts/abis/mainnet/Distributor.d.ts +618 -0
- package/dist/contracts/abis/mainnet/Distributor.js +492 -0
- package/dist/contracts/abis/mainnet/Distributor.js.map +1 -0
- package/dist/contracts/abis/nucleus-accountant-abis.cjs +1 -1
- package/dist/contracts/abis/nucleus-accountant-abis.d.ts +2 -1
- package/dist/contracts/abis/nucleus-accountant-abis.js +1 -1
- package/dist/contracts/abis/nucleus-atomic-queue-abis.cjs +1 -1
- package/dist/contracts/abis/nucleus-atomic-queue-abis.d.ts +2 -1
- package/dist/contracts/abis/nucleus-atomic-queue-abis.js +1 -1
- package/dist/contracts/abis/nucleus-boring-vault-abis.cjs +1 -1
- package/dist/contracts/abis/nucleus-boring-vault-abis.d.ts +2 -1
- package/dist/contracts/abis/nucleus-boring-vault-abis.js +1 -1
- package/dist/contracts/abis/nucleus-teller-abis.cjs +1 -1
- package/dist/contracts/abis/nucleus-teller-abis.d.ts +2 -1
- package/dist/contracts/abis/nucleus-teller-abis.js +1 -1
- package/dist/contracts/abis/puf-locker-abis.cjs +1 -1
- package/dist/contracts/abis/puf-locker-abis.d.ts +484 -1
- package/dist/contracts/abis/puf-locker-abis.js +1 -1
- package/dist/contracts/abis/puffer-depositor-abis.cjs +1 -1
- package/dist/contracts/abis/puffer-depositor-abis.d.ts +663 -2
- package/dist/contracts/abis/puffer-depositor-abis.js +1 -1
- package/dist/contracts/abis/puffer-vault-abis.cjs +1 -1
- package/dist/contracts/abis/puffer-vault-abis.d.ts +4 -2
- package/dist/contracts/abis/puffer-vault-abis.js +1 -1
- package/dist/contracts/abis/puffer-withdrawal-manager-abis.cjs +1 -1
- package/dist/contracts/abis/puffer-withdrawal-manager-abis.d.ts +514 -1
- package/dist/contracts/abis/puffer-withdrawal-manager-abis.js +1 -1
- package/dist/contracts/addresses.cjs +1 -1
- package/dist/contracts/addresses.cjs.map +1 -1
- package/dist/contracts/addresses.d.ts +7 -13
- package/dist/contracts/addresses.js +6 -5
- package/dist/contracts/addresses.js.map +1 -1
- package/dist/contracts/handlers/carrot-staking-handler.cjs +1 -1
- package/dist/contracts/handlers/carrot-staking-handler.js +2 -2
- package/dist/contracts/handlers/distributor-handler.cjs +2 -0
- package/dist/contracts/handlers/distributor-handler.cjs.map +1 -0
- package/dist/contracts/handlers/distributor-handler.js +318 -0
- package/dist/contracts/handlers/distributor-handler.js.map +1 -0
- package/dist/contracts/handlers/erc20-permit-handler.cjs +1 -1
- package/dist/contracts/handlers/erc20-permit-handler.cjs.map +1 -1
- package/dist/contracts/handlers/erc20-permit-handler.d.ts +17101 -14898
- package/dist/contracts/handlers/erc20-permit-handler.js +3 -3
- package/dist/contracts/handlers/erc20-permit-handler.js.map +1 -1
- package/dist/contracts/handlers/l1-reward-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/l1-reward-manager-handler.js +2 -2
- package/dist/contracts/handlers/l2-reward-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/l2-reward-manager-handler.js +2 -2
- package/dist/contracts/handlers/mtw-carrot-handler.cjs +1 -1
- package/dist/contracts/handlers/mtw-carrot-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-accountant-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-accountant-handler.js +1 -1
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.cjs.map +1 -1
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.d.ts +7619 -14812
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.js.map +1 -1
- package/dist/contracts/handlers/nucleus-boring-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-boring-vault-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-teller-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-teller-handler.js +2 -2
- package/dist/contracts/handlers/puf-locker-handler.cjs +1 -1
- package/dist/contracts/handlers/puf-locker-handler.cjs.map +1 -1
- package/dist/contracts/handlers/puf-locker-handler.js +2 -2
- package/dist/contracts/handlers/puf-locker-handler.js.map +1 -1
- package/dist/contracts/handlers/puffer-depositor-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-depositor-handler.d.ts +11215 -14794
- package/dist/contracts/handlers/puffer-depositor-handler.js +2 -2
- package/dist/contracts/handlers/puffer-l2-depositor-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-l2-depositor-handler.js +2 -2
- package/dist/contracts/handlers/puffer-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-vault-handler.js +2 -2
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.js +2 -2
- package/dist/contracts/tokens.cjs +1 -1
- package/dist/contracts/tokens.js +1 -1
- package/dist/contracts/vaults-addresses.cjs +1 -1
- package/dist/contracts/vaults-addresses.d.ts +5 -4
- package/dist/contracts/vaults-addresses.js +1 -1
- package/dist/createWalletClient-DNLhBkOd.js +3289 -0
- package/dist/createWalletClient-DNLhBkOd.js.map +1 -0
- package/dist/createWalletClient-Di5of07E.cjs +6 -0
- package/dist/createWalletClient-Di5of07E.cjs.map +1 -0
- package/dist/{getContract-CezEyDf-.js → getContract-6ajhFbP2.js} +2 -2
- package/dist/getContract-6ajhFbP2.js.map +1 -0
- package/dist/{getContract-3QbyfZBF.cjs → getContract-ChPFzc5y.cjs} +2 -2
- package/dist/{getContract-CezEyDf-.js.map → getContract-ChPFzc5y.cjs.map} +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.js +13 -11
- package/dist/main.js.map +1 -1
- package/dist/secp256k1-B8plqpXf.cjs +2 -0
- package/dist/secp256k1-B8plqpXf.cjs.map +1 -0
- package/dist/secp256k1-Ev0s9Yr6.js +1340 -0
- package/dist/secp256k1-Ev0s9Yr6.js.map +1 -0
- package/dist/utils/version.cjs +1 -1
- package/dist/utils/version.js +1 -1
- package/dist/writeContract-BatuNuTe.cjs +32 -0
- package/dist/writeContract-BatuNuTe.cjs.map +1 -0
- package/dist/{writeContract-ChuHpJLC.js → writeContract-CjcOEtWX.js} +822 -763
- package/dist/writeContract-CjcOEtWX.js.map +1 -0
- package/package.json +15 -15
- package/dist/ccip-BO_b9tFc.cjs.map +0 -1
- package/dist/ccip-DLDO0_x2.js.map +0 -1
- package/dist/constants-BjRNQpT2.js.map +0 -1
- package/dist/constants-DA2xUb9r.cjs +0 -9
- package/dist/constants-DA2xUb9r.cjs.map +0 -1
- package/dist/contracts/handlers/carrot-staking-handler.d.ts +0 -15063
- package/dist/contracts/handlers/l1-reward-manager-handler.d.ts +0 -15107
- package/dist/contracts/handlers/l2-reward-manager-handler.d.ts +0 -15353
- package/dist/contracts/handlers/mtw-carrot-handler.d.ts +0 -15293
- package/dist/contracts/handlers/nucleus-accountant-handler.d.ts +0 -15126
- package/dist/contracts/handlers/nucleus-boring-vault-handler.d.ts +0 -15284
- package/dist/contracts/handlers/nucleus-teller-handler.d.ts +0 -15201
- package/dist/contracts/handlers/puf-locker-handler.d.ts +0 -15116
- package/dist/contracts/handlers/puffer-l2-depositor-handler.d.ts +0 -14969
- package/dist/contracts/handlers/puffer-vault-handler.d.ts +0 -17452
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.d.ts +0 -15111
- package/dist/createWalletClient-BuLYysrp.cjs +0 -4
- package/dist/createWalletClient-BuLYysrp.cjs.map +0 -1
- package/dist/createWalletClient-DNcW-ENe.js +0 -2028
- package/dist/createWalletClient-DNcW-ENe.js.map +0 -1
- package/dist/getContract-3QbyfZBF.cjs.map +0 -1
- package/dist/secp256k1-3OC5y4qp.js +0 -1579
- package/dist/secp256k1-3OC5y4qp.js.map +0 -1
- package/dist/secp256k1-bcahnPX9.cjs +0 -2
- package/dist/secp256k1-bcahnPX9.cjs.map +0 -1
- package/dist/writeContract-ChuHpJLC.js.map +0 -1
- package/dist/writeContract-D97dSJQe.cjs +0 -32
- package/dist/writeContract-D97dSJQe.cjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var c=(a,t,e)=>t in a?s(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var r=(a,t,e)=>c(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../constants-
|
|
1
|
+
"use strict";var s=Object.defineProperty;var c=(a,t,e)=>t in a?s(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var r=(a,t,e)=>c(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../constants-BcPRVxdH.cjs"),i=require("../tokens.cjs"),l=require("../abis/mainnet/CarrotStaker.cjs"),h=require("../../getContract-ChPFzc5y.cjs");class C{constructor(t,e,n){r(this,"viemChain");this.chain=t,this.walletClient=e,this.publicClient=n,this.viemChain=o.VIEM_CHAINS[t]}getContract(){const t=i.TOKENS_ADDRESSES[i.Token.sCARROT][this.chain],e=l.CarrotStaker,n={public:this.publicClient,wallet:this.walletClient};return h.getContract({address:t,abi:e,client:n})}allowance(t,e){return this.getContract().read.allowance([t,e])}balanceOf(t){return this.getContract().read.balanceOf([t])}decimals(){return this.getContract().read.decimals()}isUnstakingAllowed(){return this.getContract().read.isUnstakingAllowed()}totalSupply(){return this.getContract().read.totalSupply()}stake(t,e){return this.getContract().write.stake([e],{account:t,chain:this.viemChain})}unstake(t,e,n){return this.getContract().write.unstake([e,n],{account:t,chain:this.viemChain})}}exports.CarrotStakingHandler=C;
|
|
2
2
|
//# sourceMappingURL=carrot-staking-handler.cjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var n = Object.defineProperty;
|
|
2
2
|
var s = (a, t, e) => t in a ? n(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
3
|
var i = (a, t, e) => s(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { V as l } from "../../constants-
|
|
4
|
+
import { V as l } from "../../constants-CH7Tz5jz.js";
|
|
5
5
|
import { TOKENS_ADDRESSES as o, Token as c } from "../tokens.js";
|
|
6
6
|
import { CarrotStaker as h } from "../abis/mainnet/CarrotStaker.js";
|
|
7
|
-
import { g as C } from "../../getContract-
|
|
7
|
+
import { g as C } from "../../getContract-6ajhFbP2.js";
|
|
8
8
|
class k {
|
|
9
9
|
/**
|
|
10
10
|
* Create the handler for the `CarrotStaker` contract exposing
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var c=(i,t,e)=>t in i?o(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var s=(i,t,e)=>c(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../constants-BcPRVxdH.cjs"),u=require("../addresses.cjs"),C=require("../abis/mainnet/Distributor.cjs"),l=require("../../getContract-ChPFzc5y.cjs");class d{constructor(t,e,r){s(this,"viemChain");this.chain=t,this.walletClient=e,this.publicClient=r,this.viemChain=h.VIEM_CHAINS[t]}getContract(){const t=u.CONTRACT_ADDRESSES[this.chain].Distributor,e=C.Distributor,r={public:this.publicClient,wallet:this.walletClient};return l.getContract({address:t,abi:e,client:r})}canUpdateMerkleRoot(t){return this.getContract().read.canUpdateMerkleRoot([t])}claim(t,{users:e,tokens:r,amounts:n,proofs:a}){return this.getContract().write.claim([e,r,n,a],{account:t,chain:this.viemChain})}async claimed(t,e){const[r,n,a]=await this.getContract().read.claimed([t,e]);return{amount:r,timestamp:BigInt(n),merkleRoot:a}}core(){return this.getContract().read.core()}disputeAmount(){return this.getContract().read.disputeAmount()}disputePeriod(){return this.getContract().read.disputePeriod()}disputeToken(){return this.getContract().read.disputeToken()}disputeTree(t,e){return this.getContract().write.disputeTree([e],{account:t,chain:this.viemChain})}disputer(){return this.getContract().read.disputer()}endOfDisputePeriod(){return this.getContract().read.endOfDisputePeriod()}getMerkleRoot(){return this.getContract().read.getMerkleRoot()}async lastTree(){const[t,e]=await this.getContract().read.lastTree();return{merkleRoot:t,ipfsHash:e}}onlyOperatorCanClaim(t){return this.getContract().read.onlyOperatorCanClaim([t])}operators(t,e){return this.getContract().read.operators([t,e])}recoverERC20(t,e,r,n){return this.getContract().write.recoverERC20([e,r,n],{account:t,chain:this.viemChain})}resolveDispute(t,e){return this.getContract().write.resolveDispute([e],{account:t,chain:this.viemChain})}revokeTree(t){return this.getContract().write.revokeTree({account:t,chain:this.viemChain})}setDisputeAmount(t,e){return this.getContract().write.setDisputeAmount([e],{account:t,chain:this.viemChain})}setDisputePeriod(t,e){return this.getContract().write.setDisputePeriod([e],{account:t,chain:this.viemChain})}setDisputeToken(t,e){return this.getContract().write.setDisputeToken([e],{account:t,chain:this.viemChain})}toggleOnlyOperatorCanClaim(t,e){return this.getContract().write.toggleOnlyOperatorCanClaim([e],{account:t,chain:this.viemChain})}toggleOperator(t,e,r){return this.getContract().write.toggleOperator([e,r],{account:t,chain:this.viemChain})}toggleTrusted(t,e){return this.getContract().write.toggleTrusted([e],{account:t,chain:this.viemChain})}async tree(){const[t,e]=await this.getContract().read.tree();return{merkleRoot:t,ipfsHash:e}}updateTree(t,e){return this.getContract().write.updateTree([e],{account:t,chain:this.viemChain})}}exports.DistributorHandler=d;
|
|
2
|
+
//# sourceMappingURL=distributor-handler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributor-handler.cjs","sources":["../../../lib/contracts/handlers/distributor-handler.ts"],"sourcesContent":["import {\n WalletClient,\n PublicClient,\n getContract,\n Address,\n GetContractReturnType,\n} from 'viem';\nimport { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';\nimport { CONTRACT_ADDRESSES } from '../addresses';\nimport { Distributor } from '../abis/mainnet/Distributor';\n\ninterface ContractAddressesWithDistributor {\n Distributor: Address;\n}\n\nexport interface MerkleTree {\n merkleRoot: `0x${string}`;\n ipfsHash: `0x${string}`;\n}\n\nexport interface ClaimInfo {\n amount: bigint;\n timestamp: bigint;\n merkleRoot: `0x${string}`;\n}\n\nexport interface ClaimParams {\n users: Address[];\n tokens: Address[];\n amounts: bigint[];\n proofs: `0x${string}`[][];\n}\n\n/**\n * Handler for the Merkle Distributor contract, for claiming rewards, e.g. mtwCARROT.\n */\nexport class DistributorHandler {\n private viemChain: ViemChain;\n\n /**\n * Create the handler for the Distributor contract exposing\n * methods to interact with the contract.\n *\n * @param chain Chain to use for the client.\n * @param walletClient The wallet client to use for wallet interactions.\n * @param publicClient The public client to use for public interactions.\n */\n constructor(\n private chain: Chain,\n private walletClient: WalletClient,\n private publicClient: PublicClient,\n ) {\n this.viemChain = VIEM_CHAINS[chain];\n }\n\n /**\n * Get the contract.\n *\n * @returns The viem contract.\n */\n public getContract() {\n const address = (\n CONTRACT_ADDRESSES[\n this.chain\n ] as unknown as ContractAddressesWithDistributor\n ).Distributor;\n const abi = Distributor;\n const client = { public: this.publicClient, wallet: this.walletClient };\n\n return getContract({ address, abi, client }) as GetContractReturnType<\n typeof abi,\n typeof client,\n Address\n >;\n }\n\n /**\n * Check if an address can update the merkle root.\n *\n * @param address The address to check.\n * @returns Whether the address can update the merkle root.\n */\n public canUpdateMerkleRoot(address: Address) {\n return this.getContract().read.canUpdateMerkleRoot([address]);\n }\n\n /**\n * Claim tokens for multiple users.\n *\n * @param account The account making the claim.\n * @param params The claim parameters.\n * @returns A promise that resolves to the transaction hash.\n */\n public claim(\n account: Address,\n { users, tokens, amounts, proofs }: ClaimParams,\n ) {\n return this.getContract().write.claim([users, tokens, amounts, proofs], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get claim information for a user and token.\n *\n * @param user The user address.\n * @param token The token address.\n * @returns The claim information.\n */\n public async claimed(user: Address, token: Address): Promise<ClaimInfo> {\n const [amount, timestamp, merkleRoot] =\n await this.getContract().read.claimed([user, token]);\n return {\n amount,\n timestamp: BigInt(timestamp),\n merkleRoot,\n };\n }\n\n /**\n * Get the core contract address.\n *\n * @returns The core contract address.\n */\n public core() {\n return this.getContract().read.core();\n }\n\n /**\n * Get the dispute amount.\n *\n * @returns The dispute amount.\n */\n public disputeAmount() {\n return this.getContract().read.disputeAmount();\n }\n\n /**\n * Get the dispute period.\n *\n * @returns The dispute period in seconds.\n */\n public disputePeriod() {\n return this.getContract().read.disputePeriod();\n }\n\n /**\n * Get the dispute token address.\n *\n * @returns The dispute token address.\n */\n public disputeToken() {\n return this.getContract().read.disputeToken();\n }\n\n /**\n * Dispute the current tree.\n *\n * @param account The account disputing the tree.\n * @param reason The reason for the dispute.\n * @returns A promise that resolves to the transaction hash.\n */\n public disputeTree(account: Address, reason: string) {\n return this.getContract().write.disputeTree([reason], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get the current disputer address.\n *\n * @returns The disputer address.\n */\n public disputer() {\n return this.getContract().read.disputer();\n }\n\n /**\n * Get the end of the dispute period.\n *\n * @returns The timestamp when the dispute period ends.\n */\n public endOfDisputePeriod() {\n return this.getContract().read.endOfDisputePeriod();\n }\n\n /**\n * Get the current merkle root.\n *\n * @returns The current merkle root.\n */\n public getMerkleRoot() {\n return this.getContract().read.getMerkleRoot();\n }\n\n /**\n * Get the last tree information.\n *\n * @returns The last tree information.\n */\n public async lastTree(): Promise<MerkleTree> {\n const [merkleRoot, ipfsHash] = await this.getContract().read.lastTree();\n return {\n merkleRoot,\n ipfsHash,\n };\n }\n\n /**\n * Check if only operators can claim for a user.\n *\n * @param user The user address to check.\n * @returns Whether only operators can claim for the user.\n */\n public onlyOperatorCanClaim(user: Address) {\n return this.getContract().read.onlyOperatorCanClaim([user]);\n }\n\n /**\n * Check if an address is an operator for a user.\n *\n * @param user The user address.\n * @param operator The operator address.\n * @returns Whether the address is an operator.\n */\n public operators(user: Address, operator: Address) {\n return this.getContract().read.operators([user, operator]);\n }\n\n /**\n * Recover ERC20 tokens sent to the contract.\n *\n * @param account The account recovering the tokens.\n * @param tokenAddress The token address to recover.\n * @param to The address to send recovered tokens to.\n * @param amountToRecover The amount to recover.\n * @returns A promise that resolves to the transaction hash.\n */\n public recoverERC20(\n account: Address,\n tokenAddress: Address,\n to: Address,\n amountToRecover: bigint,\n ) {\n return this.getContract().write.recoverERC20(\n [tokenAddress, to, amountToRecover],\n {\n account,\n chain: this.viemChain,\n },\n );\n }\n\n /**\n * Resolve a dispute.\n *\n * @param account The account resolving the dispute.\n * @param valid Whether the disputed tree is valid.\n * @returns A promise that resolves to the transaction hash.\n */\n public resolveDispute(account: Address, valid: boolean) {\n return this.getContract().write.resolveDispute([valid], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Revoke the current tree.\n *\n * @param account The account revoking the tree.\n * @returns A promise that resolves to the transaction hash.\n */\n public revokeTree(account: Address) {\n return this.getContract().write.revokeTree({\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute amount.\n *\n * @param account The account setting the dispute amount.\n * @param disputeAmount The new dispute amount.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputeAmount(account: Address, disputeAmount: bigint) {\n return this.getContract().write.setDisputeAmount([disputeAmount], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute period.\n *\n * @param account The account setting the dispute period.\n * @param disputePeriod The new dispute period in seconds.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputePeriod(account: Address, disputePeriod: number) {\n return this.getContract().write.setDisputePeriod([disputePeriod], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute token.\n *\n * @param account The account setting the dispute token.\n * @param disputeToken The new dispute token address.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputeToken(account: Address, disputeToken: Address) {\n return this.getContract().write.setDisputeToken([disputeToken], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle whether only operators can claim for a user.\n *\n * @param account The account toggling the setting.\n * @param user The user address to toggle for.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleOnlyOperatorCanClaim(account: Address, user: Address) {\n return this.getContract().write.toggleOnlyOperatorCanClaim([user], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle an operator for a user.\n *\n * @param account The account toggling the operator.\n * @param user The user address.\n * @param operator The operator address to toggle.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleOperator(account: Address, user: Address, operator: Address) {\n return this.getContract().write.toggleOperator([user, operator], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle whether an address is trusted.\n *\n * @param account The account toggling the trusted status.\n * @param eoa The address to toggle trust for.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleTrusted(account: Address, eoa: Address) {\n return this.getContract().write.toggleTrusted([eoa], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get the current tree information.\n *\n * @returns The current tree information.\n */\n public async tree(): Promise<MerkleTree> {\n const [merkleRoot, ipfsHash] = await this.getContract().read.tree();\n return {\n merkleRoot,\n ipfsHash,\n };\n }\n\n /**\n * Update the merkle tree.\n *\n * @param account The account updating the tree.\n * @param tree The new tree information.\n * @returns A promise that resolves to the transaction hash.\n */\n public updateTree(account: Address, tree: MerkleTree) {\n return this.getContract().write.updateTree([tree], {\n account,\n chain: this.viemChain,\n });\n }\n}\n"],"names":["DistributorHandler","chain","walletClient","publicClient","__publicField","VIEM_CHAINS","address","CONTRACT_ADDRESSES","abi","Distributor","client","getContract","account","users","tokens","amounts","proofs","user","token","amount","timestamp","merkleRoot","reason","ipfsHash","operator","tokenAddress","to","amountToRecover","valid","disputeAmount","disputePeriod","disputeToken","eoa","tree"],"mappings":"2ZAoCO,MAAMA,CAAmB,CAW9B,YACUC,EACAC,EACAC,EACR,CAdMC,EAAA,kBAWE,KAAA,MAAAH,EACA,KAAA,aAAAC,EACA,KAAA,aAAAC,EAEH,KAAA,UAAYE,cAAYJ,CAAK,CAAA,CAQ7B,aAAc,CACnB,MAAMK,EACJC,EAAA,mBACE,KAAK,KACP,EACA,YACIC,EAAMC,EAAA,YACNC,EAAS,CAAE,OAAQ,KAAK,aAAc,OAAQ,KAAK,YAAa,EAEtE,OAAOC,EAAY,YAAA,CAAE,QAAAL,EAAS,IAAAE,EAAK,OAAAE,EAAQ,CAAA,CAatC,oBAAoBJ,EAAkB,CAC3C,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AAA,CAUI,cAAcA,EAAkBoB,EAAc,CACnD,OAAO,KAAK,YAAY,EAAE,MAAM,cAAc,CAACA,CAAG,EAAG,CACnD,QAAApB,EACA,MAAO,KAAK,SAAA,CACb,CAAA,CAQH,MAAa,MAA4B,CACjC,KAAA,CAACS,EAAYE,CAAQ,EAAI,MAAM,KAAK,YAAc,EAAA,KAAK,KAAK,EAC3D,MAAA,CACL,WAAAF,EACA,SAAAE,CACF,CAAA,CAUK,WAAWX,EAAkBqB,EAAkB,CACpD,OAAO,KAAK,YAAY,EAAE,MAAM,WAAW,CAACA,CAAI,EAAG,CACjD,QAAArB,EACA,MAAO,KAAK,SAAA,CACb,CAAA,CAEL"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
var o = Object.defineProperty;
|
|
2
|
+
var h = (i, t, e) => t in i ? o(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var s = (i, t, e) => h(i, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { V as c } from "../../constants-CH7Tz5jz.js";
|
|
5
|
+
import { CONTRACT_ADDRESSES as u } from "../addresses.js";
|
|
6
|
+
import { Distributor as C } from "../abis/mainnet/Distributor.js";
|
|
7
|
+
import { g as l } from "../../getContract-6ajhFbP2.js";
|
|
8
|
+
class w {
|
|
9
|
+
/**
|
|
10
|
+
* Create the handler for the Distributor contract exposing
|
|
11
|
+
* methods to interact with the contract.
|
|
12
|
+
*
|
|
13
|
+
* @param chain Chain to use for the client.
|
|
14
|
+
* @param walletClient The wallet client to use for wallet interactions.
|
|
15
|
+
* @param publicClient The public client to use for public interactions.
|
|
16
|
+
*/
|
|
17
|
+
constructor(t, e, r) {
|
|
18
|
+
s(this, "viemChain");
|
|
19
|
+
this.chain = t, this.walletClient = e, this.publicClient = r, this.viemChain = c[t];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the contract.
|
|
23
|
+
*
|
|
24
|
+
* @returns The viem contract.
|
|
25
|
+
*/
|
|
26
|
+
getContract() {
|
|
27
|
+
const t = u[this.chain].Distributor, e = C, r = { public: this.publicClient, wallet: this.walletClient };
|
|
28
|
+
return l({ address: t, abi: e, client: r });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if an address can update the merkle root.
|
|
32
|
+
*
|
|
33
|
+
* @param address The address to check.
|
|
34
|
+
* @returns Whether the address can update the merkle root.
|
|
35
|
+
*/
|
|
36
|
+
canUpdateMerkleRoot(t) {
|
|
37
|
+
return this.getContract().read.canUpdateMerkleRoot([t]);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Claim tokens for multiple users.
|
|
41
|
+
*
|
|
42
|
+
* @param account The account making the claim.
|
|
43
|
+
* @param params The claim parameters.
|
|
44
|
+
* @returns A promise that resolves to the transaction hash.
|
|
45
|
+
*/
|
|
46
|
+
claim(t, { users: e, tokens: r, amounts: a, proofs: n }) {
|
|
47
|
+
return this.getContract().write.claim([e, r, a, n], {
|
|
48
|
+
account: t,
|
|
49
|
+
chain: this.viemChain
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get claim information for a user and token.
|
|
54
|
+
*
|
|
55
|
+
* @param user The user address.
|
|
56
|
+
* @param token The token address.
|
|
57
|
+
* @returns The claim information.
|
|
58
|
+
*/
|
|
59
|
+
async claimed(t, e) {
|
|
60
|
+
const [r, a, n] = await this.getContract().read.claimed([t, e]);
|
|
61
|
+
return {
|
|
62
|
+
amount: r,
|
|
63
|
+
timestamp: BigInt(a),
|
|
64
|
+
merkleRoot: n
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the core contract address.
|
|
69
|
+
*
|
|
70
|
+
* @returns The core contract address.
|
|
71
|
+
*/
|
|
72
|
+
core() {
|
|
73
|
+
return this.getContract().read.core();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the dispute amount.
|
|
77
|
+
*
|
|
78
|
+
* @returns The dispute amount.
|
|
79
|
+
*/
|
|
80
|
+
disputeAmount() {
|
|
81
|
+
return this.getContract().read.disputeAmount();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the dispute period.
|
|
85
|
+
*
|
|
86
|
+
* @returns The dispute period in seconds.
|
|
87
|
+
*/
|
|
88
|
+
disputePeriod() {
|
|
89
|
+
return this.getContract().read.disputePeriod();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the dispute token address.
|
|
93
|
+
*
|
|
94
|
+
* @returns The dispute token address.
|
|
95
|
+
*/
|
|
96
|
+
disputeToken() {
|
|
97
|
+
return this.getContract().read.disputeToken();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Dispute the current tree.
|
|
101
|
+
*
|
|
102
|
+
* @param account The account disputing the tree.
|
|
103
|
+
* @param reason The reason for the dispute.
|
|
104
|
+
* @returns A promise that resolves to the transaction hash.
|
|
105
|
+
*/
|
|
106
|
+
disputeTree(t, e) {
|
|
107
|
+
return this.getContract().write.disputeTree([e], {
|
|
108
|
+
account: t,
|
|
109
|
+
chain: this.viemChain
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the current disputer address.
|
|
114
|
+
*
|
|
115
|
+
* @returns The disputer address.
|
|
116
|
+
*/
|
|
117
|
+
disputer() {
|
|
118
|
+
return this.getContract().read.disputer();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the end of the dispute period.
|
|
122
|
+
*
|
|
123
|
+
* @returns The timestamp when the dispute period ends.
|
|
124
|
+
*/
|
|
125
|
+
endOfDisputePeriod() {
|
|
126
|
+
return this.getContract().read.endOfDisputePeriod();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the current merkle root.
|
|
130
|
+
*
|
|
131
|
+
* @returns The current merkle root.
|
|
132
|
+
*/
|
|
133
|
+
getMerkleRoot() {
|
|
134
|
+
return this.getContract().read.getMerkleRoot();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the last tree information.
|
|
138
|
+
*
|
|
139
|
+
* @returns The last tree information.
|
|
140
|
+
*/
|
|
141
|
+
async lastTree() {
|
|
142
|
+
const [t, e] = await this.getContract().read.lastTree();
|
|
143
|
+
return {
|
|
144
|
+
merkleRoot: t,
|
|
145
|
+
ipfsHash: e
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if only operators can claim for a user.
|
|
150
|
+
*
|
|
151
|
+
* @param user The user address to check.
|
|
152
|
+
* @returns Whether only operators can claim for the user.
|
|
153
|
+
*/
|
|
154
|
+
onlyOperatorCanClaim(t) {
|
|
155
|
+
return this.getContract().read.onlyOperatorCanClaim([t]);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if an address is an operator for a user.
|
|
159
|
+
*
|
|
160
|
+
* @param user The user address.
|
|
161
|
+
* @param operator The operator address.
|
|
162
|
+
* @returns Whether the address is an operator.
|
|
163
|
+
*/
|
|
164
|
+
operators(t, e) {
|
|
165
|
+
return this.getContract().read.operators([t, e]);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Recover ERC20 tokens sent to the contract.
|
|
169
|
+
*
|
|
170
|
+
* @param account The account recovering the tokens.
|
|
171
|
+
* @param tokenAddress The token address to recover.
|
|
172
|
+
* @param to The address to send recovered tokens to.
|
|
173
|
+
* @param amountToRecover The amount to recover.
|
|
174
|
+
* @returns A promise that resolves to the transaction hash.
|
|
175
|
+
*/
|
|
176
|
+
recoverERC20(t, e, r, a) {
|
|
177
|
+
return this.getContract().write.recoverERC20(
|
|
178
|
+
[e, r, a],
|
|
179
|
+
{
|
|
180
|
+
account: t,
|
|
181
|
+
chain: this.viemChain
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Resolve a dispute.
|
|
187
|
+
*
|
|
188
|
+
* @param account The account resolving the dispute.
|
|
189
|
+
* @param valid Whether the disputed tree is valid.
|
|
190
|
+
* @returns A promise that resolves to the transaction hash.
|
|
191
|
+
*/
|
|
192
|
+
resolveDispute(t, e) {
|
|
193
|
+
return this.getContract().write.resolveDispute([e], {
|
|
194
|
+
account: t,
|
|
195
|
+
chain: this.viemChain
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Revoke the current tree.
|
|
200
|
+
*
|
|
201
|
+
* @param account The account revoking the tree.
|
|
202
|
+
* @returns A promise that resolves to the transaction hash.
|
|
203
|
+
*/
|
|
204
|
+
revokeTree(t) {
|
|
205
|
+
return this.getContract().write.revokeTree({
|
|
206
|
+
account: t,
|
|
207
|
+
chain: this.viemChain
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Set the dispute amount.
|
|
212
|
+
*
|
|
213
|
+
* @param account The account setting the dispute amount.
|
|
214
|
+
* @param disputeAmount The new dispute amount.
|
|
215
|
+
* @returns A promise that resolves to the transaction hash.
|
|
216
|
+
*/
|
|
217
|
+
setDisputeAmount(t, e) {
|
|
218
|
+
return this.getContract().write.setDisputeAmount([e], {
|
|
219
|
+
account: t,
|
|
220
|
+
chain: this.viemChain
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Set the dispute period.
|
|
225
|
+
*
|
|
226
|
+
* @param account The account setting the dispute period.
|
|
227
|
+
* @param disputePeriod The new dispute period in seconds.
|
|
228
|
+
* @returns A promise that resolves to the transaction hash.
|
|
229
|
+
*/
|
|
230
|
+
setDisputePeriod(t, e) {
|
|
231
|
+
return this.getContract().write.setDisputePeriod([e], {
|
|
232
|
+
account: t,
|
|
233
|
+
chain: this.viemChain
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set the dispute token.
|
|
238
|
+
*
|
|
239
|
+
* @param account The account setting the dispute token.
|
|
240
|
+
* @param disputeToken The new dispute token address.
|
|
241
|
+
* @returns A promise that resolves to the transaction hash.
|
|
242
|
+
*/
|
|
243
|
+
setDisputeToken(t, e) {
|
|
244
|
+
return this.getContract().write.setDisputeToken([e], {
|
|
245
|
+
account: t,
|
|
246
|
+
chain: this.viemChain
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Toggle whether only operators can claim for a user.
|
|
251
|
+
*
|
|
252
|
+
* @param account The account toggling the setting.
|
|
253
|
+
* @param user The user address to toggle for.
|
|
254
|
+
* @returns A promise that resolves to the transaction hash.
|
|
255
|
+
*/
|
|
256
|
+
toggleOnlyOperatorCanClaim(t, e) {
|
|
257
|
+
return this.getContract().write.toggleOnlyOperatorCanClaim([e], {
|
|
258
|
+
account: t,
|
|
259
|
+
chain: this.viemChain
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Toggle an operator for a user.
|
|
264
|
+
*
|
|
265
|
+
* @param account The account toggling the operator.
|
|
266
|
+
* @param user The user address.
|
|
267
|
+
* @param operator The operator address to toggle.
|
|
268
|
+
* @returns A promise that resolves to the transaction hash.
|
|
269
|
+
*/
|
|
270
|
+
toggleOperator(t, e, r) {
|
|
271
|
+
return this.getContract().write.toggleOperator([e, r], {
|
|
272
|
+
account: t,
|
|
273
|
+
chain: this.viemChain
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Toggle whether an address is trusted.
|
|
278
|
+
*
|
|
279
|
+
* @param account The account toggling the trusted status.
|
|
280
|
+
* @param eoa The address to toggle trust for.
|
|
281
|
+
* @returns A promise that resolves to the transaction hash.
|
|
282
|
+
*/
|
|
283
|
+
toggleTrusted(t, e) {
|
|
284
|
+
return this.getContract().write.toggleTrusted([e], {
|
|
285
|
+
account: t,
|
|
286
|
+
chain: this.viemChain
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get the current tree information.
|
|
291
|
+
*
|
|
292
|
+
* @returns The current tree information.
|
|
293
|
+
*/
|
|
294
|
+
async tree() {
|
|
295
|
+
const [t, e] = await this.getContract().read.tree();
|
|
296
|
+
return {
|
|
297
|
+
merkleRoot: t,
|
|
298
|
+
ipfsHash: e
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Update the merkle tree.
|
|
303
|
+
*
|
|
304
|
+
* @param account The account updating the tree.
|
|
305
|
+
* @param tree The new tree information.
|
|
306
|
+
* @returns A promise that resolves to the transaction hash.
|
|
307
|
+
*/
|
|
308
|
+
updateTree(t, e) {
|
|
309
|
+
return this.getContract().write.updateTree([e], {
|
|
310
|
+
account: t,
|
|
311
|
+
chain: this.viemChain
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export {
|
|
316
|
+
w as DistributorHandler
|
|
317
|
+
};
|
|
318
|
+
//# sourceMappingURL=distributor-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributor-handler.js","sources":["../../../lib/contracts/handlers/distributor-handler.ts"],"sourcesContent":["import {\n WalletClient,\n PublicClient,\n getContract,\n Address,\n GetContractReturnType,\n} from 'viem';\nimport { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';\nimport { CONTRACT_ADDRESSES } from '../addresses';\nimport { Distributor } from '../abis/mainnet/Distributor';\n\ninterface ContractAddressesWithDistributor {\n Distributor: Address;\n}\n\nexport interface MerkleTree {\n merkleRoot: `0x${string}`;\n ipfsHash: `0x${string}`;\n}\n\nexport interface ClaimInfo {\n amount: bigint;\n timestamp: bigint;\n merkleRoot: `0x${string}`;\n}\n\nexport interface ClaimParams {\n users: Address[];\n tokens: Address[];\n amounts: bigint[];\n proofs: `0x${string}`[][];\n}\n\n/**\n * Handler for the Merkle Distributor contract, for claiming rewards, e.g. mtwCARROT.\n */\nexport class DistributorHandler {\n private viemChain: ViemChain;\n\n /**\n * Create the handler for the Distributor contract exposing\n * methods to interact with the contract.\n *\n * @param chain Chain to use for the client.\n * @param walletClient The wallet client to use for wallet interactions.\n * @param publicClient The public client to use for public interactions.\n */\n constructor(\n private chain: Chain,\n private walletClient: WalletClient,\n private publicClient: PublicClient,\n ) {\n this.viemChain = VIEM_CHAINS[chain];\n }\n\n /**\n * Get the contract.\n *\n * @returns The viem contract.\n */\n public getContract() {\n const address = (\n CONTRACT_ADDRESSES[\n this.chain\n ] as unknown as ContractAddressesWithDistributor\n ).Distributor;\n const abi = Distributor;\n const client = { public: this.publicClient, wallet: this.walletClient };\n\n return getContract({ address, abi, client }) as GetContractReturnType<\n typeof abi,\n typeof client,\n Address\n >;\n }\n\n /**\n * Check if an address can update the merkle root.\n *\n * @param address The address to check.\n * @returns Whether the address can update the merkle root.\n */\n public canUpdateMerkleRoot(address: Address) {\n return this.getContract().read.canUpdateMerkleRoot([address]);\n }\n\n /**\n * Claim tokens for multiple users.\n *\n * @param account The account making the claim.\n * @param params The claim parameters.\n * @returns A promise that resolves to the transaction hash.\n */\n public claim(\n account: Address,\n { users, tokens, amounts, proofs }: ClaimParams,\n ) {\n return this.getContract().write.claim([users, tokens, amounts, proofs], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get claim information for a user and token.\n *\n * @param user The user address.\n * @param token The token address.\n * @returns The claim information.\n */\n public async claimed(user: Address, token: Address): Promise<ClaimInfo> {\n const [amount, timestamp, merkleRoot] =\n await this.getContract().read.claimed([user, token]);\n return {\n amount,\n timestamp: BigInt(timestamp),\n merkleRoot,\n };\n }\n\n /**\n * Get the core contract address.\n *\n * @returns The core contract address.\n */\n public core() {\n return this.getContract().read.core();\n }\n\n /**\n * Get the dispute amount.\n *\n * @returns The dispute amount.\n */\n public disputeAmount() {\n return this.getContract().read.disputeAmount();\n }\n\n /**\n * Get the dispute period.\n *\n * @returns The dispute period in seconds.\n */\n public disputePeriod() {\n return this.getContract().read.disputePeriod();\n }\n\n /**\n * Get the dispute token address.\n *\n * @returns The dispute token address.\n */\n public disputeToken() {\n return this.getContract().read.disputeToken();\n }\n\n /**\n * Dispute the current tree.\n *\n * @param account The account disputing the tree.\n * @param reason The reason for the dispute.\n * @returns A promise that resolves to the transaction hash.\n */\n public disputeTree(account: Address, reason: string) {\n return this.getContract().write.disputeTree([reason], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get the current disputer address.\n *\n * @returns The disputer address.\n */\n public disputer() {\n return this.getContract().read.disputer();\n }\n\n /**\n * Get the end of the dispute period.\n *\n * @returns The timestamp when the dispute period ends.\n */\n public endOfDisputePeriod() {\n return this.getContract().read.endOfDisputePeriod();\n }\n\n /**\n * Get the current merkle root.\n *\n * @returns The current merkle root.\n */\n public getMerkleRoot() {\n return this.getContract().read.getMerkleRoot();\n }\n\n /**\n * Get the last tree information.\n *\n * @returns The last tree information.\n */\n public async lastTree(): Promise<MerkleTree> {\n const [merkleRoot, ipfsHash] = await this.getContract().read.lastTree();\n return {\n merkleRoot,\n ipfsHash,\n };\n }\n\n /**\n * Check if only operators can claim for a user.\n *\n * @param user The user address to check.\n * @returns Whether only operators can claim for the user.\n */\n public onlyOperatorCanClaim(user: Address) {\n return this.getContract().read.onlyOperatorCanClaim([user]);\n }\n\n /**\n * Check if an address is an operator for a user.\n *\n * @param user The user address.\n * @param operator The operator address.\n * @returns Whether the address is an operator.\n */\n public operators(user: Address, operator: Address) {\n return this.getContract().read.operators([user, operator]);\n }\n\n /**\n * Recover ERC20 tokens sent to the contract.\n *\n * @param account The account recovering the tokens.\n * @param tokenAddress The token address to recover.\n * @param to The address to send recovered tokens to.\n * @param amountToRecover The amount to recover.\n * @returns A promise that resolves to the transaction hash.\n */\n public recoverERC20(\n account: Address,\n tokenAddress: Address,\n to: Address,\n amountToRecover: bigint,\n ) {\n return this.getContract().write.recoverERC20(\n [tokenAddress, to, amountToRecover],\n {\n account,\n chain: this.viemChain,\n },\n );\n }\n\n /**\n * Resolve a dispute.\n *\n * @param account The account resolving the dispute.\n * @param valid Whether the disputed tree is valid.\n * @returns A promise that resolves to the transaction hash.\n */\n public resolveDispute(account: Address, valid: boolean) {\n return this.getContract().write.resolveDispute([valid], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Revoke the current tree.\n *\n * @param account The account revoking the tree.\n * @returns A promise that resolves to the transaction hash.\n */\n public revokeTree(account: Address) {\n return this.getContract().write.revokeTree({\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute amount.\n *\n * @param account The account setting the dispute amount.\n * @param disputeAmount The new dispute amount.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputeAmount(account: Address, disputeAmount: bigint) {\n return this.getContract().write.setDisputeAmount([disputeAmount], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute period.\n *\n * @param account The account setting the dispute period.\n * @param disputePeriod The new dispute period in seconds.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputePeriod(account: Address, disputePeriod: number) {\n return this.getContract().write.setDisputePeriod([disputePeriod], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Set the dispute token.\n *\n * @param account The account setting the dispute token.\n * @param disputeToken The new dispute token address.\n * @returns A promise that resolves to the transaction hash.\n */\n public setDisputeToken(account: Address, disputeToken: Address) {\n return this.getContract().write.setDisputeToken([disputeToken], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle whether only operators can claim for a user.\n *\n * @param account The account toggling the setting.\n * @param user The user address to toggle for.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleOnlyOperatorCanClaim(account: Address, user: Address) {\n return this.getContract().write.toggleOnlyOperatorCanClaim([user], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle an operator for a user.\n *\n * @param account The account toggling the operator.\n * @param user The user address.\n * @param operator The operator address to toggle.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleOperator(account: Address, user: Address, operator: Address) {\n return this.getContract().write.toggleOperator([user, operator], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Toggle whether an address is trusted.\n *\n * @param account The account toggling the trusted status.\n * @param eoa The address to toggle trust for.\n * @returns A promise that resolves to the transaction hash.\n */\n public toggleTrusted(account: Address, eoa: Address) {\n return this.getContract().write.toggleTrusted([eoa], {\n account,\n chain: this.viemChain,\n });\n }\n\n /**\n * Get the current tree information.\n *\n * @returns The current tree information.\n */\n public async tree(): Promise<MerkleTree> {\n const [merkleRoot, ipfsHash] = await this.getContract().read.tree();\n return {\n merkleRoot,\n ipfsHash,\n };\n }\n\n /**\n * Update the merkle tree.\n *\n * @param account The account updating the tree.\n * @param tree The new tree information.\n * @returns A promise that resolves to the transaction hash.\n */\n public updateTree(account: Address, tree: MerkleTree) {\n return this.getContract().write.updateTree([tree], {\n account,\n chain: this.viemChain,\n });\n }\n}\n"],"names":["DistributorHandler","chain","walletClient","publicClient","__publicField","VIEM_CHAINS","address","CONTRACT_ADDRESSES","abi","Distributor","client","getContract","account","users","tokens","amounts","proofs","user","token","amount","timestamp","merkleRoot","reason","ipfsHash","operator","tokenAddress","to","amountToRecover","valid","disputeAmount","disputePeriod","disputeToken","eoa","tree"],"mappings":";;;;;;;AAoCO,MAAMA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,YACUC,GACAC,GACAC,GACR;AAdM,IAAAC,EAAA;AAWE,SAAA,QAAAH,GACA,KAAA,eAAAC,GACA,KAAA,eAAAC,GAEH,KAAA,YAAYE,EAAYJ,CAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,cAAc;AACnB,UAAMK,IACJC,EACE,KAAK,KACP,EACA,aACIC,IAAMC,GACNC,IAAS,EAAE,QAAQ,KAAK,cAAc,QAAQ,KAAK,aAAa;AAEtE,WAAOC,EAAY,EAAE,SAAAL,GAAS,KAAAE,GAAK,QAAAE,GAAQ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatC,oBAAoBJ,GAAkB;AAC3C,WAAO,KAAK,YAAY,EAAE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,MACA,OAAO,KAAK;AAAA,IAAA,CACb;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUI,cAAcA,GAAkBoB,GAAc;AACnD,WAAO,KAAK,YAAY,EAAE,MAAM,cAAc,CAACA,CAAG,GAAG;AAAA,MACnD,SAAApB;AAAA,MACA,OAAO,KAAK;AAAA,IAAA,CACb;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQH,MAAa,OAA4B;AACjC,UAAA,CAACS,GAAYE,CAAQ,IAAI,MAAM,KAAK,YAAc,EAAA,KAAK,KAAK;AAC3D,WAAA;AAAA,MACL,YAAAF;AAAA,MACA,UAAAE;AAAA,IACF;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUK,WAAWX,GAAkBqB,GAAkB;AACpD,WAAO,KAAK,YAAY,EAAE,MAAM,WAAW,CAACA,CAAI,GAAG;AAAA,MACjD,SAAArB;AAAA,MACA,OAAO,KAAK;AAAA,IAAA,CACb;AAAA,EAAA;AAEL;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var d=(i,t,e)=>t in i?p(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var c=(i,t,e)=>d(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../constants-
|
|
1
|
+
"use strict";var p=Object.defineProperty;var d=(i,t,e)=>t in i?p(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var c=(i,t,e)=>d(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../constants-BcPRVxdH.cjs"),g=require("../abis/tokens-abis.cjs"),s=require("../tokens.cjs"),S=require("../../utils/time.cjs"),y=require("../../getContract-ChPFzc5y.cjs"),C=require("../../secp256k1-B8plqpXf.cjs");function T(i){const{r:t,s:e}=C.secp256k1.Signature.fromCompact(i.slice(2,130)),n=+`0x${i.slice(130)}`,[r,o]=(()=>{if(n===0||n===1)return[void 0,n];if(n===27)return[BigInt(n),0];if(n===28)return[BigInt(n),1];throw new Error("Invalid yParityOrV value")})();return typeof r<"u"?{r:a.numberToHex(t,{size:32}),s:a.numberToHex(e,{size:32}),v:r,yParity:o}:{r:a.numberToHex(t,{size:32}),s:a.numberToHex(e,{size:32}),yParity:o}}class E{constructor(t,e,n){c(this,"viemChain");c(this,"token");this.chain=t,this.walletClient=e,this.publicClient=n,this.viemChain=a.VIEM_CHAINS[t],this.token=s.Token.WETH}withToken(t){return this.token=t,this}getContract(){const t=s.TOKENS_ADDRESSES[this.token][this.chain],e=g.ERC20PERMIT_ABI,n={public:this.publicClient,wallet:this.walletClient};return y.getContract({address:t,abi:e,client:n})}async getPermitSignature(t,e,n){const r=this.getContract(),o=await r.read.nonces([t]),h={name:await r.read.name(),version:this.getPermitVersion(this.token),chainId:this.chain,verifyingContract:s.TOKENS_ADDRESSES[this.token][this.chain],salt:this.getPermitSalt(this.token)},m={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},u=BigInt(S.getTimestampInSeconds()+60*60*2),l=await this.walletClient.signTypedData({account:t,domain:h,types:m,primaryType:"Permit",message:{owner:t,spender:e,value:n,nonce:o,deadline:u}});return{...T(l),deadline:u}}approve(t,e,n){return this.getContract().write.approve([e,n],{account:t,chain:this.viemChain})}getPermitVersion(t){return s.TOKENS_PERMIT_VERSION[t]}getPermitSalt(t){var e,n;return(n=(e=s.TOKENS_SALT)==null?void 0:e[t])==null?void 0:n[this.chain]}}exports.ERC20PermitHandler=E;
|
|
2
2
|
//# sourceMappingURL=erc20-permit-handler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc20-permit-handler.cjs","sources":["../../../node_modules/.pnpm/viem@2.
|
|
1
|
+
{"version":3,"file":"erc20-permit-handler.cjs","sources":["../../../node_modules/.pnpm/viem@2.23.6_typescript@5.8.2_zod@3.24.2/node_modules/viem/_esm/utils/signature/parseSignature.js","../../../lib/contracts/handlers/erc20-permit-handler.ts"],"sourcesContent":["import { secp256k1 } from '@noble/curves/secp256k1';\nimport { numberToHex, } from '../../utils/encoding/toHex.js';\n/**\n * @description Parses a hex formatted signature into a structured signature.\n *\n * @param signatureHex Signature in hex format.\n * @returns The structured signature.\n *\n * @example\n * parseSignature('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')\n * // { r: '0x...', s: '0x...', v: 28n }\n */\nexport function parseSignature(signatureHex) {\n const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130));\n const yParityOrV = Number(`0x${signatureHex.slice(130)}`);\n const [v, yParity] = (() => {\n if (yParityOrV === 0 || yParityOrV === 1)\n return [undefined, yParityOrV];\n if (yParityOrV === 27)\n return [BigInt(yParityOrV), 0];\n if (yParityOrV === 28)\n return [BigInt(yParityOrV), 1];\n throw new Error('Invalid yParityOrV value');\n })();\n if (typeof v !== 'undefined')\n return {\n r: numberToHex(r, { size: 32 }),\n s: numberToHex(s, { size: 32 }),\n v,\n yParity,\n };\n return {\n r: numberToHex(r, { size: 32 }),\n s: numberToHex(s, { size: 32 }),\n yParity,\n };\n}\n//# sourceMappingURL=parseSignature.js.map","import {\n WalletClient,\n PublicClient,\n getContract,\n Address,\n parseSignature,\n GetContractReturnType,\n} from 'viem';\nimport { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';\nimport { ERC20PERMIT_ABI } from '../abis/tokens-abis';\nimport {\n AnyToken,\n TOKENS_ADDRESSES,\n TOKENS_SALT,\n TOKENS_PERMIT_VERSION,\n Token,\n} from '../tokens';\nimport { getTimestampInSeconds } from '../../utils/time';\n\n/**\n * Handler for performing operations for and with ERC20Permit tokens.\n */\nexport class ERC20PermitHandler {\n private viemChain: ViemChain;\n private token: AnyToken;\n\n /**\n * Create the handler for processing tokens.\n *\n * @param chain Chain to use for the client.\n * @param walletClient The wallet client to use for wallet\n * interactions.\n * @param publicClient The public client to use for public\n * interactions.\n */\n constructor(\n private chain: Chain,\n private walletClient: WalletClient,\n private publicClient: PublicClient,\n ) {\n this.viemChain = VIEM_CHAINS[chain];\n this.token = Token.WETH;\n }\n\n /**\n * Set the token to use for executing transactions on the contract.\n *\n * @param token Token to use for the handler.\n * @returns The handler.\n */\n public withToken(token: AnyToken) {\n this.token = token;\n return this;\n }\n\n /**\n * Get the contract. This is a method because the typings are complex\n * and lost when trying to make it a member.\n *\n * @returns The viem contract.\n */\n public getContract() {\n const address = TOKENS_ADDRESSES[this.token][this.chain];\n const abi = ERC20PERMIT_ABI;\n const client = { public: this.publicClient, wallet: this.walletClient };\n\n return getContract({ address, abi, client }) as GetContractReturnType<\n typeof abi,\n typeof client,\n Address\n >;\n }\n\n /**\n * Process and get permit signature for the given token to perform\n * transactions without calling `approve()`.\n *\n * @param ownerAddress Address of the token owner.\n * @param spenderAddress Address of the spender who needs the permit.\n * @param value Value of the transaction.\n * @returns Permit signature in the form `{ r, s, v?, yParity }`.\n */\n public async getPermitSignature(\n ownerAddress: Address,\n spenderAddress: Address,\n value: bigint,\n ) {\n const contract = this.getContract();\n\n const permitNonces = await contract.read.nonces([ownerAddress]);\n const name = await contract.read.name();\n const domain = <const>{\n name,\n version: this.getPermitVersion(this.token),\n chainId: this.chain,\n verifyingContract: TOKENS_ADDRESSES[this.token][this.chain],\n salt: this.getPermitSalt(this.token),\n };\n const types = <const>{\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n };\n // Valid for 2 hours.\n const deadline = BigInt(getTimestampInSeconds() + 60 * 60 * 2);\n\n const signature = await this.walletClient.signTypedData({\n account: ownerAddress,\n domain,\n types,\n primaryType: 'Permit',\n message: {\n owner: ownerAddress,\n spender: spenderAddress,\n value,\n nonce: permitNonces,\n deadline,\n },\n });\n\n return { ...parseSignature(signature), deadline };\n }\n\n /**\n * Approve transaction for the spender to spend the owner's tokens.\n *\n * @param ownerAddress Address of the caller of the transaction.\n * @param spenderAddress Address of the spender.\n * @param value Value to approve for the spender.\n * @returns Hash of the transaction.\n */\n public approve(\n ownerAddress: Address,\n spenderAddress: Address,\n value: bigint,\n ) {\n return this.getContract().write.approve([spenderAddress, value], {\n account: ownerAddress,\n chain: this.viemChain,\n });\n }\n\n private getPermitVersion(token: AnyToken): string {\n return TOKENS_PERMIT_VERSION[token];\n }\n\n private getPermitSalt(token: AnyToken) {\n return TOKENS_SALT?.[token]?.[this.chain];\n }\n}\n"],"names":["parseSignature","signatureHex","r","s","secp256k1","yParityOrV","v","yParity","numberToHex","ERC20PermitHandler","chain","walletClient","publicClient","__publicField","VIEM_CHAINS","Token","token","address","TOKENS_ADDRESSES","abi","ERC20PERMIT_ABI","client","getContract","ownerAddress","spenderAddress","value","contract","permitNonces","domain","types","deadline","getTimestampInSeconds","signature","TOKENS_PERMIT_VERSION","TOKENS_SALT"],"mappings":"4dAYO,SAASA,EAAeC,EAAc,CACzC,KAAM,CAAE,EAAAC,EAAG,EAAAC,CAAG,EAAGC,YAAU,UAAU,YAAYH,EAAa,MAAM,EAAG,GAAG,CAAC,EACrEI,EAAa,CAAO,KAAKJ,EAAa,MAAM,GAAG,CAAC,GAChD,CAACK,EAAGC,CAAO,GAAK,IAAM,CACxB,GAAIF,IAAe,GAAKA,IAAe,EACnC,MAAO,CAAC,OAAWA,CAAU,EACjC,GAAIA,IAAe,GACf,MAAO,CAAC,OAAOA,CAAU,EAAG,CAAC,EACjC,GAAIA,IAAe,GACf,MAAO,CAAC,OAAOA,CAAU,EAAG,CAAC,EACjC,MAAM,IAAI,MAAM,0BAA0B,CAClD,GAAQ,EACJ,OAAI,OAAOC,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