@aptos-labs/ts-sdk 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/{account-CEmLe1wW.d.ts → account-Bb5REyaT.d.ts} +60 -11
- package/dist/common/chunk-6MMUUJHX.js +4 -0
- package/dist/common/chunk-6MMUUJHX.js.map +1 -0
- package/dist/common/cli/index.d.ts +1 -1
- package/dist/common/cli/index.js +1 -1
- package/dist/common/cli/index.js.map +1 -1
- package/dist/common/index.d.ts +121 -9
- package/dist/common/index.js +53 -32
- package/dist/common/index.js.map +1 -1
- package/dist/esm/{Ed25519Account-Ccxj1zdx.d.mts → Ed25519Account-ndmdpFe9.d.mts} +1 -1
- package/dist/esm/account/AbstractKeylessAccount.d.mts +3 -3
- package/dist/esm/account/AbstractKeylessAccount.mjs +1 -1
- package/dist/esm/account/AbstractedAccount.d.mts +2 -2
- package/dist/esm/account/AbstractedAccount.mjs +1 -1
- package/dist/esm/account/Account.d.mts +2 -2
- package/dist/esm/account/Account.mjs +1 -1
- package/dist/esm/account/AccountUtils.d.mts +3 -3
- package/dist/esm/account/AccountUtils.mjs +1 -1
- package/dist/esm/account/DerivableAbstractedAccount.d.mts +2 -2
- package/dist/esm/account/DerivableAbstractedAccount.mjs +1 -1
- package/dist/esm/account/Ed25519Account.d.mts +2 -2
- package/dist/esm/account/Ed25519Account.mjs +1 -1
- package/dist/esm/account/EphemeralKeyPair.d.mts +1 -1
- package/dist/esm/account/EphemeralKeyPair.mjs +1 -1
- package/dist/esm/account/FederatedKeylessAccount.d.mts +4 -3
- package/dist/esm/account/FederatedKeylessAccount.mjs +1 -1
- package/dist/esm/account/KeylessAccount.d.mts +4 -3
- package/dist/esm/account/KeylessAccount.mjs +1 -1
- package/dist/esm/account/MultiEd25519Account.d.mts +2 -2
- package/dist/esm/account/MultiEd25519Account.mjs +1 -1
- package/dist/esm/account/MultiKeyAccount.d.mts +3 -3
- package/dist/esm/account/MultiKeyAccount.mjs +1 -1
- package/dist/esm/account/SingleKeyAccount.d.mts +2 -2
- package/dist/esm/account/SingleKeyAccount.mjs +1 -1
- package/dist/esm/account/index.d.mts +3 -3
- package/dist/esm/account/index.mjs +1 -1
- package/dist/esm/account/utils.d.mts +1 -1
- package/dist/esm/account/utils.mjs +1 -1
- package/dist/esm/{account-9G6tix5T.d.mts → account--Q9z_xMN.d.mts} +37 -3
- package/dist/esm/api/account/abstraction.d.mts +1 -1
- package/dist/esm/api/account/abstraction.mjs +1 -1
- package/dist/esm/api/account.d.mts +94 -3
- package/dist/esm/api/account.mjs +1 -1
- package/dist/esm/api/ans.d.mts +2 -2
- package/dist/esm/api/ans.mjs +1 -1
- package/dist/esm/api/aptos.d.mts +6 -4
- package/dist/esm/api/aptos.mjs +1 -1
- package/dist/esm/api/aptosConfig.d.mts +1 -1
- package/dist/esm/api/aptosConfig.mjs +1 -1
- package/dist/esm/api/coin.d.mts +1 -1
- package/dist/esm/api/coin.mjs +1 -1
- package/dist/esm/api/digitalAsset.d.mts +2 -2
- package/dist/esm/api/digitalAsset.mjs +1 -1
- package/dist/esm/api/event.d.mts +1 -1
- package/dist/esm/api/event.mjs +1 -1
- package/dist/esm/api/faucet.d.mts +1 -1
- package/dist/esm/api/faucet.mjs +1 -1
- package/dist/esm/api/fungibleAsset.d.mts +2 -2
- package/dist/esm/api/fungibleAsset.mjs +1 -1
- package/dist/esm/api/general.d.mts +1 -1
- package/dist/esm/api/general.mjs +1 -1
- package/dist/esm/api/index.d.mts +6 -4
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/keyless.d.mts +3 -3
- package/dist/esm/api/keyless.mjs +1 -1
- package/dist/esm/api/object.d.mts +1 -1
- package/dist/esm/api/object.mjs +1 -1
- package/dist/esm/api/staking.d.mts +1 -1
- package/dist/esm/api/staking.mjs +1 -1
- package/dist/esm/api/table.d.mts +1 -1
- package/dist/esm/api/table.mjs +1 -1
- package/dist/esm/api/transaction.d.mts +3 -2
- package/dist/esm/api/transaction.mjs +1 -1
- package/dist/esm/api/transactionSubmission/build.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/build.mjs +1 -1
- package/dist/esm/api/transactionSubmission/management.d.mts +2 -2
- package/dist/esm/api/transactionSubmission/management.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.d.mts +2 -2
- package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
- package/dist/esm/api/transactionSubmission/simulate.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
- package/dist/esm/api/transactionSubmission/submit.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
- package/dist/esm/api/utils.d.mts +1 -1
- package/dist/esm/api/utils.mjs +1 -1
- package/dist/esm/bcs/consts.d.mts +1 -1
- package/dist/esm/bcs/deserializer.d.mts +1 -1
- package/dist/esm/bcs/index.d.mts +1 -1
- package/dist/esm/bcs/index.mjs +1 -1
- package/dist/esm/bcs/serializable/entryFunctionBytes.d.mts +1 -1
- package/dist/esm/bcs/serializable/fixedBytes.d.mts +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.d.mts +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
- package/dist/esm/bcs/serializable/moveStructs.d.mts +1 -1
- package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
- package/dist/esm/bcs/serializer.d.mts +1 -1
- package/dist/esm/{chunk-Q4W3WJ2U.mjs → chunk-2BOHKN33.mjs} +2 -2
- package/dist/esm/{chunk-SAMHWS73.mjs → chunk-4COLMDT3.mjs} +2 -2
- package/dist/esm/chunk-5HXLZHDW.mjs +1 -0
- package/dist/esm/chunk-5HXLZHDW.mjs.map +1 -0
- package/dist/esm/{chunk-5ZRPV4YI.mjs → chunk-5URUYE6H.mjs} +2 -2
- package/dist/esm/chunk-ACNHLCQQ.mjs +6 -0
- package/dist/esm/chunk-ACNHLCQQ.mjs.map +1 -0
- package/dist/esm/{chunk-2XQKGWHQ.mjs → chunk-FYYEPFML.mjs} +2 -2
- package/dist/esm/chunk-HUWKPKPQ.mjs +2 -0
- package/dist/esm/{chunk-HMUIOIBG.mjs.map → chunk-HUWKPKPQ.mjs.map} +1 -1
- package/dist/esm/chunk-IJE2LVZG.mjs +2 -0
- package/dist/esm/chunk-IJE2LVZG.mjs.map +1 -0
- package/dist/esm/chunk-JCFTAG5Z.mjs +2 -0
- package/dist/esm/{chunk-RJ7F4JDV.mjs.map → chunk-JCFTAG5Z.mjs.map} +1 -1
- package/dist/esm/{chunk-YHGGNYYL.mjs → chunk-MML57K5H.mjs} +2 -2
- package/dist/esm/{chunk-PFXXFUBL.mjs → chunk-MNDTFHDB.mjs} +2 -2
- package/dist/esm/{chunk-FSP4QM2T.mjs → chunk-SLWIGOQL.mjs} +2 -2
- package/dist/esm/{chunk-7T62PEFI.mjs → chunk-TYYVB2A6.mjs} +2 -2
- package/dist/esm/{chunk-WOTQ7227.mjs → chunk-U3GMNXO4.mjs} +2 -2
- package/dist/esm/{chunk-VHNX2NUR.mjs → chunk-UL777LTI.mjs} +47 -26
- package/dist/esm/chunk-UL777LTI.mjs.map +1 -0
- package/dist/esm/{chunk-IDHVW7HS.mjs → chunk-XZ75T7Q7.mjs} +2 -2
- package/dist/esm/{chunk-UIVX6WSC.mjs → chunk-Y7ZQTLH4.mjs} +2 -2
- package/dist/esm/{chunk-R7NQJWDG.mjs → chunk-Z5URUE4U.mjs} +2 -2
- package/dist/esm/cli/index.d.mts +1 -1
- package/dist/esm/cli/index.mjs +1 -1
- package/dist/esm/cli/localNode.mjs +1 -1
- package/dist/esm/cli/move.d.mts +1 -1
- package/dist/esm/client/core.d.mts +1 -1
- package/dist/esm/client/core.mjs +1 -1
- package/dist/esm/client/get.d.mts +1 -1
- package/dist/esm/client/get.mjs +1 -1
- package/dist/esm/client/index.d.mts +1 -1
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/client/post.d.mts +1 -1
- package/dist/esm/client/post.mjs +1 -1
- package/dist/esm/core/account/index.d.mts +1 -1
- package/dist/esm/core/account/index.mjs +1 -1
- package/dist/esm/core/account/utils/address.d.mts +1 -1
- package/dist/esm/core/account/utils/address.mjs +1 -1
- package/dist/esm/core/account/utils/index.d.mts +1 -1
- package/dist/esm/core/account/utils/index.mjs +1 -1
- package/dist/esm/core/accountAddress.d.mts +1 -1
- package/dist/esm/core/accountAddress.mjs +1 -1
- package/dist/esm/core/authenticationKey.d.mts +1 -1
- package/dist/esm/core/authenticationKey.mjs +1 -1
- package/dist/esm/core/crypto/abstraction.d.mts +1 -1
- package/dist/esm/core/crypto/abstraction.mjs +1 -1
- package/dist/esm/core/crypto/deserializationUtils.d.mts +1 -1
- package/dist/esm/core/crypto/deserializationUtils.mjs +1 -1
- package/dist/esm/core/crypto/ed25519.d.mts +1 -1
- package/dist/esm/core/crypto/ed25519.mjs +1 -1
- package/dist/esm/core/crypto/ephemeral.d.mts +1 -1
- package/dist/esm/core/crypto/ephemeral.mjs +1 -1
- package/dist/esm/core/crypto/federatedKeyless.d.mts +2 -2
- package/dist/esm/core/crypto/federatedKeyless.mjs +1 -1
- package/dist/esm/core/crypto/index.d.mts +3 -2
- package/dist/esm/core/crypto/index.mjs +1 -1
- package/dist/esm/core/crypto/keyless.d.mts +2 -2
- package/dist/esm/core/crypto/keyless.mjs +1 -1
- package/dist/esm/core/crypto/multiEd25519.d.mts +1 -1
- package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
- package/dist/esm/core/crypto/multiKey.d.mts +1 -1
- package/dist/esm/core/crypto/multiKey.mjs +1 -1
- package/dist/esm/core/crypto/privateKey.d.mts +1 -1
- package/dist/esm/core/crypto/privateKey.mjs +1 -1
- package/dist/esm/core/crypto/proof.d.mts +1 -1
- package/dist/esm/core/crypto/proof.mjs +1 -1
- package/dist/esm/core/crypto/publicKey.d.mts +1 -1
- package/dist/esm/core/crypto/publicKey.mjs +1 -1
- package/dist/esm/core/crypto/secp256k1.d.mts +1 -1
- package/dist/esm/core/crypto/secp256k1.mjs +1 -1
- package/dist/esm/core/crypto/signature.d.mts +1 -1
- package/dist/esm/core/crypto/signature.mjs +1 -1
- package/dist/esm/core/crypto/singleKey.d.mts +1 -1
- package/dist/esm/core/crypto/singleKey.mjs +1 -1
- package/dist/esm/core/crypto/types.d.mts +11 -0
- package/dist/esm/core/crypto/types.mjs +2 -0
- package/dist/esm/core/crypto/types.mjs.map +1 -0
- package/dist/esm/core/crypto/utils.d.mts +1 -1
- package/dist/esm/core/hex.d.mts +1 -1
- package/dist/esm/core/index.d.mts +3 -2
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/errors/index.d.mts +1 -1
- package/dist/esm/errors/index.mjs +1 -1
- package/dist/esm/{federatedKeyless-CVKW5pnz.d.mts → federatedKeyless-CiyplsOB.d.mts} +1 -1
- package/dist/esm/index.d.mts +6 -4
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/abstraction.d.mts +1 -1
- package/dist/esm/internal/abstraction.mjs +1 -1
- package/dist/esm/internal/account.d.mts +38 -8
- package/dist/esm/internal/account.mjs +1 -1
- package/dist/esm/internal/ans.d.mts +2 -2
- package/dist/esm/internal/ans.mjs +1 -1
- package/dist/esm/internal/coin.d.mts +1 -1
- package/dist/esm/internal/coin.mjs +1 -1
- package/dist/esm/internal/digitalAsset.d.mts +2 -2
- package/dist/esm/internal/digitalAsset.mjs +1 -1
- package/dist/esm/internal/event.d.mts +1 -1
- package/dist/esm/internal/event.mjs +1 -1
- package/dist/esm/internal/faucet.d.mts +1 -1
- package/dist/esm/internal/faucet.mjs +1 -1
- package/dist/esm/internal/fungibleAsset.d.mts +2 -2
- package/dist/esm/internal/fungibleAsset.mjs +1 -1
- package/dist/esm/internal/general.d.mts +1 -1
- package/dist/esm/internal/general.mjs +1 -1
- package/dist/esm/internal/keyless.d.mts +12 -3
- package/dist/esm/internal/keyless.mjs +1 -1
- package/dist/esm/internal/object.d.mts +1 -1
- package/dist/esm/internal/object.mjs +1 -1
- package/dist/esm/internal/staking.d.mts +1 -1
- package/dist/esm/internal/staking.mjs +1 -1
- package/dist/esm/internal/table.d.mts +1 -1
- package/dist/esm/internal/table.mjs +1 -1
- package/dist/esm/internal/transaction.d.mts +1 -1
- package/dist/esm/internal/transaction.mjs +1 -1
- package/dist/esm/internal/transactionSubmission.d.mts +2 -2
- package/dist/esm/internal/transactionSubmission.mjs +1 -1
- package/dist/esm/internal/utils/index.d.mts +1 -1
- package/dist/esm/internal/utils/index.mjs +1 -1
- package/dist/esm/internal/utils/utils.d.mts +1 -1
- package/dist/esm/internal/utils/utils.mjs +1 -1
- package/dist/esm/internal/view.d.mts +1 -1
- package/dist/esm/internal/view.mjs +1 -1
- package/dist/esm/transactions/authenticator/account.d.mts +1 -1
- package/dist/esm/transactions/authenticator/account.mjs +1 -1
- package/dist/esm/transactions/authenticator/index.d.mts +1 -1
- package/dist/esm/transactions/authenticator/index.mjs +1 -1
- package/dist/esm/transactions/authenticator/transaction.d.mts +1 -1
- package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
- package/dist/esm/transactions/index.d.mts +1 -1
- package/dist/esm/transactions/index.mjs +1 -1
- package/dist/esm/transactions/instances/chainId.d.mts +1 -1
- package/dist/esm/transactions/instances/identifier.d.mts +1 -1
- package/dist/esm/transactions/instances/index.d.mts +1 -1
- package/dist/esm/transactions/instances/index.mjs +1 -1
- package/dist/esm/transactions/instances/moduleId.d.mts +1 -1
- package/dist/esm/transactions/instances/moduleId.mjs +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rawTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
- package/dist/esm/transactions/instances/signedTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/transactionArgument.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.d.mts +2 -2
- package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
- package/dist/esm/transactions/management/index.d.mts +2 -2
- package/dist/esm/transactions/management/index.mjs +1 -1
- package/dist/esm/transactions/management/transactionWorker.d.mts +2 -2
- package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/index.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
- package/dist/esm/transactions/typeTag/index.d.mts +1 -1
- package/dist/esm/transactions/typeTag/index.mjs +1 -1
- package/dist/esm/transactions/typeTag/parser.d.mts +1 -1
- package/dist/esm/transactions/typeTag/parser.mjs +1 -1
- package/dist/esm/transactions/types.d.mts +1 -1
- package/dist/esm/types/generated/operations.d.mts +37 -10
- package/dist/esm/types/generated/queries.d.mts +6 -2
- package/dist/esm/types/generated/queries.mjs +1 -1
- package/dist/esm/types/generated/types.d.mts +584 -1172
- package/dist/esm/types/generated/types.mjs +1 -1
- package/dist/esm/types/generated/types.mjs.map +1 -1
- package/dist/esm/types/index.d.mts +2 -2
- package/dist/esm/types/index.mjs +1 -1
- package/dist/esm/types/indexer.d.mts +8 -2
- package/dist/esm/types/types.d.mts +1 -1
- package/dist/esm/types/types.mjs +1 -1
- package/dist/esm/utils/const.d.mts +1 -0
- package/dist/esm/utils/const.mjs +1 -1
- package/dist/esm/utils/helpers.d.mts +1 -1
- package/dist/esm/utils/helpers.mjs +1 -1
- package/dist/esm/utils/index.d.mts +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/utils/normalizeBundle.d.mts +1 -1
- package/dist/esm/utils/normalizeBundle.mjs +1 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +19 -18
- package/src/account/FederatedKeylessAccount.ts +7 -1
- package/src/account/KeylessAccount.ts +17 -2
- package/src/api/account.ts +135 -2
- package/src/api/transaction.ts +1 -0
- package/src/core/crypto/index.ts +1 -0
- package/src/core/crypto/multiEd25519.ts +26 -0
- package/src/core/crypto/multiKey.ts +6 -0
- package/src/core/crypto/types.ts +9 -0
- package/src/internal/account.ts +526 -59
- package/src/internal/keyless.ts +10 -0
- package/src/internal/move/jwks/build/jwk/BuildInfo.yaml +56 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/account.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aggregator.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aggregator_factory.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aggregator_v2.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aptos_account.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aptos_coin.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/aptos_governance.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/block.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/chain_id.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/chain_status.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/code.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/coin.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/config_buffer.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/consensus_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/create_signer.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/delegation_pool.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/dispatchable_fungible_asset.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/dkg.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/event.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/execution_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/function_info.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/fungible_asset.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/gas_schedule.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/genesis.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/governance_proposal.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/guid.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/jwk_consensus_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/jwks.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/keyless_account.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/managed_coin.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/multisig_account.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/object.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/object_code_deployment.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/optional_aggregator.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/primary_fungible_store.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/randomness.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/randomness_api_v0_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/randomness_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/randomness_config_seqnum.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/reconfiguration.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/reconfiguration_state.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/reconfiguration_with_dkg.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/resource_account.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/stake.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/staking_config.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/staking_contract.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/staking_proxy.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/state_storage.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/storage_gas.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/system_addresses.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/timestamp.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/transaction_context.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/transaction_fee.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/transaction_validation.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/util.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/validator_consensus_info.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/version.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/vesting.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosFramework/voting.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/any.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/aptos_hash.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/big_vector.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/bls12381.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/bls12381_algebra.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/bn254_algebra.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/capability.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/comparator.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/copyable_any.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/crypto_algebra.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/debug.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/ed25519.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/fixed_point64.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/from_bcs.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/math128.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/math64.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/math_fixed.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/math_fixed64.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/multi_ed25519.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/pool_u64.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/pool_u64_unbound.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/ristretto255.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/ristretto255_bulletproofs.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/ristretto255_elgamal.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/ristretto255_pedersen.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/secp256k1.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/simple_map.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/smart_table.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/smart_vector.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/string_utils.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/table.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/table_with_length.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/AptosStdlib/type_info.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/acl.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/bcs.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/bit_vector.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/error.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/features.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/fixed_point32.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/hash.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/option.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/signer.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/string.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_modules/dependencies/MoveStdlib/vector.mv +0 -0
- package/src/internal/move/jwks/build/jwk/bytecode_scripts/main.mv +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/account.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aggregator.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aggregator_factory.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aggregator_v2.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aptos_account.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aptos_coin.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/aptos_governance.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/block.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/chain_id.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/chain_status.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/code.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/coin.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/config_buffer.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/consensus_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/create_signer.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/delegation_pool.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/dispatchable_fungible_asset.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/dkg.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/event.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/execution_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/function_info.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/fungible_asset.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/gas_schedule.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/genesis.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/governance_proposal.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/guid.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/jwk_consensus_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/jwks.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/keyless_account.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/managed_coin.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/multisig_account.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/object.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/object_code_deployment.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/optional_aggregator.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/primary_fungible_store.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/randomness.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/randomness_api_v0_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/randomness_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/randomness_config_seqnum.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/reconfiguration.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/reconfiguration_state.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/reconfiguration_with_dkg.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/resource_account.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/stake.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/staking_config.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/staking_contract.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/staking_proxy.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/state_storage.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/storage_gas.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/system_addresses.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/timestamp.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/transaction_context.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/transaction_fee.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/transaction_validation.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/util.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/validator_consensus_info.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/version.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/vesting.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosFramework/voting.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/any.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/aptos_hash.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/big_vector.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/bls12381.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/bls12381_algebra.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/bn254_algebra.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/capability.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/comparator.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/copyable_any.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/crypto_algebra.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/debug.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/ed25519.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/fixed_point64.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/from_bcs.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/math128.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/math64.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/math_fixed.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/math_fixed64.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/multi_ed25519.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/pool_u64.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/pool_u64_unbound.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/ristretto255.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/ristretto255_bulletproofs.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/ristretto255_elgamal.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/ristretto255_pedersen.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/secp256k1.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/simple_map.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/smart_table.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/smart_vector.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/string_utils.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/table.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/table_with_length.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/AptosStdlib/type_info.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/acl.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/bcs.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/bit_vector.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/error.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/features.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/fixed_point32.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/hash.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/option.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/signer.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/string.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/dependencies/MoveStdlib/vector.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/source_maps/main.mvsm +0 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/account.move +1533 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aggregator.move +48 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aggregator_factory.move +66 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aggregator_v2.move +280 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aptos_account.move +443 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aptos_coin.move +204 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/aptos_governance.move +1387 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/block.move +394 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/chain_id.move +41 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/chain_status.move +48 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/code.move +367 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/coin.move +2214 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/config_buffer.move +101 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/consensus_config.move +77 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/create_signer.move +21 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/delegation_pool.move +5568 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/dispatchable_fungible_asset.move +228 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/dkg.move +121 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/event.move +92 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/execution_config.move +66 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/function_info.move +100 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/fungible_asset.move +1566 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/gas_schedule.move +176 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/genesis.move +550 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/governance_proposal.move +23 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/guid.move +68 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/jwk_consensus_config.move +148 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/jwks.move +817 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/keyless_account.move +312 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/managed_coin.move +205 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/multisig_account.move +2477 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/object.move +1073 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/object_code_deployment.move +147 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/optional_aggregator.move +295 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/primary_fungible_store.move +405 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/randomness.move +574 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/randomness_api_v0_config.move +57 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/randomness_config.move +153 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/randomness_config_seqnum.move +49 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/reconfiguration.move +237 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/reconfiguration_state.move +132 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/reconfiguration_with_dkg.move +69 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/resource_account.move +267 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/stake.move +3286 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/staking_config.move +686 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/staking_contract.move +1618 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/staking_proxy.move +228 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/state_storage.move +90 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/storage_gas.move +622 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/system_addresses.move +82 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/timestamp.move +88 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/transaction_context.move +262 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/transaction_fee.move +457 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/transaction_validation.move +501 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/util.move +16 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/validator_consensus_info.move +42 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/version.move +115 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/vesting.move +2183 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/voting.move +1279 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/any.move +57 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/aptos_hash.move +253 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/big_vector.move +469 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/bls12381.move +985 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/bls12381_algebra.move +802 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/bn254_algebra.move +855 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/capability.move +193 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/comparator.move +173 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/copyable_any.move +45 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/crypto_algebra.move +351 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/debug.move +278 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/ed25519.move +262 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/fixed_point64.move +447 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/from_bcs.move +91 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/math128.move +381 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/math64.move +336 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/math_fixed.move +139 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/math_fixed64.move +142 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/multi_ed25519.move +482 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/pool_u64.move +571 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/pool_u64_unbound.move +270 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/ristretto255.move +1310 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/ristretto255_bulletproofs.move +253 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/ristretto255_elgamal.move +234 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/ristretto255_pedersen.move +158 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/secp256k1.move +114 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/simple_map.move +319 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/smart_table.move +769 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/smart_vector.move +766 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/string_utils.move +148 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/table.move +152 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/table_with_length.move +141 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosStdlib/type_info.move +351 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/acl.move +46 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/bcs.move +27 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/bit_vector.move +239 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/error.move +88 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/features.move +780 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/fixed_point32.move +295 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/hash.move +8 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/option.move +356 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/signer.move +21 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/string.move +93 -0
- package/src/internal/move/jwks/build/jwk/sources/dependencies/MoveStdlib/vector.move +669 -0
- package/src/internal/move/jwks/build/jwk/sources/main.move +20 -0
- package/src/internal/queries/getAccountAddressesForAuthKey.graphql +8 -0
- package/src/internal/queries/getAuthKeysForPublicKey.graphql +11 -0
- package/src/types/codegen.yaml +1 -1
- package/src/types/generated/operations.ts +39 -8
- package/src/types/generated/queries.ts +53 -0
- package/src/types/generated/types.ts +620 -1239
- package/src/types/indexer.ts +8 -0
- package/src/types/types.ts +40 -3
- package/src/utils/const.ts +1 -0
- package/src/version.ts +1 -1
- package/dist/common/chunk-5JIJXVJ5.js +0 -4
- package/dist/common/chunk-5JIJXVJ5.js.map +0 -1
- package/dist/esm/chunk-4H2RMR7D.mjs +0 -2
- package/dist/esm/chunk-4H2RMR7D.mjs.map +0 -1
- package/dist/esm/chunk-GMDBBVDH.mjs +0 -6
- package/dist/esm/chunk-GMDBBVDH.mjs.map +0 -1
- package/dist/esm/chunk-HMUIOIBG.mjs +0 -2
- package/dist/esm/chunk-RJ7F4JDV.mjs +0 -2
- package/dist/esm/chunk-VHNX2NUR.mjs.map +0 -1
- /package/dist/esm/{chunk-Q4W3WJ2U.mjs.map → chunk-2BOHKN33.mjs.map} +0 -0
- /package/dist/esm/{chunk-SAMHWS73.mjs.map → chunk-4COLMDT3.mjs.map} +0 -0
- /package/dist/esm/{chunk-5ZRPV4YI.mjs.map → chunk-5URUYE6H.mjs.map} +0 -0
- /package/dist/esm/{chunk-2XQKGWHQ.mjs.map → chunk-FYYEPFML.mjs.map} +0 -0
- /package/dist/esm/{chunk-YHGGNYYL.mjs.map → chunk-MML57K5H.mjs.map} +0 -0
- /package/dist/esm/{chunk-PFXXFUBL.mjs.map → chunk-MNDTFHDB.mjs.map} +0 -0
- /package/dist/esm/{chunk-FSP4QM2T.mjs.map → chunk-SLWIGOQL.mjs.map} +0 -0
- /package/dist/esm/{chunk-7T62PEFI.mjs.map → chunk-TYYVB2A6.mjs.map} +0 -0
- /package/dist/esm/{chunk-WOTQ7227.mjs.map → chunk-U3GMNXO4.mjs.map} +0 -0
- /package/dist/esm/{chunk-IDHVW7HS.mjs.map → chunk-XZ75T7Q7.mjs.map} +0 -0
- /package/dist/esm/{chunk-UIVX6WSC.mjs.map → chunk-Y7ZQTLH4.mjs.map} +0 -0
- /package/dist/esm/{chunk-R7NQJWDG.mjs.map → chunk-Z5URUE4U.mjs.map} +0 -0
package/src/internal/move/jwks/build/jwk/sources/dependencies/AptosFramework/staking_contract.move
ADDED
|
@@ -0,0 +1,1618 @@
|
|
|
1
|
+
/// Allow stakers and operators to enter a staking contract with reward sharing.
|
|
2
|
+
/// The main accounting logic in a staking contract consists of 2 parts:
|
|
3
|
+
/// 1. Tracks how much commission needs to be paid out to the operator. This is tracked with an increasing principal
|
|
4
|
+
/// amount that's updated every time the operator requests commission, the staker withdraws funds, or the staker
|
|
5
|
+
/// switches operators.
|
|
6
|
+
/// 2. Distributions of funds to operators (commissions) and stakers (stake withdrawals) use the shares model provided
|
|
7
|
+
/// by the pool_u64 to track shares that increase in price as the stake pool accumulates rewards.
|
|
8
|
+
///
|
|
9
|
+
/// Example flow:
|
|
10
|
+
/// 1. A staker creates a staking contract with an operator by calling create_staking_contract() with 100 coins of
|
|
11
|
+
/// initial stake and commission = 10%. This means the operator will receive 10% of any accumulated rewards. A new stake
|
|
12
|
+
/// pool will be created and hosted in a separate account that's controlled by the staking contract.
|
|
13
|
+
/// 2. The operator sets up a validator node and, once ready, joins the validator set by calling stake::join_validator_set
|
|
14
|
+
/// 3. After some time, the stake pool gains rewards and now has 150 coins.
|
|
15
|
+
/// 4. Operator can now call request_commission. 10% of (150 - 100) = 5 coins will be unlocked from the stake pool. The
|
|
16
|
+
/// staker's principal is now updated from 100 to 145 (150 coins - 5 coins of commission). The pending distribution pool
|
|
17
|
+
/// has 5 coins total and the operator owns all 5 shares of it.
|
|
18
|
+
/// 5. Some more time has passed. The pool now has 50 more coins in rewards and a total balance of 195. The operator
|
|
19
|
+
/// calls request_commission again. Since the previous 5 coins have now become withdrawable, it'll be deposited into the
|
|
20
|
+
/// operator's account first. Their new commission will be 10% of (195 coins - 145 principal) = 5 coins. Principal is
|
|
21
|
+
/// updated to be 190 (195 - 5). Pending distribution pool has 5 coins and operator owns all 5 shares.
|
|
22
|
+
/// 6. Staker calls unlock_stake to unlock 50 coins of stake, which gets added to the pending distribution pool. Based
|
|
23
|
+
/// on shares math, staker will be owning 50 shares and operator still owns 5 shares of the 55-coin pending distribution
|
|
24
|
+
/// pool.
|
|
25
|
+
/// 7. Some time passes and the 55 coins become fully withdrawable from the stake pool. Due to accumulated rewards, the
|
|
26
|
+
/// 55 coins become 70 coins. Calling distribute() distributes 6 coins to the operator and 64 coins to the validator.
|
|
27
|
+
module aptos_framework::staking_contract {
|
|
28
|
+
use std::bcs;
|
|
29
|
+
use std::error;
|
|
30
|
+
use std::features;
|
|
31
|
+
use std::signer;
|
|
32
|
+
use std::vector;
|
|
33
|
+
|
|
34
|
+
use aptos_std::pool_u64::{Self, Pool};
|
|
35
|
+
use aptos_std::simple_map::{Self, SimpleMap};
|
|
36
|
+
|
|
37
|
+
use aptos_framework::account::{Self, SignerCapability};
|
|
38
|
+
use aptos_framework::aptos_account;
|
|
39
|
+
use aptos_framework::aptos_coin::AptosCoin;
|
|
40
|
+
use aptos_framework::coin::{Self, Coin};
|
|
41
|
+
use aptos_framework::event::{EventHandle, emit, emit_event};
|
|
42
|
+
use aptos_framework::stake::{Self, OwnerCapability};
|
|
43
|
+
use aptos_framework::staking_config;
|
|
44
|
+
|
|
45
|
+
const SALT: vector<u8> = b"aptos_framework::staking_contract";
|
|
46
|
+
|
|
47
|
+
/// Store amount must be at least the min stake required for a stake pool to join the validator set.
|
|
48
|
+
const EINSUFFICIENT_STAKE_AMOUNT: u64 = 1;
|
|
49
|
+
/// Commission percentage has to be between 0 and 100.
|
|
50
|
+
const EINVALID_COMMISSION_PERCENTAGE: u64 = 2;
|
|
51
|
+
/// Staker has no staking contracts.
|
|
52
|
+
const ENO_STAKING_CONTRACT_FOUND_FOR_STAKER: u64 = 3;
|
|
53
|
+
/// No staking contract between the staker and operator found.
|
|
54
|
+
const ENO_STAKING_CONTRACT_FOUND_FOR_OPERATOR: u64 = 4;
|
|
55
|
+
/// Staking contracts can't be merged.
|
|
56
|
+
const ECANT_MERGE_STAKING_CONTRACTS: u64 = 5;
|
|
57
|
+
/// The staking contract already exists and cannot be re-created.
|
|
58
|
+
const ESTAKING_CONTRACT_ALREADY_EXISTS: u64 = 6;
|
|
59
|
+
/// Not enough active stake to withdraw. Some stake might still pending and will be active in the next epoch.
|
|
60
|
+
const EINSUFFICIENT_ACTIVE_STAKE_TO_WITHDRAW: u64 = 7;
|
|
61
|
+
/// Caller must be either the staker, operator, or beneficiary.
|
|
62
|
+
const ENOT_STAKER_OR_OPERATOR_OR_BENEFICIARY: u64 = 8;
|
|
63
|
+
/// Changing beneficiaries for operators is not supported.
|
|
64
|
+
const EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED: u64 = 9;
|
|
65
|
+
|
|
66
|
+
/// Maximum number of distributions a stake pool can support.
|
|
67
|
+
const MAXIMUM_PENDING_DISTRIBUTIONS: u64 = 20;
|
|
68
|
+
|
|
69
|
+
#[resource_group(scope = module_)]
|
|
70
|
+
struct StakingGroupContainer {}
|
|
71
|
+
|
|
72
|
+
struct StakingContract has store {
|
|
73
|
+
// Recorded principal after the last commission distribution.
|
|
74
|
+
// This is only used to calculate the commission the operator should be receiving.
|
|
75
|
+
principal: u64,
|
|
76
|
+
pool_address: address,
|
|
77
|
+
// The stake pool's owner capability. This can be used to control funds in the stake pool.
|
|
78
|
+
owner_cap: OwnerCapability,
|
|
79
|
+
commission_percentage: u64,
|
|
80
|
+
// Current distributions, including operator commission withdrawals and staker's partial withdrawals.
|
|
81
|
+
distribution_pool: Pool,
|
|
82
|
+
// Just in case we need the SignerCap for stake pool account in the future.
|
|
83
|
+
signer_cap: SignerCapability,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
struct Store has key {
|
|
87
|
+
staking_contracts: SimpleMap<address, StakingContract>,
|
|
88
|
+
|
|
89
|
+
// Events.
|
|
90
|
+
create_staking_contract_events: EventHandle<CreateStakingContractEvent>,
|
|
91
|
+
update_voter_events: EventHandle<UpdateVoterEvent>,
|
|
92
|
+
reset_lockup_events: EventHandle<ResetLockupEvent>,
|
|
93
|
+
add_stake_events: EventHandle<AddStakeEvent>,
|
|
94
|
+
request_commission_events: EventHandle<RequestCommissionEvent>,
|
|
95
|
+
unlock_stake_events: EventHandle<UnlockStakeEvent>,
|
|
96
|
+
switch_operator_events: EventHandle<SwitchOperatorEvent>,
|
|
97
|
+
add_distribution_events: EventHandle<AddDistributionEvent>,
|
|
98
|
+
distribute_events: EventHandle<DistributeEvent>,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
struct BeneficiaryForOperator has key {
|
|
102
|
+
beneficiary_for_operator: address,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
struct UpdateCommissionEvent has drop, store {
|
|
106
|
+
staker: address,
|
|
107
|
+
operator: address,
|
|
108
|
+
old_commission_percentage: u64,
|
|
109
|
+
new_commission_percentage: u64,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#[event]
|
|
113
|
+
struct UpdateCommission has drop, store {
|
|
114
|
+
staker: address,
|
|
115
|
+
operator: address,
|
|
116
|
+
old_commission_percentage: u64,
|
|
117
|
+
new_commission_percentage: u64,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#[resource_group_member(group = aptos_framework::staking_contract::StakingGroupContainer)]
|
|
121
|
+
struct StakingGroupUpdateCommissionEvent has key {
|
|
122
|
+
update_commission_events: EventHandle<UpdateCommissionEvent>,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#[event]
|
|
126
|
+
struct CreateStakingContract has drop, store {
|
|
127
|
+
operator: address,
|
|
128
|
+
voter: address,
|
|
129
|
+
pool_address: address,
|
|
130
|
+
principal: u64,
|
|
131
|
+
commission_percentage: u64,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[event]
|
|
135
|
+
struct UpdateVoter has drop, store {
|
|
136
|
+
operator: address,
|
|
137
|
+
pool_address: address,
|
|
138
|
+
old_voter: address,
|
|
139
|
+
new_voter: address,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#[event]
|
|
143
|
+
struct ResetLockup has drop, store {
|
|
144
|
+
operator: address,
|
|
145
|
+
pool_address: address,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[event]
|
|
149
|
+
struct AddStake has drop, store {
|
|
150
|
+
operator: address,
|
|
151
|
+
pool_address: address,
|
|
152
|
+
amount: u64
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[event]
|
|
156
|
+
struct RequestCommission has drop, store {
|
|
157
|
+
operator: address,
|
|
158
|
+
pool_address: address,
|
|
159
|
+
accumulated_rewards: u64,
|
|
160
|
+
commission_amount: u64,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#[event]
|
|
164
|
+
struct UnlockStake has drop, store {
|
|
165
|
+
operator: address,
|
|
166
|
+
pool_address: address,
|
|
167
|
+
amount: u64,
|
|
168
|
+
commission_paid: u64,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#[event]
|
|
172
|
+
struct SwitchOperator has drop, store {
|
|
173
|
+
old_operator: address,
|
|
174
|
+
new_operator: address,
|
|
175
|
+
pool_address: address,
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#[event]
|
|
179
|
+
struct AddDistribution has drop, store {
|
|
180
|
+
operator: address,
|
|
181
|
+
pool_address: address,
|
|
182
|
+
amount: u64,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#[event]
|
|
186
|
+
struct Distribute has drop, store {
|
|
187
|
+
operator: address,
|
|
188
|
+
pool_address: address,
|
|
189
|
+
recipient: address,
|
|
190
|
+
amount: u64,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#[event]
|
|
194
|
+
struct SetBeneficiaryForOperator has drop, store {
|
|
195
|
+
operator: address,
|
|
196
|
+
old_beneficiary: address,
|
|
197
|
+
new_beneficiary: address,
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
struct CreateStakingContractEvent has drop, store {
|
|
201
|
+
operator: address,
|
|
202
|
+
voter: address,
|
|
203
|
+
pool_address: address,
|
|
204
|
+
principal: u64,
|
|
205
|
+
commission_percentage: u64,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
struct UpdateVoterEvent has drop, store {
|
|
209
|
+
operator: address,
|
|
210
|
+
pool_address: address,
|
|
211
|
+
old_voter: address,
|
|
212
|
+
new_voter: address,
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
struct ResetLockupEvent has drop, store {
|
|
216
|
+
operator: address,
|
|
217
|
+
pool_address: address,
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
struct AddStakeEvent has drop, store {
|
|
221
|
+
operator: address,
|
|
222
|
+
pool_address: address,
|
|
223
|
+
amount: u64
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
struct RequestCommissionEvent has drop, store {
|
|
227
|
+
operator: address,
|
|
228
|
+
pool_address: address,
|
|
229
|
+
accumulated_rewards: u64,
|
|
230
|
+
commission_amount: u64,
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
struct UnlockStakeEvent has drop, store {
|
|
234
|
+
operator: address,
|
|
235
|
+
pool_address: address,
|
|
236
|
+
amount: u64,
|
|
237
|
+
commission_paid: u64,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
struct SwitchOperatorEvent has drop, store {
|
|
241
|
+
old_operator: address,
|
|
242
|
+
new_operator: address,
|
|
243
|
+
pool_address: address,
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
struct AddDistributionEvent has drop, store {
|
|
247
|
+
operator: address,
|
|
248
|
+
pool_address: address,
|
|
249
|
+
amount: u64,
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
struct DistributeEvent has drop, store {
|
|
253
|
+
operator: address,
|
|
254
|
+
pool_address: address,
|
|
255
|
+
recipient: address,
|
|
256
|
+
amount: u64,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
#[view]
|
|
260
|
+
/// Return the address of the underlying stake pool for the staking contract between the provided staker and
|
|
261
|
+
/// operator.
|
|
262
|
+
///
|
|
263
|
+
/// This errors out the staking contract with the provided staker and operator doesn't exist.
|
|
264
|
+
public fun stake_pool_address(staker: address, operator: address): address acquires Store {
|
|
265
|
+
assert_staking_contract_exists(staker, operator);
|
|
266
|
+
let staking_contracts = &borrow_global<Store>(staker).staking_contracts;
|
|
267
|
+
simple_map::borrow(staking_contracts, &operator).pool_address
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#[view]
|
|
271
|
+
/// Return the last recorded principal (the amount that 100% belongs to the staker with commission already paid for)
|
|
272
|
+
/// for staking contract between the provided staker and operator.
|
|
273
|
+
///
|
|
274
|
+
/// This errors out the staking contract with the provided staker and operator doesn't exist.
|
|
275
|
+
public fun last_recorded_principal(staker: address, operator: address): u64 acquires Store {
|
|
276
|
+
assert_staking_contract_exists(staker, operator);
|
|
277
|
+
let staking_contracts = &borrow_global<Store>(staker).staking_contracts;
|
|
278
|
+
simple_map::borrow(staking_contracts, &operator).principal
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#[view]
|
|
282
|
+
/// Return percentage of accumulated rewards that will be paid to the operator as commission for staking contract
|
|
283
|
+
/// between the provided staker and operator.
|
|
284
|
+
///
|
|
285
|
+
/// This errors out the staking contract with the provided staker and operator doesn't exist.
|
|
286
|
+
public fun commission_percentage(staker: address, operator: address): u64 acquires Store {
|
|
287
|
+
assert_staking_contract_exists(staker, operator);
|
|
288
|
+
let staking_contracts = &borrow_global<Store>(staker).staking_contracts;
|
|
289
|
+
simple_map::borrow(staking_contracts, &operator).commission_percentage
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
#[view]
|
|
293
|
+
/// Return a tuple of three numbers:
|
|
294
|
+
/// 1. The total active stake in the underlying stake pool
|
|
295
|
+
/// 2. The total accumulated rewards that haven't had commission paid out
|
|
296
|
+
/// 3. The commission amount owned from those accumulated rewards.
|
|
297
|
+
///
|
|
298
|
+
/// This errors out the staking contract with the provided staker and operator doesn't exist.
|
|
299
|
+
public fun staking_contract_amounts(staker: address, operator: address): (u64, u64, u64) acquires Store {
|
|
300
|
+
assert_staking_contract_exists(staker, operator);
|
|
301
|
+
let staking_contracts = &borrow_global<Store>(staker).staking_contracts;
|
|
302
|
+
let staking_contract = simple_map::borrow(staking_contracts, &operator);
|
|
303
|
+
get_staking_contract_amounts_internal(staking_contract)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
#[view]
|
|
307
|
+
/// Return the number of pending distributions (e.g. commission, withdrawals from stakers).
|
|
308
|
+
///
|
|
309
|
+
/// This errors out the staking contract with the provided staker and operator doesn't exist.
|
|
310
|
+
public fun pending_distribution_counts(staker: address, operator: address): u64 acquires Store {
|
|
311
|
+
assert_staking_contract_exists(staker, operator);
|
|
312
|
+
let staking_contracts = &borrow_global<Store>(staker).staking_contracts;
|
|
313
|
+
pool_u64::shareholders_count(&simple_map::borrow(staking_contracts, &operator).distribution_pool)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#[view]
|
|
317
|
+
/// Return true if the staking contract between the provided staker and operator exists.
|
|
318
|
+
public fun staking_contract_exists(staker: address, operator: address): bool acquires Store {
|
|
319
|
+
if (!exists<Store>(staker)) {
|
|
320
|
+
return false
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
let store = borrow_global<Store>(staker);
|
|
324
|
+
simple_map::contains_key(&store.staking_contracts, &operator)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
#[view]
|
|
328
|
+
/// Return the beneficiary address of the operator.
|
|
329
|
+
public fun beneficiary_for_operator(operator: address): address acquires BeneficiaryForOperator {
|
|
330
|
+
if (exists<BeneficiaryForOperator>(operator)) {
|
|
331
|
+
return borrow_global<BeneficiaryForOperator>(operator).beneficiary_for_operator
|
|
332
|
+
} else {
|
|
333
|
+
operator
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
#[view]
|
|
338
|
+
/// Return the address of the stake pool to be created with the provided staker, operator and seed.
|
|
339
|
+
public fun get_expected_stake_pool_address(
|
|
340
|
+
staker: address,
|
|
341
|
+
operator: address,
|
|
342
|
+
contract_creation_seed: vector<u8>,
|
|
343
|
+
): address {
|
|
344
|
+
let seed = create_resource_account_seed(staker, operator, contract_creation_seed);
|
|
345
|
+
account::create_resource_address(&staker, seed)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// Staker can call this function to create a simple staking contract with a specified operator.
|
|
349
|
+
public entry fun create_staking_contract(
|
|
350
|
+
staker: &signer,
|
|
351
|
+
operator: address,
|
|
352
|
+
voter: address,
|
|
353
|
+
amount: u64,
|
|
354
|
+
commission_percentage: u64,
|
|
355
|
+
// Optional seed used when creating the staking contract account.
|
|
356
|
+
contract_creation_seed: vector<u8>,
|
|
357
|
+
) acquires Store {
|
|
358
|
+
let staked_coins = coin::withdraw<AptosCoin>(staker, amount);
|
|
359
|
+
create_staking_contract_with_coins(
|
|
360
|
+
staker, operator, voter, staked_coins, commission_percentage, contract_creation_seed);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/// Staker can call this function to create a simple staking contract with a specified operator.
|
|
364
|
+
public fun create_staking_contract_with_coins(
|
|
365
|
+
staker: &signer,
|
|
366
|
+
operator: address,
|
|
367
|
+
voter: address,
|
|
368
|
+
coins: Coin<AptosCoin>,
|
|
369
|
+
commission_percentage: u64,
|
|
370
|
+
// Optional seed used when creating the staking contract account.
|
|
371
|
+
contract_creation_seed: vector<u8>,
|
|
372
|
+
): address acquires Store {
|
|
373
|
+
assert!(
|
|
374
|
+
commission_percentage >= 0 && commission_percentage <= 100,
|
|
375
|
+
error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE),
|
|
376
|
+
);
|
|
377
|
+
// The amount should be at least the min_stake_required, so the stake pool will be eligible to join the
|
|
378
|
+
// validator set.
|
|
379
|
+
let (min_stake_required, _) = staking_config::get_required_stake(&staking_config::get());
|
|
380
|
+
let principal = coin::value(&coins);
|
|
381
|
+
assert!(principal >= min_stake_required, error::invalid_argument(EINSUFFICIENT_STAKE_AMOUNT));
|
|
382
|
+
|
|
383
|
+
// Initialize Store resource if this is the first time the staker has delegated to anyone.
|
|
384
|
+
let staker_address = signer::address_of(staker);
|
|
385
|
+
if (!exists<Store>(staker_address)) {
|
|
386
|
+
move_to(staker, new_staking_contracts_holder(staker));
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// Cannot create the staking contract if it already exists.
|
|
390
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
391
|
+
let staking_contracts = &mut store.staking_contracts;
|
|
392
|
+
assert!(
|
|
393
|
+
!simple_map::contains_key(staking_contracts, &operator),
|
|
394
|
+
error::already_exists(ESTAKING_CONTRACT_ALREADY_EXISTS)
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
// Initialize the stake pool in a new resource account. This allows the same staker to contract with multiple
|
|
398
|
+
// different operators.
|
|
399
|
+
let (stake_pool_signer, stake_pool_signer_cap, owner_cap) =
|
|
400
|
+
create_stake_pool(staker, operator, voter, contract_creation_seed);
|
|
401
|
+
|
|
402
|
+
// Add the stake to the stake pool.
|
|
403
|
+
stake::add_stake_with_cap(&owner_cap, coins);
|
|
404
|
+
|
|
405
|
+
// Create the contract record.
|
|
406
|
+
let pool_address = signer::address_of(&stake_pool_signer);
|
|
407
|
+
simple_map::add(staking_contracts, operator, StakingContract {
|
|
408
|
+
principal,
|
|
409
|
+
pool_address,
|
|
410
|
+
owner_cap,
|
|
411
|
+
commission_percentage,
|
|
412
|
+
// Make sure we don't have too many pending recipients in the distribution pool.
|
|
413
|
+
// Otherwise, a griefing attack is possible where the staker can keep switching operators and create too
|
|
414
|
+
// many pending distributions. This can lead to out-of-gas failure whenever distribute() is called.
|
|
415
|
+
distribution_pool: pool_u64::create(MAXIMUM_PENDING_DISTRIBUTIONS),
|
|
416
|
+
signer_cap: stake_pool_signer_cap,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
if (std::features::module_event_migration_enabled()) {
|
|
420
|
+
emit(CreateStakingContract { operator, voter, pool_address, principal, commission_percentage });
|
|
421
|
+
};
|
|
422
|
+
emit_event(
|
|
423
|
+
&mut store.create_staking_contract_events,
|
|
424
|
+
CreateStakingContractEvent { operator, voter, pool_address, principal, commission_percentage },
|
|
425
|
+
);
|
|
426
|
+
pool_address
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/// Add more stake to an existing staking contract.
|
|
430
|
+
public entry fun add_stake(staker: &signer, operator: address, amount: u64) acquires Store {
|
|
431
|
+
let staker_address = signer::address_of(staker);
|
|
432
|
+
assert_staking_contract_exists(staker_address, operator);
|
|
433
|
+
|
|
434
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
435
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
436
|
+
|
|
437
|
+
// Add the stake to the stake pool.
|
|
438
|
+
let staked_coins = coin::withdraw<AptosCoin>(staker, amount);
|
|
439
|
+
stake::add_stake_with_cap(&staking_contract.owner_cap, staked_coins);
|
|
440
|
+
|
|
441
|
+
staking_contract.principal = staking_contract.principal + amount;
|
|
442
|
+
let pool_address = staking_contract.pool_address;
|
|
443
|
+
if (std::features::module_event_migration_enabled()) {
|
|
444
|
+
emit(AddStake { operator, pool_address, amount });
|
|
445
|
+
};
|
|
446
|
+
emit_event(
|
|
447
|
+
&mut store.add_stake_events,
|
|
448
|
+
AddStakeEvent { operator, pool_address, amount },
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/// Convenient function to allow the staker to update the voter address in a staking contract they made.
|
|
453
|
+
public entry fun update_voter(staker: &signer, operator: address, new_voter: address) acquires Store {
|
|
454
|
+
let staker_address = signer::address_of(staker);
|
|
455
|
+
assert_staking_contract_exists(staker_address, operator);
|
|
456
|
+
|
|
457
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
458
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
459
|
+
let pool_address = staking_contract.pool_address;
|
|
460
|
+
let old_voter = stake::get_delegated_voter(pool_address);
|
|
461
|
+
stake::set_delegated_voter_with_cap(&staking_contract.owner_cap, new_voter);
|
|
462
|
+
|
|
463
|
+
if (std::features::module_event_migration_enabled()) {
|
|
464
|
+
emit(UpdateVoter { operator, pool_address, old_voter, new_voter });
|
|
465
|
+
};
|
|
466
|
+
emit_event(
|
|
467
|
+
&mut store.update_voter_events,
|
|
468
|
+
UpdateVoterEvent { operator, pool_address, old_voter, new_voter },
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/// Convenient function to allow the staker to reset their stake pool's lockup period to start now.
|
|
474
|
+
public entry fun reset_lockup(staker: &signer, operator: address) acquires Store {
|
|
475
|
+
let staker_address = signer::address_of(staker);
|
|
476
|
+
assert_staking_contract_exists(staker_address, operator);
|
|
477
|
+
|
|
478
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
479
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
480
|
+
let pool_address = staking_contract.pool_address;
|
|
481
|
+
stake::increase_lockup_with_cap(&staking_contract.owner_cap);
|
|
482
|
+
|
|
483
|
+
if (std::features::module_event_migration_enabled()) {
|
|
484
|
+
emit(ResetLockup { operator, pool_address });
|
|
485
|
+
};
|
|
486
|
+
emit_event(&mut store.reset_lockup_events, ResetLockupEvent { operator, pool_address });
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/// Convenience function to allow a staker to update the commission percentage paid to the operator.
|
|
490
|
+
/// TODO: fix the typo in function name. commision -> commission
|
|
491
|
+
public entry fun update_commision(
|
|
492
|
+
staker: &signer,
|
|
493
|
+
operator: address,
|
|
494
|
+
new_commission_percentage: u64
|
|
495
|
+
) acquires Store, BeneficiaryForOperator, StakingGroupUpdateCommissionEvent {
|
|
496
|
+
assert!(
|
|
497
|
+
new_commission_percentage >= 0 && new_commission_percentage <= 100,
|
|
498
|
+
error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE),
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
let staker_address = signer::address_of(staker);
|
|
502
|
+
assert!(exists<Store>(staker_address), error::not_found(ENO_STAKING_CONTRACT_FOUND_FOR_STAKER));
|
|
503
|
+
|
|
504
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
505
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
506
|
+
distribute_internal(staker_address, operator, staking_contract, &mut store.distribute_events);
|
|
507
|
+
request_commission_internal(
|
|
508
|
+
operator,
|
|
509
|
+
staking_contract,
|
|
510
|
+
&mut store.add_distribution_events,
|
|
511
|
+
&mut store.request_commission_events,
|
|
512
|
+
);
|
|
513
|
+
let old_commission_percentage = staking_contract.commission_percentage;
|
|
514
|
+
staking_contract.commission_percentage = new_commission_percentage;
|
|
515
|
+
if (!exists<StakingGroupUpdateCommissionEvent>(staker_address)) {
|
|
516
|
+
move_to(
|
|
517
|
+
staker,
|
|
518
|
+
StakingGroupUpdateCommissionEvent {
|
|
519
|
+
update_commission_events: account::new_event_handle<UpdateCommissionEvent>(
|
|
520
|
+
staker
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
)
|
|
524
|
+
};
|
|
525
|
+
if (std::features::module_event_migration_enabled()) {
|
|
526
|
+
emit(
|
|
527
|
+
UpdateCommission { staker: staker_address, operator, old_commission_percentage, new_commission_percentage }
|
|
528
|
+
);
|
|
529
|
+
};
|
|
530
|
+
emit_event(
|
|
531
|
+
&mut borrow_global_mut<StakingGroupUpdateCommissionEvent>(staker_address).update_commission_events,
|
|
532
|
+
UpdateCommissionEvent { staker: staker_address, operator, old_commission_percentage, new_commission_percentage }
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/// Unlock commission amount from the stake pool. Operator needs to wait for the amount to become withdrawable
|
|
537
|
+
/// at the end of the stake pool's lockup period before they can actually can withdraw_commission.
|
|
538
|
+
///
|
|
539
|
+
/// Only staker, operator or beneficiary can call this.
|
|
540
|
+
public entry fun request_commission(
|
|
541
|
+
account: &signer,
|
|
542
|
+
staker: address,
|
|
543
|
+
operator: address
|
|
544
|
+
) acquires Store, BeneficiaryForOperator {
|
|
545
|
+
let account_addr = signer::address_of(account);
|
|
546
|
+
assert!(
|
|
547
|
+
account_addr == staker || account_addr == operator || account_addr == beneficiary_for_operator(operator),
|
|
548
|
+
error::unauthenticated(ENOT_STAKER_OR_OPERATOR_OR_BENEFICIARY)
|
|
549
|
+
);
|
|
550
|
+
assert_staking_contract_exists(staker, operator);
|
|
551
|
+
|
|
552
|
+
let store = borrow_global_mut<Store>(staker);
|
|
553
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
554
|
+
// Short-circuit if zero commission.
|
|
555
|
+
if (staking_contract.commission_percentage == 0) {
|
|
556
|
+
return
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// Force distribution of any already inactive stake.
|
|
560
|
+
distribute_internal(staker, operator, staking_contract, &mut store.distribute_events);
|
|
561
|
+
|
|
562
|
+
request_commission_internal(
|
|
563
|
+
operator,
|
|
564
|
+
staking_contract,
|
|
565
|
+
&mut store.add_distribution_events,
|
|
566
|
+
&mut store.request_commission_events,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
fun request_commission_internal(
|
|
571
|
+
operator: address,
|
|
572
|
+
staking_contract: &mut StakingContract,
|
|
573
|
+
add_distribution_events: &mut EventHandle<AddDistributionEvent>,
|
|
574
|
+
request_commission_events: &mut EventHandle<RequestCommissionEvent>,
|
|
575
|
+
): u64 {
|
|
576
|
+
// Unlock just the commission portion from the stake pool.
|
|
577
|
+
let (total_active_stake, accumulated_rewards, commission_amount) =
|
|
578
|
+
get_staking_contract_amounts_internal(staking_contract);
|
|
579
|
+
staking_contract.principal = total_active_stake - commission_amount;
|
|
580
|
+
|
|
581
|
+
// Short-circuit if there's no commission to pay.
|
|
582
|
+
if (commission_amount == 0) {
|
|
583
|
+
return 0
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// Add a distribution for the operator.
|
|
587
|
+
add_distribution(operator, staking_contract, operator, commission_amount, add_distribution_events);
|
|
588
|
+
|
|
589
|
+
// Request to unlock the commission from the stake pool.
|
|
590
|
+
// This won't become fully unlocked until the stake pool's lockup expires.
|
|
591
|
+
stake::unlock_with_cap(commission_amount, &staking_contract.owner_cap);
|
|
592
|
+
|
|
593
|
+
let pool_address = staking_contract.pool_address;
|
|
594
|
+
if (std::features::module_event_migration_enabled()) {
|
|
595
|
+
emit(RequestCommission { operator, pool_address, accumulated_rewards, commission_amount });
|
|
596
|
+
};
|
|
597
|
+
emit_event(
|
|
598
|
+
request_commission_events,
|
|
599
|
+
RequestCommissionEvent { operator, pool_address, accumulated_rewards, commission_amount },
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
commission_amount
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/// Staker can call this to request withdrawal of part or all of their staking_contract.
|
|
606
|
+
/// This also triggers paying commission to the operator for accounting simplicity.
|
|
607
|
+
public entry fun unlock_stake(
|
|
608
|
+
staker: &signer,
|
|
609
|
+
operator: address,
|
|
610
|
+
amount: u64
|
|
611
|
+
) acquires Store, BeneficiaryForOperator {
|
|
612
|
+
// Short-circuit if amount is 0.
|
|
613
|
+
if (amount == 0) return;
|
|
614
|
+
|
|
615
|
+
let staker_address = signer::address_of(staker);
|
|
616
|
+
assert_staking_contract_exists(staker_address, operator);
|
|
617
|
+
|
|
618
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
619
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
620
|
+
|
|
621
|
+
// Force distribution of any already inactive stake.
|
|
622
|
+
distribute_internal(staker_address, operator, staking_contract, &mut store.distribute_events);
|
|
623
|
+
|
|
624
|
+
// For simplicity, we request commission to be paid out first. This avoids having to ensure to staker doesn't
|
|
625
|
+
// withdraw into the commission portion.
|
|
626
|
+
let commission_paid = request_commission_internal(
|
|
627
|
+
operator,
|
|
628
|
+
staking_contract,
|
|
629
|
+
&mut store.add_distribution_events,
|
|
630
|
+
&mut store.request_commission_events,
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
// If there's less active stake remaining than the amount requested (potentially due to commission),
|
|
634
|
+
// only withdraw up to the active amount.
|
|
635
|
+
let (active, _, _, _) = stake::get_stake(staking_contract.pool_address);
|
|
636
|
+
if (active < amount) {
|
|
637
|
+
amount = active;
|
|
638
|
+
};
|
|
639
|
+
staking_contract.principal = staking_contract.principal - amount;
|
|
640
|
+
|
|
641
|
+
// Record a distribution for the staker.
|
|
642
|
+
add_distribution(operator, staking_contract, staker_address, amount, &mut store.add_distribution_events);
|
|
643
|
+
|
|
644
|
+
// Request to unlock the distribution amount from the stake pool.
|
|
645
|
+
// This won't become fully unlocked until the stake pool's lockup expires.
|
|
646
|
+
stake::unlock_with_cap(amount, &staking_contract.owner_cap);
|
|
647
|
+
|
|
648
|
+
let pool_address = staking_contract.pool_address;
|
|
649
|
+
if (std::features::module_event_migration_enabled()) {
|
|
650
|
+
emit(UnlockStake { pool_address, operator, amount, commission_paid });
|
|
651
|
+
};
|
|
652
|
+
emit_event(
|
|
653
|
+
&mut store.unlock_stake_events,
|
|
654
|
+
UnlockStakeEvent { pool_address, operator, amount, commission_paid },
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/// Unlock all accumulated rewards since the last recorded principals.
|
|
659
|
+
public entry fun unlock_rewards(staker: &signer, operator: address) acquires Store, BeneficiaryForOperator {
|
|
660
|
+
let staker_address = signer::address_of(staker);
|
|
661
|
+
assert_staking_contract_exists(staker_address, operator);
|
|
662
|
+
|
|
663
|
+
// Calculate how much rewards belongs to the staker after commission is paid.
|
|
664
|
+
let (_, accumulated_rewards, unpaid_commission) = staking_contract_amounts(staker_address, operator);
|
|
665
|
+
let staker_rewards = accumulated_rewards - unpaid_commission;
|
|
666
|
+
unlock_stake(staker, operator, staker_rewards);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/// Allows staker to switch operator without going through the lenghthy process to unstake, without resetting commission.
|
|
670
|
+
public entry fun switch_operator_with_same_commission(
|
|
671
|
+
staker: &signer,
|
|
672
|
+
old_operator: address,
|
|
673
|
+
new_operator: address,
|
|
674
|
+
) acquires Store, BeneficiaryForOperator {
|
|
675
|
+
let staker_address = signer::address_of(staker);
|
|
676
|
+
assert_staking_contract_exists(staker_address, old_operator);
|
|
677
|
+
|
|
678
|
+
let commission_percentage = commission_percentage(staker_address, old_operator);
|
|
679
|
+
switch_operator(staker, old_operator, new_operator, commission_percentage);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/// Allows staker to switch operator without going through the lenghthy process to unstake.
|
|
683
|
+
public entry fun switch_operator(
|
|
684
|
+
staker: &signer,
|
|
685
|
+
old_operator: address,
|
|
686
|
+
new_operator: address,
|
|
687
|
+
new_commission_percentage: u64,
|
|
688
|
+
) acquires Store, BeneficiaryForOperator {
|
|
689
|
+
let staker_address = signer::address_of(staker);
|
|
690
|
+
assert_staking_contract_exists(staker_address, old_operator);
|
|
691
|
+
|
|
692
|
+
// Merging two existing staking contracts is too complex as we'd need to merge two separate stake pools.
|
|
693
|
+
let store = borrow_global_mut<Store>(staker_address);
|
|
694
|
+
let staking_contracts = &mut store.staking_contracts;
|
|
695
|
+
assert!(
|
|
696
|
+
!simple_map::contains_key(staking_contracts, &new_operator),
|
|
697
|
+
error::invalid_state(ECANT_MERGE_STAKING_CONTRACTS),
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
let (_, staking_contract) = simple_map::remove(staking_contracts, &old_operator);
|
|
701
|
+
// Force distribution of any already inactive stake.
|
|
702
|
+
distribute_internal(staker_address, old_operator, &mut staking_contract, &mut store.distribute_events);
|
|
703
|
+
|
|
704
|
+
// For simplicity, we request commission to be paid out first. This avoids having to ensure to staker doesn't
|
|
705
|
+
// withdraw into the commission portion.
|
|
706
|
+
request_commission_internal(
|
|
707
|
+
old_operator,
|
|
708
|
+
&mut staking_contract,
|
|
709
|
+
&mut store.add_distribution_events,
|
|
710
|
+
&mut store.request_commission_events,
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
// Update the staking contract's commission rate and stake pool's operator.
|
|
714
|
+
stake::set_operator_with_cap(&staking_contract.owner_cap, new_operator);
|
|
715
|
+
staking_contract.commission_percentage = new_commission_percentage;
|
|
716
|
+
|
|
717
|
+
let pool_address = staking_contract.pool_address;
|
|
718
|
+
simple_map::add(staking_contracts, new_operator, staking_contract);
|
|
719
|
+
if (std::features::module_event_migration_enabled()) {
|
|
720
|
+
emit(SwitchOperator { pool_address, old_operator, new_operator });
|
|
721
|
+
};
|
|
722
|
+
emit_event(
|
|
723
|
+
&mut store.switch_operator_events,
|
|
724
|
+
SwitchOperatorEvent { pool_address, old_operator, new_operator }
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/// Allows an operator to change its beneficiary. Any existing unpaid commission rewards will be paid to the new
|
|
729
|
+
/// beneficiary. To ensures payment to the current beneficiary, one should first call `distribute` before switching
|
|
730
|
+
/// the beneficiary. An operator can set one beneficiary for staking contract pools, not a separate one for each pool.
|
|
731
|
+
public entry fun set_beneficiary_for_operator(
|
|
732
|
+
operator: &signer,
|
|
733
|
+
new_beneficiary: address
|
|
734
|
+
) acquires BeneficiaryForOperator {
|
|
735
|
+
assert!(features::operator_beneficiary_change_enabled(), std::error::invalid_state(
|
|
736
|
+
EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED
|
|
737
|
+
));
|
|
738
|
+
// The beneficiay address of an operator is stored under the operator's address.
|
|
739
|
+
// So, the operator does not need to be validated with respect to a staking pool.
|
|
740
|
+
let operator_addr = signer::address_of(operator);
|
|
741
|
+
let old_beneficiary = beneficiary_for_operator(operator_addr);
|
|
742
|
+
if (exists<BeneficiaryForOperator>(operator_addr)) {
|
|
743
|
+
borrow_global_mut<BeneficiaryForOperator>(operator_addr).beneficiary_for_operator = new_beneficiary;
|
|
744
|
+
} else {
|
|
745
|
+
move_to(operator, BeneficiaryForOperator { beneficiary_for_operator: new_beneficiary });
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
emit(SetBeneficiaryForOperator {
|
|
749
|
+
operator: operator_addr,
|
|
750
|
+
old_beneficiary,
|
|
751
|
+
new_beneficiary,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/// Allow anyone to distribute already unlocked funds. This does not affect reward compounding and therefore does
|
|
756
|
+
/// not need to be restricted to just the staker or operator.
|
|
757
|
+
public entry fun distribute(staker: address, operator: address) acquires Store, BeneficiaryForOperator {
|
|
758
|
+
assert_staking_contract_exists(staker, operator);
|
|
759
|
+
let store = borrow_global_mut<Store>(staker);
|
|
760
|
+
let staking_contract = simple_map::borrow_mut(&mut store.staking_contracts, &operator);
|
|
761
|
+
distribute_internal(staker, operator, staking_contract, &mut store.distribute_events);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/// Distribute all unlocked (inactive) funds according to distribution shares.
|
|
765
|
+
fun distribute_internal(
|
|
766
|
+
staker: address,
|
|
767
|
+
operator: address,
|
|
768
|
+
staking_contract: &mut StakingContract,
|
|
769
|
+
distribute_events: &mut EventHandle<DistributeEvent>,
|
|
770
|
+
) acquires BeneficiaryForOperator {
|
|
771
|
+
let pool_address = staking_contract.pool_address;
|
|
772
|
+
let (_, inactive, _, pending_inactive) = stake::get_stake(pool_address);
|
|
773
|
+
let total_potential_withdrawable = inactive + pending_inactive;
|
|
774
|
+
let coins = stake::withdraw_with_cap(&staking_contract.owner_cap, total_potential_withdrawable);
|
|
775
|
+
let distribution_amount = coin::value(&coins);
|
|
776
|
+
if (distribution_amount == 0) {
|
|
777
|
+
coin::destroy_zero(coins);
|
|
778
|
+
return
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
let distribution_pool = &mut staking_contract.distribution_pool;
|
|
782
|
+
update_distribution_pool(
|
|
783
|
+
distribution_pool, distribution_amount, operator, staking_contract.commission_percentage);
|
|
784
|
+
|
|
785
|
+
// Buy all recipients out of the distribution pool.
|
|
786
|
+
while (pool_u64::shareholders_count(distribution_pool) > 0) {
|
|
787
|
+
let recipients = pool_u64::shareholders(distribution_pool);
|
|
788
|
+
let recipient = *vector::borrow(&mut recipients, 0);
|
|
789
|
+
let current_shares = pool_u64::shares(distribution_pool, recipient);
|
|
790
|
+
let amount_to_distribute = pool_u64::redeem_shares(distribution_pool, recipient, current_shares);
|
|
791
|
+
// If the recipient is the operator, send the commission to the beneficiary instead.
|
|
792
|
+
if (recipient == operator) {
|
|
793
|
+
recipient = beneficiary_for_operator(operator);
|
|
794
|
+
};
|
|
795
|
+
aptos_account::deposit_coins(recipient, coin::extract(&mut coins, amount_to_distribute));
|
|
796
|
+
|
|
797
|
+
if (std::features::module_event_migration_enabled()) {
|
|
798
|
+
emit(Distribute { operator, pool_address, recipient, amount: amount_to_distribute });
|
|
799
|
+
};
|
|
800
|
+
emit_event(
|
|
801
|
+
distribute_events,
|
|
802
|
+
DistributeEvent { operator, pool_address, recipient, amount: amount_to_distribute }
|
|
803
|
+
);
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
// In case there's any dust left, send them all to the staker.
|
|
807
|
+
if (coin::value(&coins) > 0) {
|
|
808
|
+
aptos_account::deposit_coins(staker, coins);
|
|
809
|
+
pool_u64::update_total_coins(distribution_pool, 0);
|
|
810
|
+
} else {
|
|
811
|
+
coin::destroy_zero(coins);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/// Assert that a staking_contract exists for the staker/operator pair.
|
|
816
|
+
fun assert_staking_contract_exists(staker: address, operator: address) acquires Store {
|
|
817
|
+
assert!(exists<Store>(staker), error::not_found(ENO_STAKING_CONTRACT_FOUND_FOR_STAKER));
|
|
818
|
+
let staking_contracts = &mut borrow_global_mut<Store>(staker).staking_contracts;
|
|
819
|
+
assert!(
|
|
820
|
+
simple_map::contains_key(staking_contracts, &operator),
|
|
821
|
+
error::not_found(ENO_STAKING_CONTRACT_FOUND_FOR_OPERATOR),
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/// Add a new distribution for `recipient` and `amount` to the staking contract's distributions list.
|
|
826
|
+
fun add_distribution(
|
|
827
|
+
operator: address,
|
|
828
|
+
staking_contract: &mut StakingContract,
|
|
829
|
+
recipient: address,
|
|
830
|
+
coins_amount: u64,
|
|
831
|
+
add_distribution_events: &mut EventHandle<AddDistributionEvent>
|
|
832
|
+
) {
|
|
833
|
+
let distribution_pool = &mut staking_contract.distribution_pool;
|
|
834
|
+
let (_, _, _, total_distribution_amount) = stake::get_stake(staking_contract.pool_address);
|
|
835
|
+
update_distribution_pool(
|
|
836
|
+
distribution_pool, total_distribution_amount, operator, staking_contract.commission_percentage);
|
|
837
|
+
|
|
838
|
+
pool_u64::buy_in(distribution_pool, recipient, coins_amount);
|
|
839
|
+
let pool_address = staking_contract.pool_address;
|
|
840
|
+
if (std::features::module_event_migration_enabled()) {
|
|
841
|
+
emit(AddDistribution { operator, pool_address, amount: coins_amount });
|
|
842
|
+
};
|
|
843
|
+
emit_event(
|
|
844
|
+
add_distribution_events,
|
|
845
|
+
AddDistributionEvent { operator, pool_address, amount: coins_amount }
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/// Calculate accumulated rewards and commissions since last update.
|
|
850
|
+
fun get_staking_contract_amounts_internal(staking_contract: &StakingContract): (u64, u64, u64) {
|
|
851
|
+
// Pending_inactive is not included in the calculation because pending_inactive can only come from:
|
|
852
|
+
// 1. Outgoing commissions. This means commission has already been extracted.
|
|
853
|
+
// 2. Stake withdrawals from stakers. This also means commission has already been extracted as
|
|
854
|
+
// request_commission_internal is called in unlock_stake
|
|
855
|
+
let (active, _, pending_active, _) = stake::get_stake(staking_contract.pool_address);
|
|
856
|
+
let total_active_stake = active + pending_active;
|
|
857
|
+
let accumulated_rewards = total_active_stake - staking_contract.principal;
|
|
858
|
+
let commission_amount = accumulated_rewards * staking_contract.commission_percentage / 100;
|
|
859
|
+
|
|
860
|
+
(total_active_stake, accumulated_rewards, commission_amount)
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
fun create_stake_pool(
|
|
864
|
+
staker: &signer,
|
|
865
|
+
operator: address,
|
|
866
|
+
voter: address,
|
|
867
|
+
contract_creation_seed: vector<u8>,
|
|
868
|
+
): (signer, SignerCapability, OwnerCapability) {
|
|
869
|
+
// Generate a seed that will be used to create the resource account that hosts the staking contract.
|
|
870
|
+
let seed = create_resource_account_seed(
|
|
871
|
+
signer::address_of(staker), operator, contract_creation_seed);
|
|
872
|
+
|
|
873
|
+
let (stake_pool_signer, stake_pool_signer_cap) = account::create_resource_account(staker, seed);
|
|
874
|
+
stake::initialize_stake_owner(&stake_pool_signer, 0, operator, voter);
|
|
875
|
+
|
|
876
|
+
// Extract owner_cap from the StakePool, so we have control over it in the staking_contracts flow.
|
|
877
|
+
// This is stored as part of the staking_contract. Thus, the staker would not have direct control over it without
|
|
878
|
+
// going through well-defined functions in this module.
|
|
879
|
+
let owner_cap = stake::extract_owner_cap(&stake_pool_signer);
|
|
880
|
+
|
|
881
|
+
(stake_pool_signer, stake_pool_signer_cap, owner_cap)
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
fun update_distribution_pool(
|
|
885
|
+
distribution_pool: &mut Pool,
|
|
886
|
+
updated_total_coins: u64,
|
|
887
|
+
operator: address,
|
|
888
|
+
commission_percentage: u64,
|
|
889
|
+
) {
|
|
890
|
+
// Short-circuit and do nothing if the pool's total value has not changed.
|
|
891
|
+
if (pool_u64::total_coins(distribution_pool) == updated_total_coins) {
|
|
892
|
+
return
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
// Charge all stakeholders (except for the operator themselves) commission on any rewards earnt relatively to the
|
|
896
|
+
// previous value of the distribution pool.
|
|
897
|
+
let shareholders = &pool_u64::shareholders(distribution_pool);
|
|
898
|
+
vector::for_each_ref(shareholders, |shareholder| {
|
|
899
|
+
let shareholder: address = *shareholder;
|
|
900
|
+
if (shareholder != operator) {
|
|
901
|
+
let shares = pool_u64::shares(distribution_pool, shareholder);
|
|
902
|
+
let previous_worth = pool_u64::balance(distribution_pool, shareholder);
|
|
903
|
+
let current_worth = pool_u64::shares_to_amount_with_total_coins(
|
|
904
|
+
distribution_pool, shares, updated_total_coins);
|
|
905
|
+
let unpaid_commission = (current_worth - previous_worth) * commission_percentage / 100;
|
|
906
|
+
// Transfer shares from current shareholder to the operator as payment.
|
|
907
|
+
// The value of the shares should use the updated pool's total value.
|
|
908
|
+
let shares_to_transfer = pool_u64::amount_to_shares_with_total_coins(
|
|
909
|
+
distribution_pool, unpaid_commission, updated_total_coins);
|
|
910
|
+
pool_u64::transfer_shares(distribution_pool, shareholder, operator, shares_to_transfer);
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
pool_u64::update_total_coins(distribution_pool, updated_total_coins);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/// Create the seed to derive the resource account address.
|
|
918
|
+
fun create_resource_account_seed(
|
|
919
|
+
staker: address,
|
|
920
|
+
operator: address,
|
|
921
|
+
contract_creation_seed: vector<u8>,
|
|
922
|
+
): vector<u8> {
|
|
923
|
+
let seed = bcs::to_bytes(&staker);
|
|
924
|
+
vector::append(&mut seed, bcs::to_bytes(&operator));
|
|
925
|
+
// Include a salt to avoid conflicts with any other modules out there that might also generate
|
|
926
|
+
// deterministic resource accounts for the same staker + operator addresses.
|
|
927
|
+
vector::append(&mut seed, SALT);
|
|
928
|
+
// Add an extra salt given by the staker in case an account with the same address has already been created.
|
|
929
|
+
vector::append(&mut seed, contract_creation_seed);
|
|
930
|
+
seed
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/// Create a new staking_contracts resource.
|
|
934
|
+
fun new_staking_contracts_holder(staker: &signer): Store {
|
|
935
|
+
Store {
|
|
936
|
+
staking_contracts: simple_map::create<address, StakingContract>(),
|
|
937
|
+
// Events.
|
|
938
|
+
create_staking_contract_events: account::new_event_handle<CreateStakingContractEvent>(staker),
|
|
939
|
+
update_voter_events: account::new_event_handle<UpdateVoterEvent>(staker),
|
|
940
|
+
reset_lockup_events: account::new_event_handle<ResetLockupEvent>(staker),
|
|
941
|
+
add_stake_events: account::new_event_handle<AddStakeEvent>(staker),
|
|
942
|
+
request_commission_events: account::new_event_handle<RequestCommissionEvent>(staker),
|
|
943
|
+
unlock_stake_events: account::new_event_handle<UnlockStakeEvent>(staker),
|
|
944
|
+
switch_operator_events: account::new_event_handle<SwitchOperatorEvent>(staker),
|
|
945
|
+
add_distribution_events: account::new_event_handle<AddDistributionEvent>(staker),
|
|
946
|
+
distribute_events: account::new_event_handle<DistributeEvent>(staker),
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
#[test_only]
|
|
951
|
+
const VALIDATOR_STATUS_ACTIVE: u64 = 2;
|
|
952
|
+
#[test_only]
|
|
953
|
+
const VALIDATOR_STATUS_INACTIVE: u64 = 4;
|
|
954
|
+
|
|
955
|
+
#[test_only]
|
|
956
|
+
use aptos_framework::stake::with_rewards;
|
|
957
|
+
|
|
958
|
+
#[test_only]
|
|
959
|
+
const INITIAL_BALANCE: u64 = 100000000000000; // 1M APT coins with 8 decimals.
|
|
960
|
+
|
|
961
|
+
#[test_only]
|
|
962
|
+
const MAXIMUM_STAKE: u64 = 100000000000000000; // 1B APT coins with 8 decimals.
|
|
963
|
+
|
|
964
|
+
#[test_only]
|
|
965
|
+
const MODULE_EVENT: u64 = 26;
|
|
966
|
+
|
|
967
|
+
#[test_only]
|
|
968
|
+
const OPERATOR_BENEFICIARY_CHANGE: u64 = 39;
|
|
969
|
+
|
|
970
|
+
#[test_only]
|
|
971
|
+
public fun setup(aptos_framework: &signer, staker: &signer, operator: &signer, initial_balance: u64) {
|
|
972
|
+
// Reward rate of 0.1% per epoch.
|
|
973
|
+
stake::initialize_for_test_custom(
|
|
974
|
+
aptos_framework,
|
|
975
|
+
INITIAL_BALANCE,
|
|
976
|
+
MAXIMUM_STAKE,
|
|
977
|
+
3600,
|
|
978
|
+
true,
|
|
979
|
+
10,
|
|
980
|
+
10000,
|
|
981
|
+
1000000
|
|
982
|
+
);
|
|
983
|
+
|
|
984
|
+
let staker_address = signer::address_of(staker);
|
|
985
|
+
if (!account::exists_at(staker_address)) {
|
|
986
|
+
account::create_account_for_test(staker_address);
|
|
987
|
+
};
|
|
988
|
+
let operator_address = signer::address_of(operator);
|
|
989
|
+
if (!account::exists_at(operator_address)) {
|
|
990
|
+
account::create_account_for_test(operator_address);
|
|
991
|
+
};
|
|
992
|
+
stake::mint(staker, initial_balance);
|
|
993
|
+
stake::mint(operator, initial_balance);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
#[test_only]
|
|
997
|
+
public fun setup_staking_contract(
|
|
998
|
+
aptos_framework: &signer,
|
|
999
|
+
staker: &signer,
|
|
1000
|
+
operator: &signer,
|
|
1001
|
+
amount: u64,
|
|
1002
|
+
commission: u64,
|
|
1003
|
+
) acquires Store {
|
|
1004
|
+
setup(aptos_framework, staker, operator, amount);
|
|
1005
|
+
let operator_address = signer::address_of(operator);
|
|
1006
|
+
|
|
1007
|
+
// Voter is initially set to operator but then updated to be staker.
|
|
1008
|
+
create_staking_contract(staker, operator_address, operator_address, amount, commission, vector::empty<u8>());
|
|
1009
|
+
std::features::change_feature_flags_for_testing(aptos_framework, vector[MODULE_EVENT, OPERATOR_BENEFICIARY_CHANGE], vector[]);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1013
|
+
public entry fun test_end_to_end(
|
|
1014
|
+
aptos_framework: &signer,
|
|
1015
|
+
staker: &signer,
|
|
1016
|
+
operator: &signer
|
|
1017
|
+
) acquires Store, BeneficiaryForOperator {
|
|
1018
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1019
|
+
let staker_address = signer::address_of(staker);
|
|
1020
|
+
let operator_address = signer::address_of(operator);
|
|
1021
|
+
assert_staking_contract_exists(staker_address, operator_address);
|
|
1022
|
+
assert_staking_contract(staker_address, operator_address, INITIAL_BALANCE, 10);
|
|
1023
|
+
|
|
1024
|
+
// Verify that the stake pool has been set up properly.
|
|
1025
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1026
|
+
stake::assert_stake_pool(pool_address, INITIAL_BALANCE, 0, 0, 0);
|
|
1027
|
+
assert!(last_recorded_principal(staker_address, operator_address) == INITIAL_BALANCE, 0);
|
|
1028
|
+
|
|
1029
|
+
// Operator joins the validator set.
|
|
1030
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1031
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1032
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1033
|
+
|
|
1034
|
+
// Fast forward to generate rewards.
|
|
1035
|
+
stake::end_epoch();
|
|
1036
|
+
let new_balance = with_rewards(INITIAL_BALANCE);
|
|
1037
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1038
|
+
|
|
1039
|
+
// Operator claims 10% of rewards so far as commissions.
|
|
1040
|
+
let expected_commission_1 = (new_balance - last_recorded_principal(staker_address, operator_address)) / 10;
|
|
1041
|
+
new_balance = new_balance - expected_commission_1;
|
|
1042
|
+
request_commission(operator, staker_address, operator_address);
|
|
1043
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, expected_commission_1);
|
|
1044
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1045
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission_1);
|
|
1046
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1047
|
+
|
|
1048
|
+
// Both original stake and operator commissions have received rewards.
|
|
1049
|
+
expected_commission_1 = with_rewards(expected_commission_1);
|
|
1050
|
+
new_balance = with_rewards(new_balance);
|
|
1051
|
+
stake::assert_stake_pool(pool_address, new_balance, expected_commission_1, 0, 0);
|
|
1052
|
+
distribute(staker_address, operator_address);
|
|
1053
|
+
let operator_balance = coin::balance<AptosCoin>(operator_address);
|
|
1054
|
+
let expected_operator_balance = INITIAL_BALANCE + expected_commission_1;
|
|
1055
|
+
assert!(operator_balance == expected_operator_balance, operator_balance);
|
|
1056
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1057
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1058
|
+
|
|
1059
|
+
// Staker adds more stake.
|
|
1060
|
+
stake::mint(staker, INITIAL_BALANCE);
|
|
1061
|
+
let previous_principal = last_recorded_principal(staker_address, operator_address);
|
|
1062
|
+
add_stake(staker, operator_address, INITIAL_BALANCE);
|
|
1063
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, INITIAL_BALANCE, 0);
|
|
1064
|
+
assert!(last_recorded_principal(staker_address, operator_address) == previous_principal + INITIAL_BALANCE, 0);
|
|
1065
|
+
|
|
1066
|
+
// The newly added stake didn't receive any rewards because it was only added in the new epoch.
|
|
1067
|
+
stake::end_epoch();
|
|
1068
|
+
new_balance = with_rewards(new_balance) + INITIAL_BALANCE;
|
|
1069
|
+
|
|
1070
|
+
// Second round of commission request/withdrawal.
|
|
1071
|
+
let expected_commission_2 = (new_balance - last_recorded_principal(staker_address, operator_address)) / 10;
|
|
1072
|
+
new_balance = new_balance - expected_commission_2;
|
|
1073
|
+
request_commission(operator, staker_address, operator_address);
|
|
1074
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission_2);
|
|
1075
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1076
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1077
|
+
expected_commission_2 = with_rewards(expected_commission_2);
|
|
1078
|
+
distribute(staker_address, operator_address);
|
|
1079
|
+
operator_balance = coin::balance<AptosCoin>(operator_address);
|
|
1080
|
+
expected_operator_balance = expected_operator_balance + expected_commission_2;
|
|
1081
|
+
assert!(operator_balance == expected_operator_balance, operator_balance);
|
|
1082
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1083
|
+
new_balance = with_rewards(new_balance);
|
|
1084
|
+
|
|
1085
|
+
// New rounds of rewards.
|
|
1086
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1087
|
+
new_balance = with_rewards(new_balance);
|
|
1088
|
+
|
|
1089
|
+
// Staker withdraws all stake, which should also request commission distribution.
|
|
1090
|
+
let unpaid_commission = (new_balance - last_recorded_principal(staker_address, operator_address)) / 10;
|
|
1091
|
+
unlock_stake(staker, operator_address, new_balance);
|
|
1092
|
+
stake::assert_stake_pool(pool_address, 0, 0, 0, new_balance);
|
|
1093
|
+
assert_distribution(staker_address, operator_address, operator_address, unpaid_commission);
|
|
1094
|
+
let withdrawn_amount = new_balance - unpaid_commission;
|
|
1095
|
+
assert_distribution(staker_address, operator_address, staker_address, withdrawn_amount);
|
|
1096
|
+
assert!(last_recorded_principal(staker_address, operator_address) == 0, 0);
|
|
1097
|
+
|
|
1098
|
+
// End epoch. The stake pool should get kicked out of the validator set as it has 0 remaining active stake.
|
|
1099
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1100
|
+
// Operator should still earn 10% commission on the rewards on top of the staker's withdrawn_amount.
|
|
1101
|
+
let commission_on_withdrawn_amount = (with_rewards(withdrawn_amount) - withdrawn_amount) / 10;
|
|
1102
|
+
unpaid_commission = with_rewards(unpaid_commission) + commission_on_withdrawn_amount;
|
|
1103
|
+
withdrawn_amount = with_rewards(withdrawn_amount) - commission_on_withdrawn_amount;
|
|
1104
|
+
stake::assert_stake_pool(pool_address, 0, with_rewards(new_balance), 0, 0);
|
|
1105
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_INACTIVE, 0);
|
|
1106
|
+
|
|
1107
|
+
// Distribute and verify balances.
|
|
1108
|
+
distribute(staker_address, operator_address);
|
|
1109
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1110
|
+
operator_balance = coin::balance<AptosCoin>(operator_address);
|
|
1111
|
+
assert!(operator_balance == expected_operator_balance + unpaid_commission, operator_balance);
|
|
1112
|
+
let staker_balance = coin::balance<AptosCoin>(staker_address);
|
|
1113
|
+
// Staker receives the extra dust due to rounding error.
|
|
1114
|
+
assert!(staker_balance == withdrawn_amount + 1, staker_balance);
|
|
1115
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1119
|
+
public entry fun test_operator_cannot_request_same_commission_multiple_times(
|
|
1120
|
+
aptos_framework: &signer, staker: &signer, operator: &signer) acquires Store, BeneficiaryForOperator {
|
|
1121
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1122
|
+
let staker_address = signer::address_of(staker);
|
|
1123
|
+
let operator_address = signer::address_of(operator);
|
|
1124
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1125
|
+
|
|
1126
|
+
// Operator joins the validator set.
|
|
1127
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1128
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1129
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1130
|
+
|
|
1131
|
+
// Fast forward to generate rewards.
|
|
1132
|
+
stake::end_epoch();
|
|
1133
|
+
let new_balance = with_rewards(INITIAL_BALANCE);
|
|
1134
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1135
|
+
|
|
1136
|
+
// Operator tries to request commission multiple times. But their distribution shouldn't change.
|
|
1137
|
+
let expected_commission = (new_balance - last_recorded_principal(staker_address, operator_address)) / 10;
|
|
1138
|
+
request_commission(operator, staker_address, operator_address);
|
|
1139
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission);
|
|
1140
|
+
request_commission(operator, staker_address, operator_address);
|
|
1141
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission);
|
|
1142
|
+
request_commission(operator, staker_address, operator_address);
|
|
1143
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1147
|
+
public entry fun test_unlock_rewards(
|
|
1148
|
+
aptos_framework: &signer, staker: &signer, operator: &signer) acquires Store, BeneficiaryForOperator {
|
|
1149
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1150
|
+
let staker_address = signer::address_of(staker);
|
|
1151
|
+
let operator_address = signer::address_of(operator);
|
|
1152
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1153
|
+
|
|
1154
|
+
// Operator joins the validator set.
|
|
1155
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1156
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1157
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1158
|
+
|
|
1159
|
+
// Fast forward to generate rewards.
|
|
1160
|
+
stake::end_epoch();
|
|
1161
|
+
let new_balance = with_rewards(INITIAL_BALANCE);
|
|
1162
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1163
|
+
|
|
1164
|
+
// Staker withdraws all accumulated rewards, which should pay commission first.
|
|
1165
|
+
unlock_rewards(staker, operator_address);
|
|
1166
|
+
let accumulated_rewards = new_balance - INITIAL_BALANCE;
|
|
1167
|
+
let expected_commission = accumulated_rewards / 10;
|
|
1168
|
+
let staker_rewards = accumulated_rewards - expected_commission;
|
|
1169
|
+
assert_distribution(staker_address, operator_address, staker_address, staker_rewards);
|
|
1170
|
+
assert_distribution(staker_address, operator_address, operator_address, expected_commission);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1174
|
+
#[expected_failure(abort_code = 0x80006, location = Self)]
|
|
1175
|
+
public entry fun test_staker_cannot_create_same_staking_contract_multiple_times(
|
|
1176
|
+
aptos_framework: &signer,
|
|
1177
|
+
staker: &signer,
|
|
1178
|
+
operator: &signer,
|
|
1179
|
+
) acquires Store {
|
|
1180
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1181
|
+
let operator_address = signer::address_of(operator);
|
|
1182
|
+
stake::mint(staker, INITIAL_BALANCE);
|
|
1183
|
+
create_staking_contract(staker, operator_address, operator_address, INITIAL_BALANCE, 10, vector::empty<u8>());
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1187
|
+
#[expected_failure(abort_code = 0x10002, location = Self)]
|
|
1188
|
+
public entry fun test_staker_cannot_create_staking_contract_with_invalid_commission(
|
|
1189
|
+
aptos_framework: &signer,
|
|
1190
|
+
staker: &signer,
|
|
1191
|
+
operator: &signer,
|
|
1192
|
+
) acquires Store {
|
|
1193
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 101);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1197
|
+
#[expected_failure(abort_code = 0x10001, location = Self)]
|
|
1198
|
+
public entry fun test_staker_cannot_create_staking_contract_with_less_than_min_stake_required(
|
|
1199
|
+
aptos_framework: &signer,
|
|
1200
|
+
staker: &signer,
|
|
1201
|
+
operator: &signer,
|
|
1202
|
+
) acquires Store {
|
|
1203
|
+
setup_staking_contract(aptos_framework, staker, operator, 50, 100);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1207
|
+
public entry fun test_update_voter(
|
|
1208
|
+
aptos_framework: &signer,
|
|
1209
|
+
staker: &signer,
|
|
1210
|
+
operator: &signer,
|
|
1211
|
+
) acquires Store {
|
|
1212
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1213
|
+
let staker_address = signer::address_of(staker);
|
|
1214
|
+
let operator_address = signer::address_of(operator);
|
|
1215
|
+
|
|
1216
|
+
// Voter is initially set to operator but then updated to be staker.
|
|
1217
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1218
|
+
assert!(stake::get_delegated_voter(pool_address) == operator_address, 0);
|
|
1219
|
+
update_voter(staker, operator_address, staker_address);
|
|
1220
|
+
assert!(stake::get_delegated_voter(pool_address) == staker_address, 1);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1224
|
+
public entry fun test_reset_lockup(
|
|
1225
|
+
aptos_framework: &signer,
|
|
1226
|
+
staker: &signer,
|
|
1227
|
+
operator: &signer,
|
|
1228
|
+
) acquires Store {
|
|
1229
|
+
setup_staking_contract(aptos_framework, staker, operator, INITIAL_BALANCE, 10);
|
|
1230
|
+
let staker_address = signer::address_of(staker);
|
|
1231
|
+
let operator_address = signer::address_of(operator);
|
|
1232
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1233
|
+
|
|
1234
|
+
let origin_lockup_expiration = stake::get_lockup_secs(pool_address);
|
|
1235
|
+
reset_lockup(staker, operator_address);
|
|
1236
|
+
assert!(origin_lockup_expiration < stake::get_lockup_secs(pool_address), 0);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator_1 = @0x234, operator_2 = @0x345)]
|
|
1240
|
+
public entry fun test_staker_can_switch_operator(
|
|
1241
|
+
aptos_framework: &signer,
|
|
1242
|
+
staker: &signer,
|
|
1243
|
+
operator_1: &signer,
|
|
1244
|
+
operator_2: &signer,
|
|
1245
|
+
) acquires Store, BeneficiaryForOperator {
|
|
1246
|
+
setup_staking_contract(aptos_framework, staker, operator_1, INITIAL_BALANCE, 10);
|
|
1247
|
+
account::create_account_for_test(signer::address_of(operator_2));
|
|
1248
|
+
stake::mint(operator_2, INITIAL_BALANCE);
|
|
1249
|
+
let staker_address = signer::address_of(staker);
|
|
1250
|
+
let operator_1_address = signer::address_of(operator_1);
|
|
1251
|
+
let operator_2_address = signer::address_of(operator_2);
|
|
1252
|
+
|
|
1253
|
+
// Join validator set and earn some rewards.
|
|
1254
|
+
let pool_address = stake_pool_address(staker_address, operator_1_address);
|
|
1255
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1256
|
+
stake::join_validator_set_for_test(&pk, &pop, operator_1, pool_address, true);
|
|
1257
|
+
stake::end_epoch();
|
|
1258
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 0);
|
|
1259
|
+
|
|
1260
|
+
// Switch operators.
|
|
1261
|
+
switch_operator(staker, operator_1_address, operator_2_address, 20);
|
|
1262
|
+
// The staking_contract is now associated with operator 2 but there should be a pending distribution of unpaid
|
|
1263
|
+
// commission to operator 1.
|
|
1264
|
+
let new_balance = with_rewards(INITIAL_BALANCE);
|
|
1265
|
+
let commission_for_operator_1 = (new_balance - INITIAL_BALANCE) / 10;
|
|
1266
|
+
assert_distribution(staker_address, operator_2_address, operator_1_address, commission_for_operator_1);
|
|
1267
|
+
// Unpaid commission should be unlocked from the stake pool.
|
|
1268
|
+
new_balance = new_balance - commission_for_operator_1;
|
|
1269
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, commission_for_operator_1);
|
|
1270
|
+
assert!(last_recorded_principal(staker_address, operator_2_address) == new_balance, 0);
|
|
1271
|
+
|
|
1272
|
+
// The stake pool's validator should not have left the validator set.
|
|
1273
|
+
assert!(stake_pool_address(staker_address, operator_2_address) == pool_address, 1);
|
|
1274
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 2);
|
|
1275
|
+
|
|
1276
|
+
// End epoch to get more rewards.
|
|
1277
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1278
|
+
new_balance = with_rewards(new_balance);
|
|
1279
|
+
// Rewards on the commission being paid to operator_1 should still be charged commission that will go to
|
|
1280
|
+
// operator_2;
|
|
1281
|
+
let commission_on_operator_1_distribution =
|
|
1282
|
+
(with_rewards(commission_for_operator_1) - commission_for_operator_1) / 5;
|
|
1283
|
+
commission_for_operator_1 = with_rewards(commission_for_operator_1) - commission_on_operator_1_distribution;
|
|
1284
|
+
|
|
1285
|
+
// Verify that when commissions are withdrawn, previous pending distribution to operator 1 also happens.
|
|
1286
|
+
// Then new commission of 20% is paid to operator 2.
|
|
1287
|
+
let commission_for_operator_2 =
|
|
1288
|
+
(new_balance - last_recorded_principal(staker_address, operator_2_address)) / 5;
|
|
1289
|
+
new_balance = new_balance - commission_for_operator_2;
|
|
1290
|
+
request_commission(operator_2, staker_address, operator_2_address);
|
|
1291
|
+
assert_distribution(staker_address, operator_2_address, operator_2_address, commission_for_operator_2);
|
|
1292
|
+
let operator_1_balance = coin::balance<AptosCoin>(operator_1_address);
|
|
1293
|
+
assert!(operator_1_balance == INITIAL_BALANCE + commission_for_operator_1, operator_1_balance);
|
|
1294
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, commission_for_operator_2);
|
|
1295
|
+
assert!(last_recorded_principal(staker_address, operator_2_address) == new_balance, 0);
|
|
1296
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1297
|
+
|
|
1298
|
+
// Operator 2's commission is distributed.
|
|
1299
|
+
distribute(staker_address, operator_2_address);
|
|
1300
|
+
let operator_2_balance = coin::balance<AptosCoin>(operator_2_address);
|
|
1301
|
+
new_balance = with_rewards(new_balance);
|
|
1302
|
+
commission_for_operator_2 = with_rewards(commission_for_operator_2);
|
|
1303
|
+
assert!(
|
|
1304
|
+
operator_2_balance == INITIAL_BALANCE + commission_for_operator_2 + commission_on_operator_1_distribution,
|
|
1305
|
+
operator_2_balance,
|
|
1306
|
+
);
|
|
1307
|
+
stake::assert_stake_pool(
|
|
1308
|
+
pool_address,
|
|
1309
|
+
new_balance,
|
|
1310
|
+
0,
|
|
1311
|
+
0,
|
|
1312
|
+
0,
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator_1 = @0x234, operator_2 = @0x345)]
|
|
1317
|
+
public entry fun test_staker_can_switch_operator_with_same_commission(
|
|
1318
|
+
aptos_framework: &signer,
|
|
1319
|
+
staker: &signer,
|
|
1320
|
+
operator_1: &signer,
|
|
1321
|
+
operator_2: &signer,
|
|
1322
|
+
) acquires Store, BeneficiaryForOperator {
|
|
1323
|
+
setup_staking_contract(aptos_framework, staker, operator_1, INITIAL_BALANCE, 10);
|
|
1324
|
+
let staker_address = signer::address_of(staker);
|
|
1325
|
+
let operator_1_address = signer::address_of(operator_1);
|
|
1326
|
+
let operator_2_address = signer::address_of(operator_2);
|
|
1327
|
+
|
|
1328
|
+
// Switch operators.
|
|
1329
|
+
switch_operator_with_same_commission(staker, operator_1_address, operator_2_address);
|
|
1330
|
+
// The staking_contract should now be associated with operator 2 but with same commission rate.
|
|
1331
|
+
assert!(staking_contract_exists(staker_address, operator_2_address), 0);
|
|
1332
|
+
assert!(!staking_contract_exists(staker_address, operator_1_address), 1);
|
|
1333
|
+
assert!(commission_percentage(staker_address, operator_2_address) == 10, 2);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator1 = @0x234, beneficiary = @0x345, operator2 = @0x456)]
|
|
1337
|
+
public entry fun test_operator_can_set_beneficiary(
|
|
1338
|
+
aptos_framework: &signer,
|
|
1339
|
+
staker: &signer,
|
|
1340
|
+
operator1: &signer,
|
|
1341
|
+
beneficiary: &signer,
|
|
1342
|
+
operator2: &signer,
|
|
1343
|
+
) acquires Store, BeneficiaryForOperator {
|
|
1344
|
+
setup_staking_contract(aptos_framework, staker, operator1, INITIAL_BALANCE, 10);
|
|
1345
|
+
let staker_address = signer::address_of(staker);
|
|
1346
|
+
let operator1_address = signer::address_of(operator1);
|
|
1347
|
+
let operator2_address = signer::address_of(operator2);
|
|
1348
|
+
let beneficiary_address = signer::address_of(beneficiary);
|
|
1349
|
+
|
|
1350
|
+
// account::create_account_for_test(beneficiary_address);
|
|
1351
|
+
aptos_framework::aptos_account::create_account(beneficiary_address);
|
|
1352
|
+
assert_staking_contract_exists(staker_address, operator1_address);
|
|
1353
|
+
assert_staking_contract(staker_address, operator1_address, INITIAL_BALANCE, 10);
|
|
1354
|
+
|
|
1355
|
+
// Verify that the stake pool has been set up properly.
|
|
1356
|
+
let pool_address = stake_pool_address(staker_address, operator1_address);
|
|
1357
|
+
stake::assert_stake_pool(pool_address, INITIAL_BALANCE, 0, 0, 0);
|
|
1358
|
+
assert!(last_recorded_principal(staker_address, operator1_address) == INITIAL_BALANCE, 0);
|
|
1359
|
+
assert!(stake::get_operator(pool_address) == operator1_address, 0);
|
|
1360
|
+
assert!(beneficiary_for_operator(operator1_address) == operator1_address, 0);
|
|
1361
|
+
|
|
1362
|
+
// Operator joins the validator set.
|
|
1363
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1364
|
+
stake::join_validator_set_for_test(&pk, &pop, operator1, pool_address, true);
|
|
1365
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1366
|
+
|
|
1367
|
+
// Set beneficiary.
|
|
1368
|
+
set_beneficiary_for_operator(operator1, beneficiary_address);
|
|
1369
|
+
assert!(beneficiary_for_operator(operator1_address) == beneficiary_address, 0);
|
|
1370
|
+
|
|
1371
|
+
// Fast forward to generate rewards.
|
|
1372
|
+
stake::end_epoch();
|
|
1373
|
+
let new_balance = with_rewards(INITIAL_BALANCE);
|
|
1374
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1375
|
+
|
|
1376
|
+
// Operator claims 10% of rewards so far as commissions.
|
|
1377
|
+
let expected_commission_1 = (new_balance - last_recorded_principal(staker_address, operator1_address)) / 10;
|
|
1378
|
+
new_balance = new_balance - expected_commission_1;
|
|
1379
|
+
request_commission(operator1, staker_address, operator1_address);
|
|
1380
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, expected_commission_1);
|
|
1381
|
+
assert!(last_recorded_principal(staker_address, operator1_address) == new_balance, 0);
|
|
1382
|
+
assert_distribution(staker_address, operator1_address, operator1_address, expected_commission_1);
|
|
1383
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1384
|
+
|
|
1385
|
+
// Both original stake and operator commissions have received rewards.
|
|
1386
|
+
expected_commission_1 = with_rewards(expected_commission_1);
|
|
1387
|
+
new_balance = with_rewards(new_balance);
|
|
1388
|
+
stake::assert_stake_pool(pool_address, new_balance, expected_commission_1, 0, 0);
|
|
1389
|
+
distribute(staker_address, operator1_address);
|
|
1390
|
+
let operator_balance = coin::balance<AptosCoin>(operator1_address);
|
|
1391
|
+
let beneficiary_balance = coin::balance<AptosCoin>(beneficiary_address);
|
|
1392
|
+
let expected_operator_balance = INITIAL_BALANCE;
|
|
1393
|
+
let expected_beneficiary_balance = expected_commission_1;
|
|
1394
|
+
assert!(operator_balance == expected_operator_balance, operator_balance);
|
|
1395
|
+
assert!(beneficiary_balance == expected_beneficiary_balance, beneficiary_balance);
|
|
1396
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1397
|
+
assert_no_pending_distributions(staker_address, operator1_address);
|
|
1398
|
+
|
|
1399
|
+
// switch operator to operator2. The rewards should go to operator2 not to the beneficiay of operator1.
|
|
1400
|
+
let old_beneficiay_balance = beneficiary_balance;
|
|
1401
|
+
switch_operator(staker, operator1_address, operator2_address, 10);
|
|
1402
|
+
|
|
1403
|
+
stake::end_epoch();
|
|
1404
|
+
let (_, accumulated_rewards, _) = staking_contract_amounts(staker_address, operator2_address);
|
|
1405
|
+
|
|
1406
|
+
let expected_commission = accumulated_rewards / 10;
|
|
1407
|
+
|
|
1408
|
+
// Request commission.
|
|
1409
|
+
request_commission(operator2, staker_address, operator2_address);
|
|
1410
|
+
// Unlocks the commission.
|
|
1411
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1412
|
+
expected_commission = with_rewards(expected_commission);
|
|
1413
|
+
|
|
1414
|
+
// Distribute the commission to the operator.
|
|
1415
|
+
distribute(staker_address, operator2_address);
|
|
1416
|
+
|
|
1417
|
+
// Assert that the rewards go to operator2, and the balance of the operator1's beneficiay remains the same.
|
|
1418
|
+
assert!(coin::balance<AptosCoin>(operator2_address) >= expected_commission, 1);
|
|
1419
|
+
assert!(coin::balance<AptosCoin>(beneficiary_address) == old_beneficiay_balance, 1);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1423
|
+
public entry fun test_staker_can_withdraw_partial_stake(
|
|
1424
|
+
aptos_framework: &signer, staker: &signer, operator: &signer) acquires Store, BeneficiaryForOperator {
|
|
1425
|
+
let initial_balance = INITIAL_BALANCE * 2;
|
|
1426
|
+
setup_staking_contract(aptos_framework, staker, operator, initial_balance, 10);
|
|
1427
|
+
let staker_address = signer::address_of(staker);
|
|
1428
|
+
let operator_address = signer::address_of(operator);
|
|
1429
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1430
|
+
|
|
1431
|
+
// Operator joins the validator set so rewards are generated.
|
|
1432
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1433
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1434
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1435
|
+
|
|
1436
|
+
// Fast forward to generate rewards.
|
|
1437
|
+
stake::end_epoch();
|
|
1438
|
+
let new_balance = with_rewards(initial_balance);
|
|
1439
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1440
|
+
|
|
1441
|
+
// Staker withdraws 1/4 of the stake, which should also request commission distribution.
|
|
1442
|
+
let withdrawn_stake = new_balance / 4;
|
|
1443
|
+
let unpaid_commission = (new_balance - initial_balance) / 10;
|
|
1444
|
+
let new_balance = new_balance - withdrawn_stake - unpaid_commission;
|
|
1445
|
+
unlock_stake(staker, operator_address, withdrawn_stake);
|
|
1446
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, withdrawn_stake + unpaid_commission);
|
|
1447
|
+
assert_distribution(staker_address, operator_address, operator_address, unpaid_commission);
|
|
1448
|
+
assert_distribution(staker_address, operator_address, staker_address, withdrawn_stake);
|
|
1449
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1450
|
+
|
|
1451
|
+
// The validator is still in the active set as its remaining stake is still above min required.
|
|
1452
|
+
stake::fast_forward_to_unlock(pool_address);
|
|
1453
|
+
new_balance = with_rewards(new_balance);
|
|
1454
|
+
unpaid_commission = with_rewards(unpaid_commission);
|
|
1455
|
+
// Commission should still be charged on the rewards on top of withdrawn_stake.
|
|
1456
|
+
// So the operator should receive 10% of the rewards on top of withdrawn_stake.
|
|
1457
|
+
let commission_on_withdrawn_stake = (with_rewards(withdrawn_stake) - withdrawn_stake) / 10;
|
|
1458
|
+
unpaid_commission = unpaid_commission + commission_on_withdrawn_stake;
|
|
1459
|
+
withdrawn_stake = with_rewards(withdrawn_stake) - commission_on_withdrawn_stake;
|
|
1460
|
+
stake::assert_stake_pool(pool_address, new_balance, withdrawn_stake + unpaid_commission, 0, 0);
|
|
1461
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 0);
|
|
1462
|
+
|
|
1463
|
+
// Distribute and verify balances.
|
|
1464
|
+
distribute(staker_address, operator_address);
|
|
1465
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1466
|
+
let operator_balance = coin::balance<AptosCoin>(operator_address);
|
|
1467
|
+
assert!(operator_balance == initial_balance + unpaid_commission, operator_balance);
|
|
1468
|
+
let staker_balance = coin::balance<AptosCoin>(staker_address);
|
|
1469
|
+
assert!(staker_balance == withdrawn_stake, staker_balance);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1473
|
+
public entry fun test_staker_can_withdraw_partial_stake_if_operator_never_joined_validator_set(
|
|
1474
|
+
aptos_framework: &signer, staker: &signer, operator: &signer) acquires Store, BeneficiaryForOperator {
|
|
1475
|
+
let initial_balance = INITIAL_BALANCE * 2;
|
|
1476
|
+
setup_staking_contract(aptos_framework, staker, operator, initial_balance, 10);
|
|
1477
|
+
let staker_address = signer::address_of(staker);
|
|
1478
|
+
let operator_address = signer::address_of(operator);
|
|
1479
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1480
|
+
|
|
1481
|
+
// Epoch ended, but since validator never joined the set, no rewards were minted.
|
|
1482
|
+
stake::end_epoch();
|
|
1483
|
+
stake::assert_stake_pool(pool_address, initial_balance, 0, 0, 0);
|
|
1484
|
+
|
|
1485
|
+
// Staker withdraws 1/4 of the stake, which doesn't create any commission distribution as there's no rewards.
|
|
1486
|
+
let withdrawn_stake = initial_balance / 4;
|
|
1487
|
+
let new_balance = initial_balance - withdrawn_stake;
|
|
1488
|
+
unlock_stake(staker, operator_address, withdrawn_stake);
|
|
1489
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, withdrawn_stake);
|
|
1490
|
+
assert_distribution(staker_address, operator_address, operator_address, 0);
|
|
1491
|
+
assert_distribution(staker_address, operator_address, staker_address, withdrawn_stake);
|
|
1492
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1493
|
+
|
|
1494
|
+
// Distribute and verify balances.
|
|
1495
|
+
distribute(staker_address, operator_address);
|
|
1496
|
+
assert_no_pending_distributions(staker_address, operator_address);
|
|
1497
|
+
// Operator's balance shouldn't change as there are no rewards.
|
|
1498
|
+
let operator_balance = coin::balance<AptosCoin>(operator_address);
|
|
1499
|
+
assert!(operator_balance == initial_balance, operator_balance);
|
|
1500
|
+
// Staker receives back the withdrawn amount (no rewards).
|
|
1501
|
+
let staker_balance = coin::balance<AptosCoin>(staker_address);
|
|
1502
|
+
assert!(staker_balance == withdrawn_stake, staker_balance);
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1506
|
+
public entry fun test_multiple_distributions_added_before_distribute(
|
|
1507
|
+
aptos_framework: &signer, staker: &signer, operator: &signer) acquires Store, BeneficiaryForOperator {
|
|
1508
|
+
let initial_balance = INITIAL_BALANCE * 2;
|
|
1509
|
+
setup_staking_contract(aptos_framework, staker, operator, initial_balance, 10);
|
|
1510
|
+
let staker_address = signer::address_of(staker);
|
|
1511
|
+
let operator_address = signer::address_of(operator);
|
|
1512
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1513
|
+
|
|
1514
|
+
// Operator joins the validator set so rewards are generated.
|
|
1515
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1516
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1517
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1518
|
+
|
|
1519
|
+
// Fast forward to generate rewards.
|
|
1520
|
+
stake::end_epoch();
|
|
1521
|
+
let new_balance = with_rewards(initial_balance);
|
|
1522
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, 0);
|
|
1523
|
+
|
|
1524
|
+
// Staker withdraws 1/4 of the stake, which should also request commission distribution.
|
|
1525
|
+
let withdrawn_stake = new_balance / 4;
|
|
1526
|
+
let unpaid_commission = (new_balance - initial_balance) / 10;
|
|
1527
|
+
let new_balance = new_balance - withdrawn_stake - unpaid_commission;
|
|
1528
|
+
unlock_stake(staker, operator_address, withdrawn_stake);
|
|
1529
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, withdrawn_stake + unpaid_commission);
|
|
1530
|
+
assert_distribution(staker_address, operator_address, operator_address, unpaid_commission);
|
|
1531
|
+
assert_distribution(staker_address, operator_address, staker_address, withdrawn_stake);
|
|
1532
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1533
|
+
|
|
1534
|
+
// End epoch to generate some rewards. Staker withdraws another 1/4 of the stake.
|
|
1535
|
+
// Commission should be charged on the rewards earned on the previous 1/4 stake withdrawal.
|
|
1536
|
+
stake::end_epoch();
|
|
1537
|
+
let commission_on_withdrawn_stake = (with_rewards(withdrawn_stake) - withdrawn_stake) / 10;
|
|
1538
|
+
let commission_on_new_balance = (with_rewards(new_balance) - new_balance) / 10;
|
|
1539
|
+
unpaid_commission = with_rewards(unpaid_commission) + commission_on_withdrawn_stake + commission_on_new_balance;
|
|
1540
|
+
new_balance = with_rewards(new_balance) - commission_on_new_balance;
|
|
1541
|
+
let new_withdrawn_stake = new_balance / 4;
|
|
1542
|
+
unlock_stake(staker, operator_address, new_withdrawn_stake);
|
|
1543
|
+
new_balance = new_balance - new_withdrawn_stake;
|
|
1544
|
+
withdrawn_stake = with_rewards(withdrawn_stake) - commission_on_withdrawn_stake + new_withdrawn_stake;
|
|
1545
|
+
stake::assert_stake_pool(pool_address, new_balance, 0, 0, withdrawn_stake + unpaid_commission);
|
|
1546
|
+
// There's some small rounding error here.
|
|
1547
|
+
assert_distribution(staker_address, operator_address, operator_address, unpaid_commission - 1);
|
|
1548
|
+
assert_distribution(staker_address, operator_address, staker_address, withdrawn_stake);
|
|
1549
|
+
assert!(last_recorded_principal(staker_address, operator_address) == new_balance, 0);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
#[test(aptos_framework = @0x1, staker = @0x123, operator = @0x234)]
|
|
1553
|
+
public entry fun test_update_commission(
|
|
1554
|
+
aptos_framework: &signer,
|
|
1555
|
+
staker: &signer,
|
|
1556
|
+
operator: &signer
|
|
1557
|
+
) acquires Store, BeneficiaryForOperator, StakingGroupUpdateCommissionEvent {
|
|
1558
|
+
let initial_balance = INITIAL_BALANCE * 2;
|
|
1559
|
+
setup_staking_contract(aptos_framework, staker, operator, initial_balance, 10);
|
|
1560
|
+
let staker_address = signer::address_of(staker);
|
|
1561
|
+
let operator_address = signer::address_of(operator);
|
|
1562
|
+
let pool_address = stake_pool_address(staker_address, operator_address);
|
|
1563
|
+
|
|
1564
|
+
// Operator joins the validator set so rewards are generated.
|
|
1565
|
+
let (_sk, pk, pop) = stake::generate_identity();
|
|
1566
|
+
stake::join_validator_set_for_test(&pk, &pop, operator, pool_address, true);
|
|
1567
|
+
assert!(stake::get_validator_state(pool_address) == VALIDATOR_STATUS_ACTIVE, 1);
|
|
1568
|
+
|
|
1569
|
+
// Fast forward to generate rewards.
|
|
1570
|
+
stake::end_epoch();
|
|
1571
|
+
let balance_1epoch = with_rewards(initial_balance);
|
|
1572
|
+
let unpaid_commission = (balance_1epoch - initial_balance) / 10;
|
|
1573
|
+
stake::assert_stake_pool(pool_address, balance_1epoch, 0, 0, 0);
|
|
1574
|
+
|
|
1575
|
+
update_commision(staker, operator_address, 5);
|
|
1576
|
+
stake::end_epoch();
|
|
1577
|
+
let balance_2epoch = with_rewards(balance_1epoch - unpaid_commission);
|
|
1578
|
+
stake::assert_stake_pool(pool_address, balance_2epoch, 0, 0, with_rewards(unpaid_commission));
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
#[test(
|
|
1582
|
+
staker = @0xe256f4f4e2986cada739e339895cf5585082ff247464cab8ec56eea726bd2263,
|
|
1583
|
+
operator = @0x9f0a211d218b082987408f1e393afe1ba0c202c6d280f081399788d3360c7f09
|
|
1584
|
+
)]
|
|
1585
|
+
public entry fun test_get_expected_stake_pool_address(staker: address, operator: address) {
|
|
1586
|
+
let pool_address = get_expected_stake_pool_address(staker, operator, vector[0x42, 0x42]);
|
|
1587
|
+
assert!(pool_address == @0x9d9648031ada367c26f7878eb0b0406ae6a969b1a43090269e5cdfabe1b48f0f, 0);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
#[test_only]
|
|
1591
|
+
public fun assert_staking_contract(
|
|
1592
|
+
staker: address, operator: address, principal: u64, commission_percentage: u64) acquires Store {
|
|
1593
|
+
let staking_contract = simple_map::borrow(&borrow_global<Store>(staker).staking_contracts, &operator);
|
|
1594
|
+
assert!(staking_contract.principal == principal, staking_contract.principal);
|
|
1595
|
+
assert!(
|
|
1596
|
+
staking_contract.commission_percentage == commission_percentage,
|
|
1597
|
+
staking_contract.commission_percentage
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
#[test_only]
|
|
1602
|
+
public fun assert_no_pending_distributions(staker: address, operator: address) acquires Store {
|
|
1603
|
+
let staking_contract = simple_map::borrow(&borrow_global<Store>(staker).staking_contracts, &operator);
|
|
1604
|
+
let distribution_pool = &staking_contract.distribution_pool;
|
|
1605
|
+
let shareholders_count = pool_u64::shareholders_count(distribution_pool);
|
|
1606
|
+
assert!(shareholders_count == 0, shareholders_count);
|
|
1607
|
+
let total_coins_remaining = pool_u64::total_coins(distribution_pool);
|
|
1608
|
+
assert!(total_coins_remaining == 0, total_coins_remaining);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
#[test_only]
|
|
1612
|
+
public fun assert_distribution(
|
|
1613
|
+
staker: address, operator: address, recipient: address, coins_amount: u64) acquires Store {
|
|
1614
|
+
let staking_contract = simple_map::borrow(&borrow_global<Store>(staker).staking_contracts, &operator);
|
|
1615
|
+
let distribution_balance = pool_u64::balance(&staking_contract.distribution_pool, recipient);
|
|
1616
|
+
assert!(distribution_balance == coins_amount, distribution_balance);
|
|
1617
|
+
}
|
|
1618
|
+
}
|