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
1 change: 1 addition & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface Solution {
name: string;
};
transaction: Transaction;
approvals?: Transaction[];
}

export interface Transaction {
Expand Down
34 changes: 22 additions & 12 deletions web/src/lib/components/TransactionCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,31 @@
// @ts-expect-error // chainId is missing in web3js call options type
const callOptions: NonPayableCallOptions = { chainId: quotaRecord.sourceChain };

console.info('Quote', quotaRecord);

// Approval sniff etc...\
const erc20 = new web3.eth.Contract(erc20Abi, quotaRecord.sourceTokenAddress);
if (quotaRecord.approvals?.length > 0) {
for (const approval of quotaRecord.approvals) {
console.log('Requesting approval:', approval);
const receipt = await web3.eth.sendTransaction(approval);
console.warn(`Approval receipt: `, receipt);
}
} else {
const erc20 = new web3.eth.Contract(erc20Abi, quotaRecord.sourceTokenAddress);

const allowed = await erc20.methods
.allowance(ownerAddress, quotaRecord.transaction.to)
.call(callOptions);
const allowed = await erc20.methods
.allowance(ownerAddress, quotaRecord.transaction.to)
.call(callOptions);

if (BigInt(quotaRecord.amount) > BigInt(allowed)) {
const approval = await erc20.methods
.approve(quotaRecord.transaction.to, quotaRecord.amount)
.send({
...callOptions,
from: ownerAddress
});
if (!approval.status) throw new Error('Not Approved!'); // To stop execution
if (BigInt(quotaRecord.amount) > BigInt(allowed)) {
const approval = await erc20.methods
.approve(quotaRecord.transaction.to, quotaRecord.amount)
.send({
...callOptions,
from: ownerAddress
});
if (!approval.status) throw new Error('Not Approved!'); // To stop execution
}
}

// FINAL STEP!
Expand Down