Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: AMB payment logic #34

Merged
merged 2 commits into from
Jun 25, 2024
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
3 changes: 2 additions & 1 deletion src/config/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ const AMBS_SCHEMA = {
enabled: {
type: "boolean"
},
incentivesAddress: { $ref: "address-field-schema" }
incentivesAddress: { $ref: "address-field-schema" },
packetCost: { $ref: "gas-field-schema" }
},
required: ["name"],
additionalProperties: true,
Expand Down
18 changes: 14 additions & 4 deletions src/submitter/queues/eval-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
private readonly resolver: Resolver,
private readonly store: Store,
private readonly incentivesContracts: Map<string, string>,
private readonly packetCosts: Map<string, bigint>,
private readonly chainId: string,
private readonly evaluationConfig: BountyEvaluationConfig,
private readonly pricing: PricingInterface,
Expand Down Expand Up @@ -86,16 +87,22 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
this.paddedRelayerAddress,
]);

const value = isDelivery
? this.packetCosts.get(order.amb) ?? 0n
: 0n;

const transactionRequest: TransactionRequest = {
from: this.relayerAddress,
to: contractAddress,
data: transactionData,
value,
}

const gasEstimateComponents = await this.resolver.estimateGas(transactionRequest);

const submitRelay = await this.evaluateRelaySubmission(
gasEstimateComponents,
value,
bounty,
order
);
Expand Down Expand Up @@ -186,6 +193,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {

private async evaluateRelaySubmission(
gasEstimateComponents: GasEstimateComponents,
value: bigint,
bounty: Bounty,
order: EvalOrder,
): Promise<boolean> {
Expand All @@ -210,7 +218,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
return true;
}

return this.evaluateDeliverySubmission(gasEstimateComponents, bounty);
return this.evaluateDeliverySubmission(gasEstimateComponents, value, bounty);
} else {
// Destination to Source
if (order.priority) {
Expand All @@ -228,12 +236,13 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
return true;
}

return this.evaluateAckSubmission(gasEstimateComponents, bounty, order.incentivesPayload);
return this.evaluateAckSubmission(gasEstimateComponents, value, bounty, order.incentivesPayload);
}
}

private async evaluateDeliverySubmission(
gasEstimateComponents: GasEstimateComponents,
value: bigint,
bounty: Bounty
): Promise<boolean> {

Expand All @@ -249,7 +258,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
const deliveryCost = this.calcGasCost( // ! In destination chain gas value
gasEstimate,
destinationGasPrice,
additionalFeeEstimate
additionalFeeEstimate + value
);

const deliveryReward = this.calcGasReward( // ! In source chain gas value
Expand Down Expand Up @@ -326,6 +335,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {

private async evaluateAckSubmission(
gasEstimateComponents: GasEstimateComponents,
value: bigint,
bounty: Bounty,
incentivesPayload?: BytesLike,
): Promise<boolean> {
Expand All @@ -341,7 +351,7 @@ export class EvalQueue extends ProcessingQueue<EvalOrder, SubmitOrder> {
const ackCost = this.calcGasCost( // ! In source chain gas value
gasEstimate,
sourceGasPrice,
additionalFeeEstimate
additionalFeeEstimate + value
);

const ackReward = this.calcGasReward( // ! In source chain gas value
Expand Down
17 changes: 17 additions & 0 deletions src/submitter/submitter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface SubmitterWorkerData {
rpc: string;
resolver: string | null;
incentivesAddresses: Map<string, string>;
packetCosts: Map<string, bigint>;
newOrdersDelay: number;
retryInterval: number;
processingInterval: number;
Expand Down Expand Up @@ -212,11 +213,27 @@ export class SubmitterService {
}
});

const packetCosts = new Map<string, bigint>();
this.configService.ambsConfig.forEach((amb) => {
const packetCost: string = this.configService.getAMBConfig(
amb.name,
'packetCost',
chainConfig.chainId
);
if (packetCost != undefined) {
packetCosts.set(
amb.name,
BigInt(packetCost), //TODO add log error if this fails
);
}
});

return {
chainId,
rpc,
resolver: chainConfig.resolver,
incentivesAddresses,
packetCosts,

newOrdersDelay:
chainConfig.submitter.newOrdersDelay ?? globalConfig.newOrdersDelay,
Expand Down
3 changes: 3 additions & 0 deletions src/submitter/submitter.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SubmitterWorker {
this.resolver,
this.store,
this.config.incentivesAddresses,
this.config.packetCosts,
this.config.chainId,
{
evaluationRetryInterval: this.config.evaluationRetryInterval,
Expand Down Expand Up @@ -107,6 +108,7 @@ class SubmitterWorker {
resolver: Resolver,
store: Store,
incentivesContracts: Map<string, string>,
packetCosts: Map<string, bigint>,
chainId: string,
bountyEvaluationConfig: BountyEvaluationConfig,
pricing: PricingInterface,
Expand All @@ -121,6 +123,7 @@ class SubmitterWorker {
resolver,
store,
incentivesContracts,
packetCosts,
chainId,
bountyEvaluationConfig,
pricing,
Expand Down