diff --git a/packages/distributor-oracle/src/client.ts b/packages/distributor-oracle/src/client.ts index 5245d8bb0..5a13fa640 100644 --- a/packages/distributor-oracle/src/client.ts +++ b/packages/distributor-oracle/src/client.ts @@ -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 ? () => @@ -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 ( @@ -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, }) diff --git a/packages/distributor-oracle/src/server.ts b/packages/distributor-oracle/src/server.ts index 00afc1285..aba1ce9a1 100644 --- a/packages/distributor-oracle/src/server.ts +++ b/packages/distributor-oracle/src/server.ts @@ -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; @@ -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" )!; @@ -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(