diff --git a/packages/contracts-sdk/src/lib/contracts-sdk.ts b/packages/contracts-sdk/src/lib/contracts-sdk.ts index 5210d80502..b064df523f 100644 --- a/packages/contracts-sdk/src/lib/contracts-sdk.ts +++ b/packages/contracts-sdk/src/lib/contracts-sdk.ts @@ -98,61 +98,61 @@ export class LitContracts { // ----- autogen:declares:start ----- allowlistContract: { - read: allowlistContract.ContractContext, - write: allowlistContract.ContractContext, - } - + read: allowlistContract.ContractContext; + write: allowlistContract.ContractContext; + }; + contractResolverContract: { - read: contractResolverContract.ContractContext, - write: contractResolverContract.ContractContext, - } - + read: contractResolverContract.ContractContext; + write: contractResolverContract.ContractContext; + }; + litTokenContract: { - read: litTokenContract.ContractContext, - write: litTokenContract.ContractContext, - } - + read: litTokenContract.ContractContext; + write: litTokenContract.ContractContext; + }; + multisenderContract: { - read: multisenderContract.ContractContext, - write: multisenderContract.ContractContext, - } - + read: multisenderContract.ContractContext; + write: multisenderContract.ContractContext; + }; + pkpHelperContract: { - read: pkpHelperContract.ContractContext, - write: pkpHelperContract.ContractContext, - } - + read: pkpHelperContract.ContractContext; + write: pkpHelperContract.ContractContext; + }; + pkpNftContract: { - read: pkpNftContract.ContractContext, - write: pkpNftContract.ContractContext, - } - + read: pkpNftContract.ContractContext; + write: pkpNftContract.ContractContext; + }; + pkpPermissionsContract: { - read: pkpPermissionsContract.ContractContext, - write: pkpPermissionsContract.ContractContext, - } - + read: pkpPermissionsContract.ContractContext; + write: pkpPermissionsContract.ContractContext; + }; + pubkeyRouterContract: { - read: pubkeyRouterContract.ContractContext, - write: pubkeyRouterContract.ContractContext, - } - + read: pubkeyRouterContract.ContractContext; + write: pubkeyRouterContract.ContractContext; + }; + rateLimitNftContract: { - read: rateLimitNftContract.ContractContext, - write: rateLimitNftContract.ContractContext, - } - + read: rateLimitNftContract.ContractContext; + write: rateLimitNftContract.ContractContext; + }; + stakingContract: { - read: stakingContract.ContractContext, - write: stakingContract.ContractContext, - } - + read: stakingContract.ContractContext; + write: stakingContract.ContractContext; + }; + stakingBalancesContract: { - read: stakingBalancesContract.ContractContext, - write: stakingBalancesContract.ContractContext, - } - -// ----- autogen:declares:end ----- + read: stakingBalancesContract.ContractContext; + write: stakingBalancesContract.ContractContext; + }; + + // ----- autogen:declares:end ----- // make the constructor args optional constructor(args?: { @@ -187,18 +187,18 @@ export class LitContracts { } // ----- autogen:blank-init:start ----- - this.allowlistContract = {} as any - this.contractResolverContract = {} as any - this.litTokenContract = {} as any - this.multisenderContract = {} as any - this.pkpHelperContract = {} as any - this.pkpNftContract = {} as any - this.pkpPermissionsContract = {} as any - this.pubkeyRouterContract = {} as any - this.rateLimitNftContract = {} as any - this.stakingContract = {} as any - this.stakingBalancesContract = {} as any -// ----- autogen:blank-init:end ----- + this.allowlistContract = {} as any; + this.contractResolverContract = {} as any; + this.litTokenContract = {} as any; + this.multisenderContract = {} as any; + this.pkpHelperContract = {} as any; + this.pkpNftContract = {} as any; + this.pkpPermissionsContract = {} as any; + this.pubkeyRouterContract = {} as any; + this.rateLimitNftContract = {} as any; + this.stakingContract = {} as any; + this.stakingBalancesContract = {} as any; + // ----- autogen:blank-init:end ----- } /** @@ -369,158 +369,166 @@ export class LitContracts { // ----- autogen:init:start ----- this.allowlistContract = { - read: (new ethers.Contract( - allowlist.address, - allowlist.abi as any, - this.provider - ) as unknown as allowlistContract.ContractContext & allowlistContract.Allowlist), - write: (new ethers.Contract( - allowlist.address, - allowlist.abi as any, - this.signer - ) as unknown as allowlistContract.ContractContext & allowlistContract.Allowlist) + read: new ethers.Contract( + allowlist.address, + allowlist.abi as any, + this.provider + ) as unknown as allowlistContract.ContractContext & + allowlistContract.Allowlist, + write: new ethers.Contract( + allowlist.address, + allowlist.abi as any, + this.signer + ) as unknown as allowlistContract.ContractContext & + allowlistContract.Allowlist, }; - this.contractResolverContract = { - read: (new ethers.Contract( - contractResolver.address, - contractResolver.abi as any, - this.provider - ) as unknown as contractResolverContract.ContractContext & contractResolverContract.ContractResolver), - write: (new ethers.Contract( - contractResolver.address, - contractResolver.abi as any, - this.signer - ) as unknown as contractResolverContract.ContractContext & contractResolverContract.ContractResolver) + read: new ethers.Contract( + contractResolver.address, + contractResolver.abi as any, + this.provider + ) as unknown as contractResolverContract.ContractContext & + contractResolverContract.ContractResolver, + write: new ethers.Contract( + contractResolver.address, + contractResolver.abi as any, + this.signer + ) as unknown as contractResolverContract.ContractContext & + contractResolverContract.ContractResolver, }; - this.litTokenContract = { - read: (new ethers.Contract( - litToken.address, - litToken.abi as any, - this.provider - ) as unknown as litTokenContract.ContractContext & litTokenContract.LITToken), - write: (new ethers.Contract( - litToken.address, - litToken.abi as any, - this.signer - ) as unknown as litTokenContract.ContractContext & litTokenContract.LITToken) + read: new ethers.Contract( + litToken.address, + litToken.abi as any, + this.provider + ) as unknown as litTokenContract.ContractContext & + litTokenContract.LITToken, + write: new ethers.Contract( + litToken.address, + litToken.abi as any, + this.signer + ) as unknown as litTokenContract.ContractContext & + litTokenContract.LITToken, }; - this.multisenderContract = { - read: (new ethers.Contract( - multisender.address, - multisender.abi as any, - this.provider - ) as unknown as multisenderContract.ContractContext & multisenderContract.Multisender), - write: (new ethers.Contract( - multisender.address, - multisender.abi as any, - this.signer - ) as unknown as multisenderContract.ContractContext & multisenderContract.Multisender) + read: new ethers.Contract( + multisender.address, + multisender.abi as any, + this.provider + ) as unknown as multisenderContract.ContractContext & + multisenderContract.Multisender, + write: new ethers.Contract( + multisender.address, + multisender.abi as any, + this.signer + ) as unknown as multisenderContract.ContractContext & + multisenderContract.Multisender, }; - this.pkpHelperContract = { - read: (new ethers.Contract( - pkpHelper.address, - pkpHelper.abi as any, - this.provider - ) as unknown as pkpHelperContract.ContractContext & pkpHelperContract.PKPHelper), - write: (new ethers.Contract( - pkpHelper.address, - pkpHelper.abi as any, - this.signer - ) as unknown as pkpHelperContract.ContractContext & pkpHelperContract.PKPHelper) + read: new ethers.Contract( + pkpHelper.address, + pkpHelper.abi as any, + this.provider + ) as unknown as pkpHelperContract.ContractContext & + pkpHelperContract.PKPHelper, + write: new ethers.Contract( + pkpHelper.address, + pkpHelper.abi as any, + this.signer + ) as unknown as pkpHelperContract.ContractContext & + pkpHelperContract.PKPHelper, }; - this.pkpNftContract = { - read: (new ethers.Contract( - pkpNft.address, - pkpNft.abi as any, - this.provider - ) as unknown as pkpNftContract.ContractContext & pkpNftContract.PKPNFT), - write: (new ethers.Contract( - pkpNft.address, - pkpNft.abi as any, - this.signer - ) as unknown as pkpNftContract.ContractContext & pkpNftContract.PKPNFT) + read: new ethers.Contract( + pkpNft.address, + pkpNft.abi as any, + this.provider + ) as unknown as pkpNftContract.ContractContext & pkpNftContract.PKPNFT, + write: new ethers.Contract( + pkpNft.address, + pkpNft.abi as any, + this.signer + ) as unknown as pkpNftContract.ContractContext & pkpNftContract.PKPNFT, }; - this.pkpPermissionsContract = { - read: (new ethers.Contract( - pkpPermissions.address, - pkpPermissions.abi as any, - this.provider - ) as unknown as pkpPermissionsContract.ContractContext & pkpPermissionsContract.PKPPermissions), - write: (new ethers.Contract( - pkpPermissions.address, - pkpPermissions.abi as any, - this.signer - ) as unknown as pkpPermissionsContract.ContractContext & pkpPermissionsContract.PKPPermissions) + read: new ethers.Contract( + pkpPermissions.address, + pkpPermissions.abi as any, + this.provider + ) as unknown as pkpPermissionsContract.ContractContext & + pkpPermissionsContract.PKPPermissions, + write: new ethers.Contract( + pkpPermissions.address, + pkpPermissions.abi as any, + this.signer + ) as unknown as pkpPermissionsContract.ContractContext & + pkpPermissionsContract.PKPPermissions, }; - this.pubkeyRouterContract = { - read: (new ethers.Contract( - pubkeyRouter.address, - pubkeyRouter.abi as any, - this.provider - ) as unknown as pubkeyRouterContract.ContractContext & pubkeyRouterContract.PubkeyRouter), - write: (new ethers.Contract( - pubkeyRouter.address, - pubkeyRouter.abi as any, - this.signer - ) as unknown as pubkeyRouterContract.ContractContext & pubkeyRouterContract.PubkeyRouter) + read: new ethers.Contract( + pubkeyRouter.address, + pubkeyRouter.abi as any, + this.provider + ) as unknown as pubkeyRouterContract.ContractContext & + pubkeyRouterContract.PubkeyRouter, + write: new ethers.Contract( + pubkeyRouter.address, + pubkeyRouter.abi as any, + this.signer + ) as unknown as pubkeyRouterContract.ContractContext & + pubkeyRouterContract.PubkeyRouter, }; - this.rateLimitNftContract = { - read: (new ethers.Contract( - rateLimitNft.address, - rateLimitNft.abi as any, - this.provider - ) as unknown as rateLimitNftContract.ContractContext & rateLimitNftContract.RateLimitNFT), - write: (new ethers.Contract( - rateLimitNft.address, - rateLimitNft.abi as any, - this.signer - ) as unknown as rateLimitNftContract.ContractContext & rateLimitNftContract.RateLimitNFT) + read: new ethers.Contract( + rateLimitNft.address, + rateLimitNft.abi as any, + this.provider + ) as unknown as rateLimitNftContract.ContractContext & + rateLimitNftContract.RateLimitNFT, + write: new ethers.Contract( + rateLimitNft.address, + rateLimitNft.abi as any, + this.signer + ) as unknown as rateLimitNftContract.ContractContext & + rateLimitNftContract.RateLimitNFT, }; - this.stakingContract = { - read: (new ethers.Contract( - staking.address, - staking.abi as any, - this.provider - ) as unknown as stakingContract.ContractContext & stakingContract.Staking), - write: (new ethers.Contract( - staking.address, - staking.abi as any, - this.signer - ) as unknown as stakingContract.ContractContext & stakingContract.Staking) + read: new ethers.Contract( + staking.address, + staking.abi as any, + this.provider + ) as unknown as stakingContract.ContractContext & stakingContract.Staking, + write: new ethers.Contract( + staking.address, + staking.abi as any, + this.signer + ) as unknown as stakingContract.ContractContext & stakingContract.Staking, }; - this.stakingBalancesContract = { - read: (new ethers.Contract( - stakingBalances.address, - stakingBalances.abi as any, - this.provider - ) as unknown as stakingBalancesContract.ContractContext & stakingBalancesContract.StakingBalances), - write: (new ethers.Contract( - stakingBalances.address, - stakingBalances.abi as any, - this.signer - ) as unknown as stakingBalancesContract.ContractContext & stakingBalancesContract.StakingBalances) + read: new ethers.Contract( + stakingBalances.address, + stakingBalances.abi as any, + this.provider + ) as unknown as stakingBalancesContract.ContractContext & + stakingBalancesContract.StakingBalances, + write: new ethers.Contract( + stakingBalances.address, + stakingBalances.abi as any, + this.signer + ) as unknown as stakingBalancesContract.ContractContext & + stakingBalancesContract.StakingBalances, }; -// ----- autogen:init:end ----- + // ----- autogen:init:end ----- this.connected = true; }; @@ -812,13 +820,12 @@ export class LitContracts { signatures: pkpNftContract.ClaimAndMintRequest[] ) => { let cost = await this.pkpNftContract.read.mintCost(); - const tx = - await this.pkpNftContract.write.claimAndMint( - 2, - keyId, - signatures, - { value: cost } - ); + const tx = await this.pkpNftContract.write.claimAndMint( + 2, + keyId, + signatures, + { value: cost } + ); let txRec = await tx.wait(); let events: any = 'events' in txRec ? txRec.events : txRec.logs; let tokenId = events[1].topics[1]; @@ -1486,7 +1493,13 @@ export class LitContracts { pkpHelperContractUtil = { read: {}, + write: { + /** + * + * @param param0 + * @returns + */ mintNextAndAddAuthMethods: async ({ keyType, permittedAuthMethodTypes, @@ -1514,11 +1527,36 @@ export class LitContracts { permittedAuthMethodScopes, addPkpEthAddressAsPermittedAddress, sendPkpToItself, - { value: mintCost }, + { value: mintCost } ); - console.log("tx", tx); + console.log('tx', tx); return tx; - } - } + }, + claimAndMintNextAndAddAuthMethods: async ( + keyType: number, + derivedKeyId: string, + signatures: pkpHelperContract.ClaimAndMintNextAndAddAuthMethodsRequest[], + permittedAuthMethodTypes: string[], + permittedAuthMethodIds: string[], + permittedAuthMethodPubkeys: string[], + permittedAuthMethodScopes: string[][], + addPkpEthAddressAsPermittedAddress: boolean, + sendPkpToItself: boolean + ): Promise => { + const mintCost = await this.pkpNftContract.read.mintCost(); + this.pkpHelperContract.write.claimAndMintNextAndAddAuthMethods( + keyType, + `0x${derivedKeyId}` as unknown as pkpHelperContract.Arrayish, + signatures, + permittedAuthMethodTypes, + permittedAuthMethodIds as unknown as pkpHelperContract.Arrayish[], + permittedAuthMethodPubkeys as unknown as pkpHelperContract.Arrayish[], + permittedAuthMethodScopes, + addPkpEthAddressAsPermittedAddress, + sendPkpToItself, + { value: mintCost } + ); + }, + }, }; }