Skip to content

Commit d5d1bb0

Browse files
committed
feat: upgradable integration
1 parent 02d12c5 commit d5d1bb0

4 files changed

Lines changed: 249 additions & 4 deletions

File tree

contract/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ extern crate static_assertions;
44
use api::{Payout, RestrictionApi, SweatApi};
55
use event::Event;
66
use near_contract_standards::fungible_token::{events::FtBurn, FungibleToken};
7-
use near_plugins::{access_control, access_control_any, AccessControlRole, AccessControllable};
7+
use near_plugins::{access_control, access_control_any, AccessControlRole, AccessControllable, Upgradable};
8+
use near_sdk::borsh::BorshDeserialize;
89
use near_sdk::{
910
assert_one_yocto,
1011
collections::UnorderedSet,
@@ -35,11 +36,20 @@ pub enum Role {
3536
PauseManager,
3637
UnpauseManager,
3738
DenylistManager,
39+
StagingManager,
40+
UpgradeManager,
3841
}
3942

40-
#[near(contract_state)]
43+
#[derive(PanicOnDefault, Upgradable)]
4144
#[access_control(role_type(Role))]
42-
#[derive(PanicOnDefault)]
45+
#[upgradable(access_control_roles(
46+
code_stagers(Role::StagingManager),
47+
code_deployers(Role::UpgradeManager),
48+
duration_initializers(Role::UpgradeManager),
49+
duration_update_stagers(Role::UpgradeManager),
50+
duration_update_appliers(Role::UpgradeManager),
51+
))]
52+
#[near(contract_state)]
4353
pub struct Contract {
4454
token: FungibleToken,
4555
steps_since_tge: U64,

res/contract.wasm

27.2 KB
Binary file not shown.

res/contract_abi.json

Lines changed: 236 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"compiler": "rustc 1.86.0",
88
"builder": "cargo-near cargo-near-build 0.11.0"
99
},
10-
"wasm_hash": "8qN5Q5wxyzZ7ik1SkANXnPKk1AXb9MzoXDzhkD3tvXzW"
10+
"wasm_hash": "5Lnvs4LPvNJWr79C1Ry2ktd2ffrf2CvbeiCmq12wHsSH"
1111
},
1212
"body": {
1313
"functions": [
@@ -868,6 +868,7 @@
868868
},
869869
{
870870
"name": "migrate",
871+
"doc": " Migrates the contract state from the previous layout to the current one.\n\n # Panics\n\n Panics if the existing on-chain state cannot be read as [`OldContract`].",
871872
"kind": "call",
872873
"modifiers": [
873874
"init",
@@ -1253,6 +1254,169 @@
12531254
"type": "boolean"
12541255
}
12551256
}
1257+
},
1258+
{
1259+
"name": "up_apply_update_staging_duration",
1260+
"kind": "call"
1261+
},
1262+
{
1263+
"name": "up_deploy_code",
1264+
"kind": "call",
1265+
"params": {
1266+
"serialization_type": "json",
1267+
"args": [
1268+
{
1269+
"name": "hash",
1270+
"type_schema": {
1271+
"type": "string"
1272+
}
1273+
},
1274+
{
1275+
"name": "function_call_args",
1276+
"type_schema": {
1277+
"anyOf": [
1278+
{
1279+
"$ref": "#/definitions/FunctionCallArgs"
1280+
},
1281+
{
1282+
"type": "null"
1283+
}
1284+
]
1285+
}
1286+
}
1287+
]
1288+
},
1289+
"result": {
1290+
"serialization_type": "json",
1291+
"type_schema": {
1292+
"$ref": "#/definitions/Promise"
1293+
}
1294+
}
1295+
},
1296+
{
1297+
"name": "up_get_delay_status",
1298+
"kind": "view",
1299+
"result": {
1300+
"serialization_type": "json",
1301+
"type_schema": {
1302+
"$ref": "#/definitions/UpgradableDurationStatus"
1303+
}
1304+
}
1305+
},
1306+
{
1307+
"name": "up_init_staging_duration",
1308+
"kind": "call",
1309+
"params": {
1310+
"serialization_type": "json",
1311+
"args": [
1312+
{
1313+
"name": "staging_duration",
1314+
"type_schema": {
1315+
"type": "integer",
1316+
"format": "uint64",
1317+
"minimum": 0.0
1318+
}
1319+
}
1320+
]
1321+
}
1322+
},
1323+
{
1324+
"name": "up_stage_code",
1325+
"kind": "call"
1326+
},
1327+
{
1328+
"name": "up_stage_update_staging_duration",
1329+
"kind": "call",
1330+
"params": {
1331+
"serialization_type": "json",
1332+
"args": [
1333+
{
1334+
"name": "staging_duration",
1335+
"type_schema": {
1336+
"type": "integer",
1337+
"format": "uint64",
1338+
"minimum": 0.0
1339+
}
1340+
}
1341+
]
1342+
}
1343+
},
1344+
{
1345+
"name": "up_staged_code",
1346+
"kind": "view",
1347+
"result": {
1348+
"serialization_type": "borsh",
1349+
"type_schema": {
1350+
"declaration": "Option<Vec<u8>>",
1351+
"definitions": {
1352+
"()": {
1353+
"Primitive": 0
1354+
},
1355+
"Option<Vec<u8>>": {
1356+
"Enum": {
1357+
"tag_width": 1,
1358+
"variants": [
1359+
[
1360+
0,
1361+
"None",
1362+
"()"
1363+
],
1364+
[
1365+
1,
1366+
"Some",
1367+
"Vec<u8>"
1368+
]
1369+
]
1370+
}
1371+
},
1372+
"Vec<u8>": {
1373+
"Sequence": {
1374+
"length_width": 4,
1375+
"length_range": {
1376+
"start": 0,
1377+
"end": 4294967295
1378+
},
1379+
"elements": "u8"
1380+
}
1381+
},
1382+
"u8": {
1383+
"Primitive": 1
1384+
}
1385+
}
1386+
}
1387+
}
1388+
},
1389+
{
1390+
"name": "up_staged_code_hash",
1391+
"kind": "view",
1392+
"result": {
1393+
"serialization_type": "json",
1394+
"type_schema": {
1395+
"type": [
1396+
"string",
1397+
"null"
1398+
]
1399+
}
1400+
}
1401+
},
1402+
{
1403+
"name": "up_storage_prefix",
1404+
"kind": "view",
1405+
"result": {
1406+
"serialization_type": "json",
1407+
"type_schema": {
1408+
"type": "array",
1409+
"items": {
1410+
"type": "integer",
1411+
"format": "uint8",
1412+
"minimum": 0.0
1413+
}
1414+
}
1415+
}
1416+
},
1417+
{
1418+
"name": "up_verify_state",
1419+
"kind": "view"
12561420
}
12571421
],
12581422
"root_schema": {
@@ -1288,6 +1452,39 @@
12881452
}
12891453
]
12901454
},
1455+
"FunctionCallArgs": {
1456+
"description": "Specifies a function call to be appended to the actions of a promise via [`near_sdk::Promise::function_call`]).",
1457+
"type": "object",
1458+
"required": [
1459+
"amount",
1460+
"arguments",
1461+
"function_name",
1462+
"gas"
1463+
],
1464+
"properties": {
1465+
"amount": {
1466+
"description": "The amount of tokens to transfer to the receiver.",
1467+
"type": "string"
1468+
},
1469+
"arguments": {
1470+
"description": "The arguments to pass to the function.",
1471+
"type": "array",
1472+
"items": {
1473+
"type": "integer",
1474+
"format": "uint8",
1475+
"minimum": 0.0
1476+
}
1477+
},
1478+
"function_name": {
1479+
"description": "The name of the function to call.",
1480+
"type": "string"
1481+
},
1482+
"gas": {
1483+
"description": "The gas limit for the function call.",
1484+
"type": "string"
1485+
}
1486+
}
1487+
},
12911488
"FungibleTokenMetadata": {
12921489
"type": "object",
12931490
"required": [
@@ -1386,6 +1583,7 @@
13861583
}
13871584
}
13881585
},
1586+
"Promise": true,
13891587
"PromiseOrValueNull": {
13901588
"type": "null"
13911589
},
@@ -1423,6 +1621,43 @@
14231621
"type": "string"
14241622
}
14251623
}
1624+
},
1625+
"UpgradableDurationStatus": {
1626+
"type": "object",
1627+
"properties": {
1628+
"new_staging_duration": {
1629+
"type": [
1630+
"integer",
1631+
"null"
1632+
],
1633+
"format": "uint64",
1634+
"minimum": 0.0
1635+
},
1636+
"new_staging_duration_timestamp": {
1637+
"type": [
1638+
"integer",
1639+
"null"
1640+
],
1641+
"format": "uint64",
1642+
"minimum": 0.0
1643+
},
1644+
"staging_duration": {
1645+
"type": [
1646+
"integer",
1647+
"null"
1648+
],
1649+
"format": "uint64",
1650+
"minimum": 0.0
1651+
},
1652+
"staging_timestamp": {
1653+
"type": [
1654+
"integer",
1655+
"null"
1656+
],
1657+
"format": "uint64",
1658+
"minimum": 0.0
1659+
}
1660+
}
14261661
}
14271662
}
14281663
}

res/contract_abi.zst

601 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)