-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(world): add Balance table and BalanceTransferSystem (#1425)
- Loading branch information
Showing
39 changed files
with
1,771 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
"@latticexyz/world": major | ||
--- | ||
|
||
The World now maintains a balance per namespace. | ||
When a system is called with value, the value stored in the World contract and credited to the system's namespace. | ||
|
||
Previously, the World contract did not store value, but passed it on to the system contracts. | ||
However, as systems are expected to be stateless (reading/writing state only via the calling World) and can be registered in multiple Worlds, this could have led to exploits. | ||
|
||
Any address with access to a namespace can use the balance of that namespace. | ||
This allows all systems registered in the same namespace to work with the same balance. | ||
|
||
There are two new World methods to transfer balance between namespaces (`transferBalanceToNamespace`) or to an address (`transferBalanceToAddress`). | ||
|
||
```solidity | ||
interface IBaseWorld { | ||
function transferBalanceToNamespace(bytes16 fromNamespace, bytes16 toNamespace, uint256 amount) external; | ||
function transferBalanceToAddress(bytes16 fromNamespace, address toAddress, uint256 amount) external; | ||
} | ||
``` |
237 changes: 237 additions & 0 deletions
237
packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json
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,237 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "resource", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "caller", | ||
"type": "address" | ||
} | ||
], | ||
"name": "AccessDenied", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "delegator", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "delegatee", | ||
"type": "address" | ||
} | ||
], | ||
"name": "DelegationNotFound", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes4", | ||
"name": "functionSelector", | ||
"type": "bytes4" | ||
} | ||
], | ||
"name": "FunctionSelectorExists", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes4", | ||
"name": "functionSelector", | ||
"type": "bytes4" | ||
} | ||
], | ||
"name": "FunctionSelectorNotFound", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "balance", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "InsufficientBalance", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "resource", | ||
"type": "string" | ||
} | ||
], | ||
"name": "InvalidSelector", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "module", | ||
"type": "string" | ||
} | ||
], | ||
"name": "ModuleAlreadyInstalled", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "length", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "PackedCounter_InvalidLength", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "resource", | ||
"type": "string" | ||
} | ||
], | ||
"name": "ResourceExists", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "resource", | ||
"type": "string" | ||
} | ||
], | ||
"name": "ResourceNotFound", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "length", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "SchemaLib_InvalidLength", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "SchemaLib_StaticTypeAfterDynamicType", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes", | ||
"name": "data", | ||
"type": "bytes" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "start", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "end", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Slice_OutOfBounds", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "expected", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "received", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "StoreCore_InvalidDataLength", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "system", | ||
"type": "address" | ||
} | ||
], | ||
"name": "SystemExists", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes16", | ||
"name": "fromNamespace", | ||
"type": "bytes16" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "toAddress", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferBalanceToAddress", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes16", | ||
"name": "fromNamespace", | ||
"type": "bytes16" | ||
}, | ||
{ | ||
"internalType": "bytes16", | ||
"name": "toNamespace", | ||
"type": "bytes16" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferBalanceToNamespace", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
Oops, something went wrong.