Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-gifts-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": minor
---

Improve data fetching for erc20 interfaces
57 changes: 34 additions & 23 deletions packages/sdk/src/evm/core/classes/erc-20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ export class Erc20<
* @twfeature ERC20
*/
public async allowance(spender: AddressOrEns): Promise<CurrencyValue> {
return await this.allowanceOf(
await this.contractWrapper.getSignerAddress(),
await resolveAddress(spender),
);
const [owner, spenderAddress] = await Promise.all([
this.contractWrapper.getSignerAddress(),
resolveAddress(spender),
]);
return await this.allowanceOf(owner, spenderAddress);
}

/**
Expand All @@ -224,10 +225,14 @@ export class Erc20<
owner: AddressOrEns,
spender: AddressOrEns,
): Promise<CurrencyValue> {
const args = await Promise.all([
resolveAddress(owner),
resolveAddress(spender),
]);
return await this.getValue(
await (this.contractWrapper as ContractWrapper<BaseERC20>).read(
"allowance",
[await resolveAddress(owner), await resolveAddress(spender)],
args,
),
);
}
Expand All @@ -252,7 +257,10 @@ export class Erc20<
return Transaction.fromContractWrapper({
contractWrapper: this.contractWrapper,
method: "transfer",
args: [await resolveAddress(to), await this.normalizeAmount(amount)],
args: await Promise.all([
resolveAddress(to),
this.normalizeAmount(amount),
]),
});
},
);
Expand Down Expand Up @@ -280,11 +288,11 @@ export class Erc20<
return Transaction.fromContractWrapper({
contractWrapper: this.contractWrapper,
method: "transferFrom",
args: [
await resolveAddress(from),
await resolveAddress(to),
await this.normalizeAmount(amount),
],
args: await Promise.all([
resolveAddress(from),
resolveAddress(to),
this.normalizeAmount(amount),
]),
});
},
);
Expand All @@ -307,10 +315,10 @@ export class Erc20<
return Transaction.fromContractWrapper({
contractWrapper: this.contractWrapper,
method: "approve",
args: [
await resolveAddress(spender),
await this.normalizeAmount(amount),
],
args: await Promise.all([
resolveAddress(spender),
this.normalizeAmount(amount),
]),
});
},
);
Expand Down Expand Up @@ -340,14 +348,17 @@ export class Erc20<
transferBatch = /* @__PURE__ */ buildTransactionFunction(
async (args: TokenMintInput[]) => {
const contractEncoder = new ContractEncoder(this.contractWrapper);
const encoded = await Promise.all(
args.map(async (arg) => {
const amountWithDecimals = await this.normalizeAmount(arg.amount);
return contractEncoder.encode("transfer", [
await resolveAddress(arg.toAddress),
amountWithDecimals,
]);
}),
const encoded = (
await Promise.all(
args.map((arg) =>
Promise.all([
this.normalizeAmount(arg.amount),
resolveAddress(arg.toAddress),
]),
),
)
).map(([amountWithDecimals, address]) =>
contractEncoder.encode("transfer", [address, amountWithDecimals]),
);
return Transaction.fromContractWrapper({
contractWrapper: this.contractWrapper,
Expand Down