Skip to content

Commit

Permalink
feat(#483): Create a burn rewardable entity as a sink for unused serv…
Browse files Browse the repository at this point in the history
…ice provider reward (#487)

* WIP

* WIP

* feat(#483): Create a burn rewardable entity as a sink for unused service provider rewards

* Fix token metadata breaking semver
  • Loading branch information
ChewingGlass authored Nov 13, 2023
1 parent 0fffa80 commit 2b8ff5b
Show file tree
Hide file tree
Showing 41 changed files with 3,168 additions and 32 deletions.
4 changes: 3 additions & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rewards_oracle = "rorcfdX4h9m9swCKgcypaHJ8NGYVANBpmV9EHn3cYrF"
voter_stake_registry = "hvsrNC3NKbcryqDs2DocYHZ9yPKEVzdSjQG6RVtK1s8"
fanout = "fanqeMu3fw8R4LwKNbahPtYXJsyLL6NXyfe2BqzhfB6"
mobile_entity_manager = "memMa1HG4odAFmUbGWfPwS1WWfK95k99F2YTkGvyxZr"
rewards_burn = "burnhwK2QgaJnK93i82g8dH1zDjbpwxMukyVit9xYXo"

[workspace]
members = [
Expand All @@ -29,7 +30,8 @@ members = [
"programs/rewards-oracle",
"programs/voter-stake-registry",
"programs/fanout",
"programs/mobile-entity-manager"
"programs/mobile-entity-manager",
"programs/rewards-burn",
]

[registry]
Expand Down
17 changes: 15 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exclude = [
[workspace.dependencies]
anchor-lang = { version = "0.28.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.28.0", features = ["mint", "token"] }
mpl-token-metadata = { version = "3.1.0" }
mpl-token-metadata = { version = "3.2.0" }
account-compression-cpi = { rev = "a2d12e4a157d91feb73aa40a97fe297fd477dd87", git = "https://github.com/helium/account-compression-anchor-gen.git", features = ["cpi"]}
bubblegum-cpi = { rev = "a2d12e4a157d91feb73aa40a97fe297fd477dd87", git = "https://github.com/helium/account-compression-anchor-gen.git", features = ["cpi"]}
solana-security-txt = "1.1.1"
Expand All @@ -28,3 +28,4 @@ shared-utils = { path = "./utils/shared-utils" }
circuit-breaker = { path = "./programs/circuit-breaker", features = ["cpi"] }
helium-sub-daos = { path = "./programs/helium-sub-daos", features = ["cpi"] }
helium-entity-manager = { path = "./programs/helium-entity-manager", features = ["cpi"] }
rewards-burn = { path = "./programs/rewards-burn", features = ["cpi"] }
2 changes: 2 additions & 0 deletions packages/anchor-resolvers/src/heliumCommonResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const heliumCommonResolver = resolveIndividual(async ({ path }) => {
return new PublicKey("Sysvar1nstructions1111111111111111111111111");
case "lazyDistributorProgram":
return new PublicKey("1azyuavdMyvsivtNxPoz6SucD18eDHeXzFCUPq5XU7w");
case "rewardsBurnProgram":
return new PublicKey("burnhwK2QgaJnK93i82g8dH1zDjbpwxMukyVit9xYXo");
default:
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/crons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@helium/organization-sdk": "^0.0.8",
"@helium/price-oracle-sdk": "^0.6.1",
"@helium/proposal-sdk": "^0.0.8",
"@helium/rewards-burn-sdk": "^0.6.1",
"@helium/rewards-oracle-sdk": "^0.6.1",
"@helium/spl-utils": "^0.6.1",
"@helium/state-controller-sdk": "^0.0.8",
Expand Down
85 changes: 83 additions & 2 deletions packages/crons/src/end-epoch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as anchor from '@coral-xyz/anchor';
import * as client from '@helium/distributor-oracle';
import { fanoutKey, init as initHydra } from '@helium/fanout-sdk';
import { init as initBurn } from "@helium/rewards-burn-sdk"
import {
init as initHem,
keyToAssetKey,
Expand All @@ -22,17 +23,20 @@ import { init as initRewards } from '@helium/rewards-oracle-sdk';
import {
HNT_MINT,
IOT_MINT,
MOBILE_MINT,
chunks,
createMintInstructions,
sendAndConfirmWithRetry,
} from '@helium/spl-utils';
import { getAccount } from '@solana/spl-token';
import { ComputeBudgetProgram as CBP } from '@solana/web3.js';
import { ComputeBudgetProgram as CBP, Keypair } from '@solana/web3.js';
import BN from 'bn.js';
import bs58 from 'bs58';

const FANOUT_NAME = 'HST';
const IOT_OPERATIONS_FUND = 'iot_operations_fund';
const MAX_CLAIM_AMOUNT = new BN('207020547945205');
const BURN = 'burn';
const MAX_CLAIM_AMOUNT = new BN("207020547945205");

(async () => {
try {
Expand Down Expand Up @@ -252,6 +256,83 @@ const MAX_CLAIM_AMOUNT = new BN('207020547945205');
errors.push(`Failed to distribute iot op funds: ${err}`);
}

// Claim and burn any rewards in the burn entity
console.log("Burning everything in the burn entity")
const burnProgram = await initBurn(provider)
const tokens = [MOBILE_MINT, IOT_MINT]
for (const token of tokens) {
const [lazyDistributor] = lazyDistributorKey(token);
const burnEntityKta = keyToAssetKey(dao, BURN, "utf-8")[0];
// Issue the burn entity if it doesn't exist yet.
if (!(await provider.connection.getAccountInfo(burnEntityKta))) {
const mint = Keypair.generate();
await hemProgram.methods
.issueBurnEntityV0()
.preInstructions(
await createMintInstructions(
provider,
0,
provider.wallet.publicKey,
provider.wallet.publicKey,
mint
)
)
.accounts({
dao,
mint: mint.publicKey,
})
.signers([mint])
.rpc({ skipPreflight: true });
}
const assetId = (
await hemProgram.account.keyToAssetV0.fetch(burnEntityKta)
).asset;
const [recipient] = recipientKey(lazyDistributor, assetId);

try {
if (!(await provider.connection.getAccountInfo(recipient))) {
const method = lazyProgram.methods.initializeRecipientV0().accounts({
lazyDistributor,
mint: assetId,
});

await method.rpc({ skipPreflight: true });
}

const rewards = await client.getCurrentRewards(
lazyProgram,
lazyDistributor,
assetId
);
const tx = await client.formTransaction({
program: lazyProgram,
rewardsOracleProgram: rewardsOracleProgram,
provider,
rewards,
asset: assetId,
lazyDistributor,
});
const signed = await provider.wallet.signTransaction(tx);
await sendAndConfirmWithRetry(
provider.connection,
signed.serialize(),
{ skipPreflight: true },
"confirmed"
);

await burnProgram.methods
.burnV0()
.accounts({
mint: token,
})
.rpc({ skipPreflight: true });
} catch (err: any) {
errors.push(
`Failed to distribute burn funds for mint ${token.toBase58()}: ${err}`
);
}
}

if (!errors.length) process.exit(0);
errors.map(console.log);
process.exit(1);
Expand Down
3 changes: 3 additions & 0 deletions packages/crons/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{
"path": "../fanout-sdk"
},
{
"path": "../rewards-burn-sdk"
},
{
"path": "../helium-sub-daos-sdk"
},
Expand Down
31 changes: 31 additions & 0 deletions packages/crons/yarn.deploy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ __metadata:
"@helium/organization-sdk": ^0.0.8
"@helium/price-oracle-sdk": ^0.6.1
"@helium/proposal-sdk": ^0.0.8
"@helium/rewards-burn-sdk": ^0.6.1
"@helium/rewards-oracle-sdk": ^0.6.1
"@helium/spl-utils": ^0.6.1
"@helium/state-controller-sdk": ^0.0.8
Expand Down Expand Up @@ -269,6 +270,7 @@ __metadata:
"@helium/anchor-resolvers": ^0.6.1
"@helium/helium-sub-daos-sdk": ^0.6.1
"@helium/idls": ^0.6.1
"@helium/rewards-burn-sdk": ^0.6.1
"@helium/spl-utils": ^0.6.1
"@types/crypto-js": ^4.1.1
bn.js: ^5.2.0
Expand Down Expand Up @@ -314,6 +316,19 @@ __metadata:
languageName: unknown
linkType: soft

"@helium/idls@npm:^0.5.0":
version: 0.5.0
resolution: "@helium/idls@npm:0.5.0"
dependencies:
"@coral-xyz/anchor": ^0.28.0
"@solana/web3.js": ^1.78.4
bn.js: ^5.2.0
borsh: ^0.7.0
bs58: ^4.0.1
checksum: 66a021a9953cf0a96f0eaf8932a2006286c266cc323f171eedf2bc18a94d55ad035cc7da9e21c99dc70fc77b1681630382a55999a2f40228f33611d7621a0c7c
languageName: node
linkType: hard

"@helium/lazy-distributor-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/lazy-distributor-sdk@workspace:packages/lazy-distributor-sdk"
Expand Down Expand Up @@ -396,6 +411,22 @@ __metadata:
languageName: node
linkType: hard

"@helium/rewards-burn-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/rewards-burn-sdk@workspace:packages/rewards-burn-sdk"
dependencies:
"@coral-xyz/anchor": ^0.28.0
"@helium/anchor-resolvers": ^0.5.0
"@helium/idls": ^0.5.0
bn.js: ^5.2.0
bs58: ^4.0.1
git-format-staged: ^2.1.3
ts-loader: ^9.2.3
ts-node: ^10.9.1
typescript: ^5.2.2
languageName: unknown
linkType: soft

"@helium/rewards-oracle-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/rewards-oracle-sdk@workspace:packages/rewards-oracle-sdk"
Expand Down
42 changes: 42 additions & 0 deletions packages/distributor-oracle/yarn.deploy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ __metadata:
languageName: unknown
linkType: soft

"@helium/anchor-resolvers@npm:^0.5.0":
version: 0.5.0
resolution: "@helium/anchor-resolvers@npm:0.5.0"
dependencies:
"@solana/spl-token": ^0.3.8
"@solana/web3.js": ^1.78.4
peerDependencies:
"@coral-xyz/anchor": ^0.28.0
checksum: b20f52072bb8e1cb097e951c98a66149989035a58d3f4de1998c3043a1e04e36b6dee2e0760b99d0fbd5fa4e47f499972ad17f6560e1f3c7424e96a1e35343a9
languageName: node
linkType: hard

"@helium/circuit-breaker-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/circuit-breaker-sdk@workspace:packages/circuit-breaker-sdk"
Expand Down Expand Up @@ -203,6 +215,7 @@ __metadata:
"@helium/anchor-resolvers": ^0.6.1
"@helium/helium-sub-daos-sdk": ^0.6.1
"@helium/idls": ^0.6.1
"@helium/rewards-burn-sdk": ^0.6.1
"@helium/spl-utils": ^0.6.1
"@types/crypto-js": ^4.1.1
bn.js: ^5.2.0
Expand Down Expand Up @@ -248,6 +261,19 @@ __metadata:
languageName: unknown
linkType: soft

"@helium/idls@npm:^0.5.0":
version: 0.5.0
resolution: "@helium/idls@npm:0.5.0"
dependencies:
"@coral-xyz/anchor": ^0.28.0
"@solana/web3.js": ^1.78.4
bn.js: ^5.2.0
borsh: ^0.7.0
bs58: ^4.0.1
checksum: 66a021a9953cf0a96f0eaf8932a2006286c266cc323f171eedf2bc18a94d55ad035cc7da9e21c99dc70fc77b1681630382a55999a2f40228f33611d7621a0c7c
languageName: node
linkType: hard

"@helium/lazy-distributor-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/lazy-distributor-sdk@workspace:packages/lazy-distributor-sdk"
Expand All @@ -264,6 +290,22 @@ __metadata:
languageName: unknown
linkType: soft

"@helium/rewards-burn-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/rewards-burn-sdk@workspace:packages/rewards-burn-sdk"
dependencies:
"@coral-xyz/anchor": ^0.28.0
"@helium/anchor-resolvers": ^0.5.0
"@helium/idls": ^0.5.0
bn.js: ^5.2.0
bs58: ^4.0.1
git-format-staged: ^2.1.3
ts-loader: ^9.2.3
ts-node: ^10.9.1
typescript: ^5.2.2
languageName: unknown
linkType: soft

"@helium/rewards-oracle-sdk@^0.6.1":
version: 0.0.0-use.local
resolution: "@helium/rewards-oracle-sdk@workspace:packages/rewards-oracle-sdk"
Expand Down
Loading

0 comments on commit 2b8ff5b

Please sign in to comment.