Skip to content

Commit

Permalink
added optional paramter blockNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
MSamiTariq committed Oct 21, 2024
1 parent 8ee8fde commit 119ebdb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
9 changes: 8 additions & 1 deletion plugins/scenario/utils/TokenSourcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface SourceTokenParameters {
asset: string;
address: string;
blacklist: string[];
blockNumber?: number;
}

export async function fetchQuery(
Expand Down Expand Up @@ -55,14 +56,20 @@ export async function sourceTokens({
asset,
address,
blacklist,
blockNumber,
}: SourceTokenParameters) {
let amount = BigNumber.from(amount_);
if (amount.isZero()) {
return;
} else if (amount.isNegative()) {
await removeTokens(dm, amount.abs(), asset, address);
} else {
await addTokens(dm, amount, asset, address, [address].concat(blacklist));
if(blockNumber) {
await addTokens(dm, amount, asset, address, [address].concat(blacklist), blockNumber);
} else {
await addTokens(dm, amount, asset, address, [address].concat(blacklist));
}

}
}

Expand Down
7 changes: 6 additions & 1 deletion scenario/RewardsScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ async function testScalingReward(properties: CometProperties, context: CometCont
[albert.address]
);
await newRewards.connect(albert.signer).setRewardConfigWithMultiplier(comet.address, rewardTokenAddress, multiplier);
await context.sourceTokens(100000, rewardTokenAddress, newRewards.address);
await context.sourceTokens(
100000,
rewardTokenAddress,
newRewards.address,
2751700
);

await baseAsset.approve(albert, comet.address);
await albert.safeSupplyAsset({ asset: baseAssetAddress, amount: 100n * baseScale });
Expand Down
27 changes: 19 additions & 8 deletions scenario/context/CometContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class CometContext {
throw new Error(`Unable to find asset by address ${address}`);
}

async sourceTokens(amount: number | bigint, asset: CometAsset | string, recipient: AddressLike) {
async sourceTokens(amount: number | bigint, asset: CometAsset | string, recipient: AddressLike, blockNumber?: number) {
const { world } = this;
const recipientAddress = resolveAddress(recipient);
const cometAsset = typeof asset === 'string' ? this.getAssetByAddress(asset) : asset;
Expand All @@ -281,13 +281,24 @@ export class CometContext {
if (amountRemaining != 0n) {
// Source from logs (expensive, in terms of node API limits)
debug('Source Tokens: sourcing from logs...', amountRemaining, cometAsset.address);
await sourceTokens({
dm: this.world.deploymentManager,
amount: amountRemaining,
asset: cometAsset.address,
address: recipientAddress,
blacklist: [comet.address],
});
if (blockNumber) {
await sourceTokens({
dm: this.world.deploymentManager,
amount: amountRemaining,
asset: cometAsset.address,
address: recipientAddress,
blacklist: [comet.address],
blockNumber,
});
} else {
await sourceTokens({
dm: this.world.deploymentManager,
amount: amountRemaining,
asset: cometAsset.address,
address: recipientAddress,
blacklist: [comet.address],
});
}
}
}

Expand Down

0 comments on commit 119ebdb

Please sign in to comment.