Skip to content

Commit 86b66e6

Browse files
authored
Merge pull request #1881 from opentensor/feat/leasing-precompile
Leasing precompile
2 parents c3bad30 + 918fb41 commit 86b66e6

File tree

10 files changed

+823
-15
lines changed

10 files changed

+823
-15
lines changed

evm-tests/src/contracts/leasing.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
export const ILEASING_ADDRESS = "0x000000000000000000000000000000000000080a";
2+
3+
export const ILeasingABI = [
4+
{
5+
"inputs": [
6+
{
7+
"internalType": "uint64",
8+
"name": "crowdloanDeposit",
9+
"type": "uint64"
10+
},
11+
{
12+
"internalType": "uint64",
13+
"name": "crowdloanMinContribution",
14+
"type": "uint64"
15+
},
16+
{
17+
"internalType": "uint64",
18+
"name": "crowdloanCap",
19+
"type": "uint64"
20+
},
21+
{
22+
"internalType": "uint32",
23+
"name": "crowdloanEnd",
24+
"type": "uint32"
25+
},
26+
{
27+
"internalType": "uint8",
28+
"name": "leasingEmissionsShare",
29+
"type": "uint8"
30+
},
31+
{
32+
"internalType": "bool",
33+
"name": "hasLeasingEndBlock",
34+
"type": "bool"
35+
},
36+
{
37+
"internalType": "uint32",
38+
"name": "leasingEndBlock",
39+
"type": "uint32"
40+
}
41+
],
42+
"name": "createLeaseCrowdloan",
43+
"outputs": [],
44+
"stateMutability": "payable",
45+
"type": "function"
46+
},
47+
{
48+
"inputs": [
49+
{
50+
"internalType": "uint32",
51+
"name": "leaseId",
52+
"type": "uint32"
53+
},
54+
{
55+
"internalType": "bytes32",
56+
"name": "contributor",
57+
"type": "bytes32"
58+
}
59+
],
60+
"name": "getContributorShare",
61+
"outputs": [
62+
{
63+
"internalType": "uint128",
64+
"name": "",
65+
"type": "uint128"
66+
},
67+
{
68+
"internalType": "uint128",
69+
"name": "",
70+
"type": "uint128"
71+
}
72+
],
73+
"stateMutability": "view",
74+
"type": "function"
75+
},
76+
{
77+
"inputs": [
78+
{
79+
"internalType": "uint32",
80+
"name": "leaseId",
81+
"type": "uint32"
82+
}
83+
],
84+
"name": "getLease",
85+
"outputs": [
86+
{
87+
"components": [
88+
{
89+
"internalType": "bytes32",
90+
"name": "beneficiary",
91+
"type": "bytes32"
92+
},
93+
{
94+
"internalType": "bytes32",
95+
"name": "coldkey",
96+
"type": "bytes32"
97+
},
98+
{
99+
"internalType": "bytes32",
100+
"name": "hotkey",
101+
"type": "bytes32"
102+
},
103+
{
104+
"internalType": "uint8",
105+
"name": "emissions_share",
106+
"type": "uint8"
107+
},
108+
{
109+
"internalType": "bool",
110+
"name": "has_end_block",
111+
"type": "bool"
112+
},
113+
{
114+
"internalType": "uint32",
115+
"name": "end_block",
116+
"type": "uint32"
117+
},
118+
{
119+
"internalType": "uint16",
120+
"name": "netuid",
121+
"type": "uint16"
122+
},
123+
{
124+
"internalType": "uint64",
125+
"name": "cost",
126+
"type": "uint64"
127+
}
128+
],
129+
"internalType": "struct LeaseInfo",
130+
"name": "",
131+
"type": "tuple"
132+
}
133+
],
134+
"stateMutability": "view",
135+
"type": "function"
136+
},
137+
{
138+
"inputs": [
139+
{
140+
"internalType": "uint16",
141+
"name": "netuid",
142+
"type": "uint16"
143+
}
144+
],
145+
"name": "getLeaseIdForSubnet",
146+
"outputs": [
147+
{
148+
"internalType": "uint32",
149+
"name": "",
150+
"type": "uint32"
151+
}
152+
],
153+
"stateMutability": "view",
154+
"type": "function"
155+
},
156+
{
157+
"inputs": [
158+
{
159+
"internalType": "uint32",
160+
"name": "leaseId",
161+
"type": "uint32"
162+
},
163+
{
164+
"internalType": "bytes32",
165+
"name": "hotkey",
166+
"type": "bytes32"
167+
}
168+
],
169+
"name": "terminateLease",
170+
"outputs": [],
171+
"stateMutability": "payable",
172+
"type": "function"
173+
}
174+
]

evm-tests/src/substrate.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import * as assert from "assert";
21
import { devnet, MultiAddress } from '@polkadot-api/descriptors';
3-
import { createClient, TypedApi, Transaction, PolkadotSigner, Binary } from 'polkadot-api';
4-
import { getWsProvider } from 'polkadot-api/ws-provider/web';
2+
import { TypedApi, Transaction, PolkadotSigner, Binary } from 'polkadot-api';
53
import { sr25519CreateDerive } from "@polkadot-labs/hdkd"
6-
import { convertPublicKeyToSs58 } from "../src/address-utils"
74
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy, KeyPair } from "@polkadot-labs/hdkd-helpers"
85
import { getPolkadotSigner } from "polkadot-api/signer"
96
import { randomBytes } from 'crypto';
107
import { Keyring } from '@polkadot/keyring';
118
import { SS58_PREFIX, TX_TIMEOUT } from "./config";
129
import { getClient } from "./setup"
10+
1311
let api: TypedApi<typeof devnet> | undefined = undefined
1412

1513
// define url string as type to extend in the future
@@ -24,26 +22,36 @@ export async function getDevnetApi() {
2422
return api
2523
}
2624

27-
export function getAlice() {
25+
export function getKeypairFromPath(path: string) {
2826
const entropy = mnemonicToEntropy(DEV_PHRASE)
2927
const miniSecret = entropyToMiniSecret(entropy)
3028
const derive = sr25519CreateDerive(miniSecret)
31-
const hdkdKeyPair = derive("//Alice")
29+
const hdkdKeyPair = derive(path)
3230

3331
return hdkdKeyPair
3432
}
3533

36-
export function getAliceSigner() {
37-
const alice = getAlice()
34+
export const getAlice = () => getKeypairFromPath("//Alice")
35+
export const getBob = () => getKeypairFromPath("//Bob")
36+
export const getCharlie = () => getKeypairFromPath("//Charlie")
37+
export const getDave = () => getKeypairFromPath("//Dave")
38+
39+
export function getSignerFromPath(path: string) {
40+
const keypair = getKeypairFromPath(path)
3841
const polkadotSigner = getPolkadotSigner(
39-
alice.publicKey,
42+
keypair.publicKey,
4043
"Sr25519",
41-
alice.sign,
44+
keypair.sign,
4245
)
4346

4447
return polkadotSigner
4548
}
4649

50+
export const getAliceSigner = () => getSignerFromPath("//Alice")
51+
export const getBobSigner = () => getSignerFromPath("//Bob")
52+
export const getCharlieSigner = () => getSignerFromPath("//Charlie")
53+
export const getDaveSigner = () => getSignerFromPath("//Dave")
54+
4755
export function getRandomSubstrateSigner() {
4856
const keypair = getRandomSubstrateKeypair();
4957
return getSignerFromKeypair(keypair)

evm-tests/test/crowdloan.precompile.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ describe("Test Crowdloan precompile", () => {
3636

3737
it("gets an existing crowdloan created on substrate side", async () => {
3838
const nextId = await api.query.Crowdloan.NextCrowdloanId.getValue();
39+
const end = await api.query.System.Number.getValue() + 100;
3940

4041
await api.tx.Crowdloan.create({
4142
deposit: BigInt(15_000_000_000), // 15 TAO
4243
min_contribution: BigInt(1_000_000_000), // 1 TAO
4344
cap: BigInt(100_000_000_000), // 100 TAO
44-
end: 1000,
45+
end,
4546
target_address: undefined,
4647
call: api.tx.System.remark({ remark: Binary.fromText("foo") }).decodedCall
4748
}).signAndSubmit(alice);
@@ -110,12 +111,13 @@ describe("Test Crowdloan precompile", () => {
110111
it("contributes/withdraws to a crowdloan created on substrate side", async () => {
111112
const nextId = await api.query.Crowdloan.NextCrowdloanId.getValue();
112113
const deposit = BigInt(15_000_000_000); // 15 TAO
114+
const end = await api.query.System.Number.getValue() + 100;
113115

114116
await api.tx.Crowdloan.create({
115117
deposit,
116118
min_contribution: BigInt(1_000_000_000), // 1 TAO
117119
cap: BigInt(100_000_000_000), // 100 TAO
118-
end: 1000,
120+
end,
119121
target_address: undefined,
120122
call: api.tx.System.remark({ remark: Binary.fromText("foo") }).decodedCall
121123
}).signAndSubmit(alice);

0 commit comments

Comments
 (0)