@audius/sdk 0.0.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/.eslintrc +38 -0
- package/.prettierrc.js +1 -0
- package/.python-version +1 -0
- package/Dockerfile +15 -0
- package/README.md +3 -0
- package/babel.config.js +3 -0
- package/data-contracts/ABIs/AdminUpgradeabilityProxy.json +132 -0
- package/data-contracts/ABIs/BaseAdminUpgradeabilityProxy.json +113 -0
- package/data-contracts/ABIs/BaseUpgradeabilityProxy.json +22 -0
- package/data-contracts/ABIs/DiscoveryProviderFactory.json +189 -0
- package/data-contracts/ABIs/DiscoveryProviderFactoryInterface.json +61 -0
- package/data-contracts/ABIs/DiscoveryProviderStorage.json +205 -0
- package/data-contracts/ABIs/DiscoveryProviderStorageInterface.json +65 -0
- package/data-contracts/ABIs/ECDSA.json +4 -0
- package/data-contracts/ABIs/IPLDBlacklistFactory.json +168 -0
- package/data-contracts/ABIs/Initializable.json +4 -0
- package/data-contracts/ABIs/Migrations.json +67 -0
- package/data-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
- package/data-contracts/ABIs/Ownable.json +79 -0
- package/data-contracts/ABIs/PlaylistFactory.json +669 -0
- package/data-contracts/ABIs/PlaylistFactoryInterface.json +42 -0
- package/data-contracts/ABIs/PlaylistStorage.json +250 -0
- package/data-contracts/ABIs/PlaylistStorageInterface.json +129 -0
- package/data-contracts/ABIs/Proxy.json +10 -0
- package/data-contracts/ABIs/Registry.json +240 -0
- package/data-contracts/ABIs/RegistryContract.json +102 -0
- package/data-contracts/ABIs/RegistryContractInterface.json +28 -0
- package/data-contracts/ABIs/RegistryInterface.json +66 -0
- package/data-contracts/ABIs/SigningLogic.json +43 -0
- package/data-contracts/ABIs/SigningLogicInitializable.json +46 -0
- package/data-contracts/ABIs/SocialFeatureFactory.json +460 -0
- package/data-contracts/ABIs/SocialFeatureStorage.json +225 -0
- package/data-contracts/ABIs/SocialFeatureStorageInterface.json +123 -0
- package/data-contracts/ABIs/TestContract.json +135 -0
- package/data-contracts/ABIs/TestContractInterface.json +19 -0
- package/data-contracts/ABIs/TestContractWithStorage.json +165 -0
- package/data-contracts/ABIs/TestContractWithStorageInterface.json +24 -0
- package/data-contracts/ABIs/TestStorage.json +144 -0
- package/data-contracts/ABIs/TestStorageInterface.json +42 -0
- package/data-contracts/ABIs/TestUserReplicaSetManager.json +432 -0
- package/data-contracts/ABIs/TrackFactory.json +391 -0
- package/data-contracts/ABIs/TrackFactoryInterface.json +73 -0
- package/data-contracts/ABIs/TrackStorage.json +223 -0
- package/data-contracts/ABIs/TrackStorageInterface.json +121 -0
- package/data-contracts/ABIs/UpgradeabilityProxy.json +37 -0
- package/data-contracts/ABIs/UserFactory.json +657 -0
- package/data-contracts/ABIs/UserFactoryInterface.json +65 -0
- package/data-contracts/ABIs/UserLibraryFactory.json +334 -0
- package/data-contracts/ABIs/UserReplicaSetManager.json +418 -0
- package/data-contracts/ABIs/UserStorage.json +233 -0
- package/data-contracts/ABIs/UserStorageInterface.json +93 -0
- package/data-contracts/signatureSchemas.ts +1236 -0
- package/dist/core.d.ts +446 -0
- package/dist/core.js +769 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +689 -0
- package/dist/index.js +72850 -0
- package/dist/index.js.map +1 -0
- package/eth-contracts/ABIs/Address.json +4 -0
- package/eth-contracts/ABIs/AudiusAdminUpgradeabilityProxy.json +105 -0
- package/eth-contracts/ABIs/AudiusClaimDistributor.json +4968 -0
- package/eth-contracts/ABIs/AudiusToken.json +724 -0
- package/eth-contracts/ABIs/BaseUpgradeabilityProxy.json +23 -0
- package/eth-contracts/ABIs/Checkpointing.json +4 -0
- package/eth-contracts/ABIs/ClaimsManager.json +539 -0
- package/eth-contracts/ABIs/Context.json +11 -0
- package/eth-contracts/ABIs/DelegateManager.json +989 -0
- package/eth-contracts/ABIs/DelegateManagerV2.json +1049 -0
- package/eth-contracts/ABIs/DelegateManagerV2Bad.json +1049 -0
- package/eth-contracts/ABIs/ERC20.json +252 -0
- package/eth-contracts/ABIs/ERC20Burnable.json +287 -0
- package/eth-contracts/ABIs/ERC20Detailed.json +270 -0
- package/eth-contracts/ABIs/ERC20Mintable.json +364 -0
- package/eth-contracts/ABIs/ERC20Pausable.json +397 -0
- package/eth-contracts/ABIs/EthRewardsManager.json +174 -0
- package/eth-contracts/ABIs/Governance.json +938 -0
- package/eth-contracts/ABIs/GovernanceUpgraded.json +953 -0
- package/eth-contracts/ABIs/GovernanceV2.json +938 -0
- package/eth-contracts/ABIs/IERC20.json +200 -0
- package/eth-contracts/ABIs/Initializable.json +4 -0
- package/eth-contracts/ABIs/InitializableV2.json +14 -0
- package/eth-contracts/ABIs/Migrations.json +71 -0
- package/eth-contracts/ABIs/MinterRole.json +91 -0
- package/eth-contracts/ABIs/MockAccount.json +62 -0
- package/eth-contracts/ABIs/MockDelegateManager.json +55 -0
- package/eth-contracts/ABIs/MockStakingCaller.json +259 -0
- package/eth-contracts/ABIs/MockWormhole.json +106 -0
- package/eth-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
- package/eth-contracts/ABIs/Ownable.json +93 -0
- package/eth-contracts/ABIs/Pausable.json +150 -0
- package/eth-contracts/ABIs/PauserRole.json +91 -0
- package/eth-contracts/ABIs/Proxy.json +10 -0
- package/eth-contracts/ABIs/Registry.json +288 -0
- package/eth-contracts/ABIs/Roles.json +4 -0
- package/eth-contracts/ABIs/SafeERC20.json +4 -0
- package/eth-contracts/ABIs/SafeMath.json +4 -0
- package/eth-contracts/ABIs/ServiceProviderFactory.json +1153 -0
- package/eth-contracts/ABIs/ServiceTypeManager.json +337 -0
- package/eth-contracts/ABIs/Staking.json +555 -0
- package/eth-contracts/ABIs/StakingUpgraded.json +570 -0
- package/eth-contracts/ABIs/TestContract.json +44 -0
- package/eth-contracts/ABIs/TrustedNotifierManager.json +265 -0
- package/eth-contracts/ABIs/Uint256Helpers.json +4 -0
- package/eth-contracts/ABIs/UpgradeabilityProxy.json +40 -0
- package/eth-contracts/ABIs/Wormhole.json +45 -0
- package/eth-contracts/ABIs/WormholeClient.json +155 -0
- package/examples/file.mp3 +0 -0
- package/examples/initAudiusLibs.js +86 -0
- package/examples/initializeVersions.js +95 -0
- package/examples/pic.jpg +0 -0
- package/initScripts/configureLocalDiscProv.js +167 -0
- package/initScripts/helpers/claim.js +43 -0
- package/initScripts/helpers/distributeTokens.js +24 -0
- package/initScripts/helpers/spRegistration.js +138 -0
- package/initScripts/helpers/utils.js +34 -0
- package/initScripts/helpers/version.js +93 -0
- package/initScripts/local.js +617 -0
- package/initScripts/mainnet.js +131 -0
- package/initScripts/manageProdRelayerWallets.js +191 -0
- package/package.json +125 -0
- package/rollup.config.js +164 -0
- package/scripts/AudiusClaimDistributor.json +4968 -0
- package/scripts/Wormhole.json +155 -0
- package/scripts/addCIDToIpldBlacklist.js +124 -0
- package/scripts/circleci-test.sh +53 -0
- package/scripts/communityRewards/transferCommunityRewardsToSolana.js +222 -0
- package/scripts/ipfs.sh +58 -0
- package/scripts/migrate_contracts.sh +25 -0
- package/scripts/reset.sh +65 -0
- package/scripts/test.sh +77 -0
- package/src/api/account.js +670 -0
- package/src/api/base.js +122 -0
- package/src/api/file.js +168 -0
- package/src/api/playlist.js +328 -0
- package/src/api/rewards.d.ts +4 -0
- package/src/api/rewards.js +682 -0
- package/src/api/serviceProvider.js +154 -0
- package/src/api/track.js +604 -0
- package/src/api/user.js +888 -0
- package/src/api/user.test.js +172 -0
- package/src/constants.ts +7 -0
- package/src/core.ts +3 -0
- package/src/index.js +6 -0
- package/src/libs.d.ts +3 -0
- package/src/libs.js +619 -0
- package/src/sanityChecks/addSecondaries.js +40 -0
- package/src/sanityChecks/assignReplicaSetIfNecessary.js +10 -0
- package/src/sanityChecks/index.d.ts +9 -0
- package/src/sanityChecks/index.js +31 -0
- package/src/sanityChecks/isCreator.js +73 -0
- package/src/sanityChecks/needsRecoveryEmail.js +20 -0
- package/src/sanityChecks/rolloverNodes.js +74 -0
- package/src/sanityChecks/sanitizeNodes.js +24 -0
- package/src/sanityChecks/syncNodes.js +28 -0
- package/src/sdk/constants.ts +10 -0
- package/src/sdk/index.ts +1 -0
- package/src/sdk/oauth/Oauth.ts +265 -0
- package/src/sdk/oauth/index.ts +1 -0
- package/src/sdk/sdk.ts +102 -0
- package/src/service-selection/ServiceSelection.test.ts +320 -0
- package/src/service-selection/ServiceSelection.ts +460 -0
- package/src/service-selection/constants.ts +14 -0
- package/src/service-selection/index.ts +1 -0
- package/src/services/ABIDecoder/AudiusABIDecoder.ts +71 -0
- package/src/services/ABIDecoder/index.ts +1 -0
- package/src/services/comstock/Comstock.ts +39 -0
- package/src/services/comstock/index.ts +1 -0
- package/src/services/contracts/ContractClient.ts +227 -0
- package/src/services/contracts/GovernedContractClient.ts +53 -0
- package/src/services/contracts/ProviderSelection.ts +42 -0
- package/src/services/creatorNode/CreatorNode.ts +1065 -0
- package/src/services/creatorNode/CreatorNodeSelection.test.ts +997 -0
- package/src/services/creatorNode/CreatorNodeSelection.ts +488 -0
- package/src/services/creatorNode/constants.ts +10 -0
- package/src/services/creatorNode/index.ts +2 -0
- package/src/services/dataContracts/AudiusContracts.ts +234 -0
- package/src/services/dataContracts/IPLDBlacklistFactoryClient.ts +73 -0
- package/src/services/dataContracts/PlaylistFactoryClient.ts +370 -0
- package/src/services/dataContracts/RegistryClient.ts +95 -0
- package/src/services/dataContracts/SocialFeatureFactoryClient.ts +196 -0
- package/src/services/dataContracts/TrackFactoryClient.ts +131 -0
- package/src/services/dataContracts/UserFactoryClient.ts +351 -0
- package/src/services/dataContracts/UserLibraryFactoryClient.ts +115 -0
- package/src/services/dataContracts/UserReplicaSetManagerClient.ts +206 -0
- package/src/services/dataContracts/index.ts +1 -0
- package/src/services/discoveryProvider/DiscoveryProvider.ts +1168 -0
- package/src/services/discoveryProvider/DiscoveryProviderSelection.test.ts +536 -0
- package/src/services/discoveryProvider/DiscoveryProviderSelection.ts +383 -0
- package/src/services/discoveryProvider/constants.ts +13 -0
- package/src/services/discoveryProvider/index.ts +1 -0
- package/src/services/discoveryProvider/requests.ts +629 -0
- package/src/services/ethContracts/AudiusTokenClient.ts +163 -0
- package/src/services/ethContracts/ClaimDistributionClient.ts +45 -0
- package/src/services/ethContracts/ClaimsManagerClient.ts +102 -0
- package/src/services/ethContracts/DelegateManagerClient.ts +480 -0
- package/src/services/ethContracts/EthContracts.ts +359 -0
- package/src/services/ethContracts/EthRewardsManagerClient.ts +33 -0
- package/src/services/ethContracts/GovernanceClient.ts +451 -0
- package/src/services/ethContracts/RegistryClient.ts +33 -0
- package/src/services/ethContracts/ServiceProviderFactoryClient.ts +691 -0
- package/src/services/ethContracts/ServiceTypeManagerClient.ts +112 -0
- package/src/services/ethContracts/StakingProxyClient.ts +97 -0
- package/src/services/ethContracts/TrustedNotifierManagerClient.ts +101 -0
- package/src/services/ethContracts/WormholeClient.ts +97 -0
- package/src/services/ethContracts/index.ts +1 -0
- package/src/services/ethWeb3Manager/EthWeb3Manager.ts +239 -0
- package/src/services/ethWeb3Manager/index.ts +1 -0
- package/src/services/hedgehog/Hedgehog.ts +96 -0
- package/src/services/hedgehog/index.ts +1 -0
- package/src/services/identity/IdentityService.ts +551 -0
- package/src/services/identity/index.ts +1 -0
- package/src/services/identity/requests.ts +65 -0
- package/src/services/schemaValidator/SchemaValidator.ts +105 -0
- package/src/services/schemaValidator/index.ts +1 -0
- package/src/services/schemaValidator/schemas/trackSchema.json +267 -0
- package/src/services/schemaValidator/schemas/userSchema.json +230 -0
- package/src/services/solanaAudiusData/errors.ts +20 -0
- package/src/services/solanaAudiusData/index.ts +1189 -0
- package/src/services/solanaWeb3Manager/errors.js +101 -0
- package/src/services/solanaWeb3Manager/index.d.ts +46 -0
- package/src/services/solanaWeb3Manager/index.js +655 -0
- package/src/services/solanaWeb3Manager/padBNToUint8Array.ts +7 -0
- package/src/services/solanaWeb3Manager/rewards.js +941 -0
- package/src/services/solanaWeb3Manager/rewardsAttester.ts +1093 -0
- package/src/services/solanaWeb3Manager/tokenAccount.js +149 -0
- package/src/services/solanaWeb3Manager/transactionHandler.js +345 -0
- package/src/services/solanaWeb3Manager/transfer.js +272 -0
- package/src/services/solanaWeb3Manager/userBank.js +160 -0
- package/src/services/solanaWeb3Manager/utils.d.ts +31 -0
- package/src/services/solanaWeb3Manager/utils.js +163 -0
- package/src/services/solanaWeb3Manager/wAudio.js +28 -0
- package/src/services/solanaWeb3Manager/wAudio.test.js +30 -0
- package/src/services/web3Manager/Web3Config.ts +14 -0
- package/src/services/web3Manager/Web3Manager.ts +360 -0
- package/src/services/web3Manager/XMLHttpRequest.ts +11 -0
- package/src/services/web3Manager/index.ts +2 -0
- package/src/services/wormhole/index.js +424 -0
- package/src/types.ts +8 -0
- package/src/userStateManager.ts +53 -0
- package/src/utils/apiSigning.ts +51 -0
- package/src/utils/captcha.ts +97 -0
- package/src/utils/estimateGas.ts +64 -0
- package/src/utils/fileHasher.ts +278 -0
- package/src/utils/importContractABI.d.ts +9 -0
- package/src/utils/importContractABI.js +19 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/multiProvider.ts +72 -0
- package/src/utils/network.test.ts +127 -0
- package/src/utils/network.ts +308 -0
- package/src/utils/promiseFight.test.ts +87 -0
- package/src/utils/promiseFight.ts +36 -0
- package/src/utils/signatures.ts +139 -0
- package/src/utils/types.ts +34 -0
- package/src/utils/utils.test.ts +36 -0
- package/src/utils/utils.ts +235 -0
- package/src/utils/uuid.ts +14 -0
- package/src/web3.d.ts +9 -0
- package/src/web3.js +8 -0
- package/tests/assets/static_image.png +0 -0
- package/tests/assets/static_text.txt +1 -0
- package/tests/audiusTokenClientTest.js +37 -0
- package/tests/creatorNodeTest.js +19 -0
- package/tests/fileHasherTest.js +125 -0
- package/tests/governanceTest.js +382 -0
- package/tests/helpers.js +105 -0
- package/tests/index.js +14 -0
- package/tests/playlistClientTest.js +157 -0
- package/tests/providerSelectionTest.js +241 -0
- package/tests/registryClientTest.js +19 -0
- package/tests/rewardsAttesterTest.js +373 -0
- package/tests/serviceTypeManagerClientTest.js +33 -0
- package/tests/socialFeatureClientTest.js +79 -0
- package/tests/stakingTest.js +302 -0
- package/tests/trackClientTest.js +86 -0
- package/tests/userClientTest.js +121 -0
- package/tsconfig.json +10 -0
- package/types/@audius-hedgehog/index.d.ts +39 -0
- package/types/abi-decoder/index.d.ts +41 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type Web3 from 'web3'
|
|
2
|
+
import type { EthWeb3Manager } from '../ethWeb3Manager'
|
|
3
|
+
import type { Contract } from 'web3-eth-contract'
|
|
4
|
+
import type { AbiItem } from 'web3-utils'
|
|
5
|
+
import type BN from 'bn.js'
|
|
6
|
+
|
|
7
|
+
export class AudiusTokenClient {
|
|
8
|
+
ethWeb3Manager: EthWeb3Manager
|
|
9
|
+
contractABI: AbiItem[]
|
|
10
|
+
contractAddress: string
|
|
11
|
+
web3: Web3
|
|
12
|
+
AudiusTokenContract: Contract
|
|
13
|
+
bustCacheNonce: number
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
ethWeb3Manager: EthWeb3Manager,
|
|
17
|
+
contractABI: AbiItem[],
|
|
18
|
+
contractAddress: string
|
|
19
|
+
) {
|
|
20
|
+
this.ethWeb3Manager = ethWeb3Manager
|
|
21
|
+
this.contractABI = contractABI
|
|
22
|
+
this.contractAddress = contractAddress
|
|
23
|
+
|
|
24
|
+
this.web3 = this.ethWeb3Manager.getWeb3()
|
|
25
|
+
this.AudiusTokenContract = new this.web3.eth.Contract(
|
|
26
|
+
this.contractABI,
|
|
27
|
+
this.contractAddress
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
this.bustCacheNonce = 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* ------- GETTERS ------- */
|
|
34
|
+
|
|
35
|
+
async bustCache() {
|
|
36
|
+
this.bustCacheNonce += 1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async balanceOf(account: string) {
|
|
40
|
+
let args
|
|
41
|
+
if (this.bustCacheNonce > 0) {
|
|
42
|
+
args = { _audiusBustCache: this.bustCacheNonce }
|
|
43
|
+
}
|
|
44
|
+
const balance = await this.AudiusTokenContract.methods
|
|
45
|
+
.balanceOf(account)
|
|
46
|
+
.call(args)
|
|
47
|
+
return this.web3.utils.toBN(balance)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Get the name of the contract
|
|
51
|
+
async name() {
|
|
52
|
+
const name = await this.AudiusTokenContract.methods.name().call()
|
|
53
|
+
return name
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Get the name of the contract
|
|
57
|
+
async nonces(wallet: string) {
|
|
58
|
+
// Pass along a unique param so the nonce value is always not cached
|
|
59
|
+
const nonce = await this.AudiusTokenContract.methods.nonces(wallet).call({
|
|
60
|
+
_audiusBustCache: Date.now()
|
|
61
|
+
})
|
|
62
|
+
const number = this.web3.utils.toBN(nonce).toNumber()
|
|
63
|
+
return number
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* ------- SETTERS ------- */
|
|
67
|
+
|
|
68
|
+
async transfer(recipient: string, amount: BN) {
|
|
69
|
+
const contractMethod = this.AudiusTokenContract.methods.transfer(
|
|
70
|
+
recipient,
|
|
71
|
+
amount
|
|
72
|
+
)
|
|
73
|
+
const tx = await this.ethWeb3Manager.sendTransaction(contractMethod)
|
|
74
|
+
return { txReceipt: tx }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async transferFrom(
|
|
78
|
+
owner: string,
|
|
79
|
+
recipient: string,
|
|
80
|
+
relayer: string,
|
|
81
|
+
amount: BN
|
|
82
|
+
) {
|
|
83
|
+
const method = this.AudiusTokenContract.methods.transferFrom(
|
|
84
|
+
owner,
|
|
85
|
+
recipient,
|
|
86
|
+
amount
|
|
87
|
+
)
|
|
88
|
+
const tx = await this.ethWeb3Manager.relayTransaction(
|
|
89
|
+
method,
|
|
90
|
+
this.contractAddress,
|
|
91
|
+
owner,
|
|
92
|
+
relayer,
|
|
93
|
+
/* retries */ 0
|
|
94
|
+
)
|
|
95
|
+
return { txReceipt: tx }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Permit meta transaction of balance transfer
|
|
99
|
+
async permit(
|
|
100
|
+
owner: string, // address
|
|
101
|
+
spender: string, // address
|
|
102
|
+
value: BN, // uint
|
|
103
|
+
deadline: number, // uint
|
|
104
|
+
v: number, // uint8
|
|
105
|
+
r: Uint8Array | Buffer, // bytes32
|
|
106
|
+
s: Uint8Array | Buffer // bytes32
|
|
107
|
+
) {
|
|
108
|
+
const contractMethod = this.AudiusTokenContract.methods.permit(
|
|
109
|
+
owner,
|
|
110
|
+
spender,
|
|
111
|
+
value,
|
|
112
|
+
deadline,
|
|
113
|
+
v,
|
|
114
|
+
r,
|
|
115
|
+
s
|
|
116
|
+
)
|
|
117
|
+
const tx = await this.ethWeb3Manager.relayTransaction(
|
|
118
|
+
contractMethod,
|
|
119
|
+
this.contractAddress,
|
|
120
|
+
owner,
|
|
121
|
+
spender,
|
|
122
|
+
/* retries */ 0
|
|
123
|
+
)
|
|
124
|
+
return tx
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Allow spender to withdraw from calling account up to value amount
|
|
128
|
+
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
|
|
129
|
+
async approve(spender: string, value: BN, privateKey = null) {
|
|
130
|
+
const contractMethod = this.AudiusTokenContract.methods.approve(
|
|
131
|
+
spender,
|
|
132
|
+
value
|
|
133
|
+
)
|
|
134
|
+
let tx
|
|
135
|
+
if (privateKey === null) {
|
|
136
|
+
tx = await this.ethWeb3Manager.sendTransaction(contractMethod)
|
|
137
|
+
} else {
|
|
138
|
+
tx = await this.ethWeb3Manager.sendTransaction(
|
|
139
|
+
contractMethod,
|
|
140
|
+
this.contractAddress,
|
|
141
|
+
privateKey
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
return { txReceipt: tx }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async approveProxyTokens(
|
|
148
|
+
owner: string,
|
|
149
|
+
spender: string,
|
|
150
|
+
value: BN,
|
|
151
|
+
relayer: string
|
|
152
|
+
) {
|
|
153
|
+
const method = this.AudiusTokenContract.methods.approve(spender, value)
|
|
154
|
+
const tx = await this.ethWeb3Manager.relayTransaction(
|
|
155
|
+
method,
|
|
156
|
+
this.contractAddress,
|
|
157
|
+
owner,
|
|
158
|
+
relayer,
|
|
159
|
+
/* retries */ 0
|
|
160
|
+
)
|
|
161
|
+
return { txReceipt: tx }
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type BN from 'bn.js'
|
|
2
|
+
import { ContractClient } from '../contracts/ContractClient'
|
|
3
|
+
import type { EthWeb3Manager } from '../ethWeb3Manager'
|
|
4
|
+
|
|
5
|
+
export class ClaimDistributionClient extends ContractClient {
|
|
6
|
+
// ===================== Contract Methods =====================
|
|
7
|
+
/**
|
|
8
|
+
* Calls the contract method to check if the claim index has been claimed
|
|
9
|
+
*/
|
|
10
|
+
async isClaimed(index: number) {
|
|
11
|
+
const method = await this.getMethod('isClaimed', index)
|
|
12
|
+
const isClaimed = await method.call()
|
|
13
|
+
return isClaimed
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Proxies the calls the contract method to make a claim
|
|
18
|
+
* @param index
|
|
19
|
+
* @param account
|
|
20
|
+
* @param amount
|
|
21
|
+
* @param merkleProof
|
|
22
|
+
* @returns transaction
|
|
23
|
+
*/
|
|
24
|
+
async claim(
|
|
25
|
+
index: number,
|
|
26
|
+
account: string,
|
|
27
|
+
amount: BN,
|
|
28
|
+
merkleProof: string[]
|
|
29
|
+
) {
|
|
30
|
+
const method = await this.getMethod(
|
|
31
|
+
'claim',
|
|
32
|
+
index,
|
|
33
|
+
account,
|
|
34
|
+
amount,
|
|
35
|
+
merkleProof
|
|
36
|
+
)
|
|
37
|
+
const contractAddress = await this.getAddress()
|
|
38
|
+
const tx = await (this.web3Manager as EthWeb3Manager).relayTransaction(
|
|
39
|
+
method,
|
|
40
|
+
contractAddress,
|
|
41
|
+
account
|
|
42
|
+
)
|
|
43
|
+
return tx
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Utils } from '../../utils'
|
|
2
|
+
import { ContractClient } from '../contracts/ContractClient'
|
|
3
|
+
import type { EthWeb3Manager } from '../ethWeb3Manager'
|
|
4
|
+
|
|
5
|
+
export class ClaimsManagerClient extends ContractClient {
|
|
6
|
+
// @ts-expect-error defined in ContractClient
|
|
7
|
+
override web3Manager: EthWeb3Manager
|
|
8
|
+
/* ------- GETTERS ------- */
|
|
9
|
+
|
|
10
|
+
// Get the duration of a funding round in blocks
|
|
11
|
+
async getFundingRoundBlockDiff() {
|
|
12
|
+
const method = await this.getMethod('getFundingRoundBlockDiff')
|
|
13
|
+
const info = await method.call()
|
|
14
|
+
return parseInt(info)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Get the last block where a funding round was initiated
|
|
18
|
+
async getLastFundedBlock() {
|
|
19
|
+
const method = await this.getMethod('getLastFundedBlock')
|
|
20
|
+
const info = await method.call()
|
|
21
|
+
return parseInt(info)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Get the amount funded per round in wei
|
|
25
|
+
async getFundsPerRound() {
|
|
26
|
+
const method = await this.getMethod('getFundsPerRound')
|
|
27
|
+
const info = await method.call()
|
|
28
|
+
return Utils.toBN(info)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Get the total amount claimed in the current round
|
|
32
|
+
async getTotalClaimedInRound() {
|
|
33
|
+
const method = await this.getMethod('getTotalClaimedInRound')
|
|
34
|
+
const info = await method.call()
|
|
35
|
+
return Utils.toBN(info)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Get the Governance address
|
|
39
|
+
async getGovernanceAddress() {
|
|
40
|
+
const method = await this.getMethod('getGovernanceAddress')
|
|
41
|
+
const info = await method.call()
|
|
42
|
+
return info
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get the ServiceProviderFactory address
|
|
46
|
+
async getServiceProviderFactoryAddress() {
|
|
47
|
+
const method = await this.getMethod('getServiceProviderFactoryAddress')
|
|
48
|
+
const info = await method.call()
|
|
49
|
+
return info
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Get the DelegateManager address
|
|
53
|
+
async getDelegateManagerAddress() {
|
|
54
|
+
const method = await this.getMethod('getDelegateManagerAddress')
|
|
55
|
+
const info = await method.call()
|
|
56
|
+
return info
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Get the Staking address
|
|
60
|
+
async getStakingAddress() {
|
|
61
|
+
const method = await this.getMethod('getStakingAddress')
|
|
62
|
+
const info = await method.call()
|
|
63
|
+
return info
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Returns boolean indicating whether a claim is considered pending
|
|
67
|
+
async claimPending(address: string) {
|
|
68
|
+
const method = await this.getMethod('claimPending', address)
|
|
69
|
+
const info = await method.call()
|
|
70
|
+
return info
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Returns boolean indicating whether a claim is considered pending
|
|
74
|
+
async initiateRound(txRetries = 5) {
|
|
75
|
+
const method = await this.getMethod('initiateRound')
|
|
76
|
+
return await this.web3Manager.sendTransaction(method, null, null, txRetries)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Fetches the claim processed events
|
|
80
|
+
async getClaimProcessedEvents({
|
|
81
|
+
claimer,
|
|
82
|
+
queryStartBlock = 0
|
|
83
|
+
}: {
|
|
84
|
+
claimer: string
|
|
85
|
+
queryStartBlock: number
|
|
86
|
+
}) {
|
|
87
|
+
const contract = await this.getContract()
|
|
88
|
+
const events = await contract.getPastEvents('ClaimProcessed', {
|
|
89
|
+
fromBlock: queryStartBlock,
|
|
90
|
+
filter: {
|
|
91
|
+
_claimer: claimer
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
return events.map((event) => ({
|
|
95
|
+
blockNumber: parseInt(event.blockNumber as unknown as string),
|
|
96
|
+
claimer: event.returnValues['_claimer'],
|
|
97
|
+
rewards: Utils.toBN(event.returnValues['_rewards']),
|
|
98
|
+
oldTotal: Utils.toBN(event.returnValues['_oldTotal']),
|
|
99
|
+
newTotal: Utils.toBN(event.returnValues['_newTotal'])
|
|
100
|
+
}))
|
|
101
|
+
}
|
|
102
|
+
}
|