Skip to content

Commit

Permalink
Merge pull request #519 from LIT-Protocol/feature/3404-add-manual-gas…
Browse files Browse the repository at this point in the history
…-limit

feat: add custom gas limit
  • Loading branch information
Ansonhkg authored Jul 2, 2024
2 parents 2efb2a2 + 2881f6e commit ddb9982
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
29 changes: 14 additions & 15 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import bs58 from 'bs58';
import { isBrowser, isNode } from '@lit-protocol/misc';
import {
CreateCustomAuthMethodRequest,
GasLimitParam,
LIT_NETWORKS_KEYS,
LitContractContext,
LitContractResolverContext,
MintCapacityCreditsContext,
MintCapacityCreditsRes,
MintNextAndAddAuthMethods,
MintWithAuthParams,
MintWithAuthResponse,
} from '@lit-protocol/types';
Expand Down Expand Up @@ -103,6 +105,8 @@ declare global {
}
}

const GAS_LIMIT = ethers.utils.hexlify(5000000); // Adjust as needed

// This code defines a LitContracts class that acts as a container for a collection of smart contracts. The class has a constructor that accepts an optional args object with provider and rpc properties. If no provider is specified, the class will create a default provider using the specified rpc URL. If no rpc URL is specified, the class will use a default URL.
// The class has a number of properties that represent the smart contract instances, such as accessControlConditionsContract, litTokenContract, pkpNftContract, etc. These smart contract instances are created by passing the contract address, ABI, and provider to the ethers.Contract constructor.
// The class also has a utils object with helper functions for converting between hexadecimal and decimal representation of numbers, as well as functions for working with multihashes and timestamps.
Expand Down Expand Up @@ -1042,6 +1046,7 @@ export class LitContracts {
scopes,
pubkey,
authMethodId,
gasLimit,
}: MintWithAuthParams): Promise<MintWithAuthResponse<ContractReceipt>> => {
// -- validate
if (!this.connected) {
Expand Down Expand Up @@ -1107,10 +1112,9 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
true,
{
value: mintCost,
gasLimit: ethers.utils.hexlify(5000000), // Adjust as needed
gasLimit: gasLimit || GAS_LIMIT, // Adjust as needed
}
);

const receipt = await tx.wait();

const events = 'events' in receipt ? receipt.events : receipt.logs;
Expand Down Expand Up @@ -1295,6 +1299,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
requestsPerSecond,
requestsPerKilosecond,
daysUntilUTCMidnightExpiration,
gasLimit,
}: MintCapacityCreditsContext): Promise<MintCapacityCreditsRes> => {
this.log('Minting Capacity Credits NFT...');

Expand Down Expand Up @@ -1380,6 +1385,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
try {
const res = await this.rateLimitNftContract.write.mint(expiresAt, {
value: mintCost,
gasLimit: gasLimit || GAS_LIMIT,
});

const txHash = res.hash;
Expand Down Expand Up @@ -1614,7 +1620,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
},
},
write: {
mint: async () => {
mint: async (param?: GasLimitParam) => {
if (!this.connected) {
throw new Error(
'Contracts are not connected. Please call connect() first'
Expand Down Expand Up @@ -1644,7 +1650,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
const tx =
await this.pkpNftContract.write.populateTransaction.mintNext(2, {
value: mintCost,
gasLimit: ethers.utils.hexlify(5000000), // Adjust as needed
gasLimit: param?.gasLimit || GAS_LIMIT,
});
this.log('tx:', tx);

Expand All @@ -1659,7 +1665,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
} else {
sentTx = await this.pkpNftContract.write.mintNext(2, {
value: mintCost,
gasLimit: ethers.utils.hexlify(5000000), // Adjust as needed
gasLimit: param?.gasLimit || GAS_LIMIT,
});
}

Expand Down Expand Up @@ -2407,15 +2413,8 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
permittedAuthMethodScopes,
addPkpEthAddressAsPermittedAddress,
sendPkpToItself,
}: {
keyType: string;
permittedAuthMethodTypes: string[];
permittedAuthMethodIds: string[];
permittedAuthMethodPubkeys: string[];
permittedAuthMethodScopes: string[][];
addPkpEthAddressAsPermittedAddress: boolean;
sendPkpToItself: boolean;
}): Promise<any> => {
gasLimit,
}: MintNextAndAddAuthMethods): Promise<any> => {
// first get mint cost
const mintCost = await this.pkpNftContract.read.mintCost();
const tx = await this.pkpHelperContract.write.mintNextAndAddAuthMethods(
Expand All @@ -2429,7 +2428,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope

{
value: mintCost,
gasLimit: ethers.utils.hexlify(5000000), // Adjust as needed
gasLimit: gasLimit || GAS_LIMIT,
}
);
return tx;
Expand Down
19 changes: 17 additions & 2 deletions packages/types/src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,8 @@ export interface MintCapacityCreditsPerKilosecond
export interface MintCapacityCreditsContext
extends MintCapacityCreditsPerDay,
MintCapacityCreditsPerSecond,
MintCapacityCreditsPerKilosecond {}
MintCapacityCreditsPerKilosecond,
GasLimitParam {}
export interface MintCapacityCreditsRes {
rliTxHash: string;
capacityTokenId: any;
Expand Down Expand Up @@ -1886,7 +1887,21 @@ export interface SignatureData {

export type ClaimsList = Record<string, SignatureData>[];

export interface MintWithAuthParams {
export interface GasLimitParam {
gasLimit?: number;
}

export interface MintNextAndAddAuthMethods extends GasLimitParam {
keyType: string;
permittedAuthMethodTypes: string[];
permittedAuthMethodIds: string[];
permittedAuthMethodPubkeys: string[];
permittedAuthMethodScopes: string[][];
addPkpEthAddressAsPermittedAddress: boolean;
sendPkpToItself: boolean;
}

export interface MintWithAuthParams extends GasLimitParam {
/**
* auth method to use for minting
*/
Expand Down

0 comments on commit ddb9982

Please sign in to comment.