Skip to content

Commit

Permalink
Add oracle payer subsidy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Nov 11, 2024
1 parent aab65bf commit cd643ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/distributor-oracle/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,22 @@ export async function formBulkTransactions({
assetEndpoint || provider.connection.rpcEndpoint,
assets
);
const willPay = (await axios.get(
`${lazyDistributorAcc.oracles[0].url}/will-pay-recipient`
)).data.willPay;
let ixsPerAsset = await Promise.all(
recipientAccs.map(async (recipientAcc, idx) => {
if (!recipientAcc) {
return [
await (
await(
await initializeCompressionRecipient({
program: lazyDistributorProgram,
assetId: assets![idx],
lazyDistributor,
assetEndpoint,
owner: wallet,
payer,
// Temporarily set oracle as the payer to subsidize new HNT wallets.
payer: willPay ? lazyDistributorAcc.oracles[0].oracle : payer,
getAssetFn: () => Promise.resolve(compressionAssetAccs![idx]), // cache result so we don't hit again
getAssetProofFn: assetProofsById
? () =>
Expand Down Expand Up @@ -522,6 +526,9 @@ export async function formTransaction({
const recipientAcc =
await lazyDistributorProgram.account.recipientV0.fetchNullable(recipient);
if (!recipientAcc) {
const willPay = (
await axios.get(`${lazyDistributorAcc.oracles[0].url}/will-pay-recipient`)
).data.willPay;
let initRecipientIx;
if (assetAcc.compression.compressed) {
initRecipientIx = await (
Expand All @@ -531,7 +538,7 @@ export async function formTransaction({
lazyDistributor,
assetEndpoint,
owner: wallet,
payer,
payer: willPay ? lazyDistributorAcc.oracles[0].oracle : payer,
getAssetFn: () => Promise.resolve(assetAcc), // cache result so we don't hit again
getAssetProofFn,
})
Expand Down
24 changes: 24 additions & 0 deletions packages/distributor-oracle/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ export class OracleServer {
private addRoutes() {
this.app.get("/active-devices", this.getActiveDevicesHandler.bind(this));
this.app.post("/bulk-rewards", this.getAllRewardsHandler.bind(this));
this.app.get(
"/will-pay-recipient",
(
_req: FastifyRequest<{ Body: { entityKeys: string[] } }>,
res: FastifyReply
) => {
res.send({
willPay: process.env.WILL_PAY_RECIPIENT === "true",
});
}
);
this.app.get<{
Querystring: {
assetId?: string;
Expand Down Expand Up @@ -361,6 +372,10 @@ export class OracleServer {
initCompressionRecipientTx.accounts.findIndex(
(x) => x.name === "lazyDistributor"
)!;
const payerIdxInitCompressionRecipient =
initCompressionRecipientTx.accounts.findIndex(
(x) => x.name === "payer"
)!;
const mintIdx = initRecipientTx.accounts.findIndex(
(x) => x.name === "mint"
)!;
Expand Down Expand Up @@ -443,6 +458,15 @@ export class OracleServer {
allAccs[ix.accountKeyIndexes[lazyDistributorIdxInitCompressionRecipient]].toBase58();
const merkleTree =
allAccs[ix.accountKeyIndexes[merkleTreeIdxInitCompressionRecipient]];
const payer =
allAccs[ix.accountKeyIndexes[payerIdxInitCompressionRecipient]].toBase58();

if (process.env.WILL_PAY_RECIPIENT !== "true" && payer === this.oracle.publicKey.toBase58()) {
return {
success: false,
message: "Cannot set this oracle as the payer",
};
}

const index = (decoded.data as any).args.index;
recipientToLazyDistToMint[recipient][lazyDist] = await getLeafAssetId(
Expand Down

0 comments on commit cd643ed

Please sign in to comment.