-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: document policies * chore: restore chain docs * chore: formatting * chore: restore terms of service * chore: restore chain docs * chore: adjust policy documentation * chore: adjust policy documentation * chore: adjust policy documentation * Updated understanding-policies.mdx for added clarity * added more detail on how each of the policies work * Change gold to diamond for consistency * Fix typo --------- Co-authored-by: alejandroreinel <[email protected]> Co-authored-by: areinel <[email protected]> Co-authored-by: lewinskimaciej <[email protected]>
- Loading branch information
1 parent
5b9d4d7
commit 2caef81
Showing
9 changed files
with
157 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"introduction": "Introduction", | ||
"understanding-policies": "Understanding policies", | ||
"managing-policies": "Managing policies", | ||
"using-policies": "Using policies" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Policies | ||
|
||
Policies are the means to make Profiles pay for transactions in an on-chain, in-game ERC20 token - but not necessarily the native one. If your game supports an in-game ERC20 token - let's call them Gold - and you would like to charge your user an X amount of Gold for every on-chain transaction you facilitate, Policies are the feature you're looking for. | ||
|
||
A policy is nothing else than a simple set of rules, which you can reference in every transaction that you make - the rules you define are up to you. | ||
|
||
- [Understanding policies](/service/policies/understanding-policies): Explainer on the different types of policies | ||
|
||
- [Managing policies](/service/policies/managing-policies): How to create, retrieve and delete policies | ||
|
||
- [Using policies](/service/policies/using-policies): How to use the policies you defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Creating policies | ||
|
||
Creating a policy is as simple as calling the `CreatePolicy` method. We highly recommend getting a good understanding about policies first by reading the [Understanding policies](/service/policies/understanding-policies) section. | ||
|
||
```typescript | ||
const profile = await beam.policies.createPolicy({ | ||
tokenAddress: "0x0...", // ERC20 token address (contract must be added to your game) | ||
amount: 1, // the fixed charge or the exchnage rate to wei | ||
rateType: "Fixed", // 'Fixed' (recommended) or 'Dynamic' | ||
chainId: 13337, // 13337 for Beam testnet, 4337 for mainnet | ||
}); | ||
|
||
// { | ||
// "id": "string", | ||
// "chainId": 13337, | ||
// "token": "string", | ||
// "amount": "string", | ||
// "rateType": "Fixed" | ||
// } | ||
``` | ||
|
||
#### Retrieving all policies | ||
|
||
If you want to return a list of all active policies in your application use the `GetPolicies` method. | ||
|
||
```typescript | ||
const profile = await beam.policies.getPolicies(); | ||
|
||
// { | ||
// "data": [ | ||
// { | ||
// "id": "string", | ||
// "chainId": 13337, | ||
// "token": "string", | ||
// "amount": "string", | ||
// "rateType": "Fixed" | ||
// } | ||
// ] | ||
// } | ||
``` | ||
|
||
#### Deleting policies | ||
|
||
If you want to clean up old policies, simply call the `DeletePolicy` method and pass the Policy ID. | ||
|
||
```typescript | ||
const profile = await beam.policies.deletePolicy("policy-id"); | ||
|
||
// { | ||
// "success": true, | ||
// } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Understanding Gas and Policies in EVM Blockchains | ||
|
||
### Overview of Gas on EVM Blockchains | ||
- **Gas Units**: A measure of computational effort required to execute transactions or smart contracts on the Ethereum Virtual Machine (EVM). | ||
- **Gas Payment in Native Currency**: Each blockchain has its own native currency for gas payments. Examples include: | ||
- Beam: Paid in Beam. | ||
- Ethereum: Paid in Ether. | ||
- Polygon: Paid in MATIC. | ||
|
||
### Challenge: Users Lacking Native Currency | ||
In scenarios where users need to transact but lack the native currency for gas, Beam 'policies' provide a solution, allowing for payments in a specific ERC20 token. | ||
|
||
### Types of Policies for Transactions | ||
|
||
#### 1. Fixed Charge Policies | ||
**A set amount of the ERC20 token is charged per transaction, regardless of the gas cost.** | ||
- **Economics**: While offering stable and predictable costs for users, this model can be financially risky for developers during high gas prices. | ||
- **User**: Users benefit from a straightforward and predictable cost structure, making budgeting for transactions easier and transparent. | ||
- **Example**: A transfer transaction might be set at 1 $Gold, while a minting transaction costs 10 $Gold. They will always cost the same, regardless of the gas price. | ||
|
||
#### 2. Dynamic Charge Policies | ||
**Charges in ERC20 tokens are calculated based on the current gas cost, the developer needs to set and exchange rate of ERC20 to wei in native currency.** | ||
- **Economics**: Aligns transaction costs with real-time gas market prices, introducing variability in costs for the user. | ||
- **User**: Users face fluctuating transaction costs, which can be challenging to predict and may require an understanding of gas market dynamics. | ||
- **Example**: | ||
- If the gas price is 20 gwei: | ||
- Mint transaction: 100 gas units * 20 gwei = 2,000 wei (equivalent to 20,000 $Gold at an exchange rate of 10 $Gold per wei). | ||
- Transfer transaction: 50 gas units * 20 gwei = 1,000 wei (equivalent to 10,000 $Gold). | ||
- If the gas price is 10 gwei: | ||
- Mint transaction: 100 gas units * 10 gwei = 1,000 wei (equivalent to 10,000 $Gold). | ||
- Transfer transaction: 50 gas units * 10 gwei = 500 wei (equivalent to 5,000 $Gold). | ||
- **Note**: Example calculations are for illustrative purposes and should be adapted for production use. | ||
|
||
### Choosing Between Fixed and Dynamic Policies | ||
Developers must weigh the benefits of simplicity (fixed policies) against the need for adaptability to market conditions (dynamic policies). | ||
- **User Considerations**: Given that most users lack in-depth knowledge of gas mechanics, the responsibility of managing price volatility and associated risks ideally lies with the developers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Using policies | ||
|
||
Once created, policies will only be used if you explicitly pass the Policy ID when running a transaction. The general rule of thumb is that the `policyId` property will be available on every method in our SDK if the method itself triggers an on-chain transaction. | ||
|
||
```typescript | ||
const transaction = await beam.assets.transferAsset("your-sender-id", { | ||
receiverEntityId: "your-receiver-id", | ||
assetAddress: "your-contract-address", | ||
assetId: "73", | ||
// ... | ||
sponsor: false, // 👈 This handles the transaction to be self paid | ||
policyId: "cl..", // 👈 This triggers the custom policy to be used | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
## Reporting | ||
|
||
If you're interesting in getting insight into how each policy is performing in your game, head over to [Reporting](/service/reporting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2caef81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
beam-docs – ./
beam-docs-git-main-merit-circle.vercel.app
beam-docs-merit-circle.vercel.app
docs.onbeam.com