-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
369 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule garden
updated
23 files
+1 −1 | backend/actors.mo | |
+21 −9 | backend/garden.mo | |
+5 −1 | backend/main.mo | |
+5 −1 | backend/types.mo | |
+8 −0 | canister_ids.json | |
+1 −1 | declarations/icrc1/initArgs.did | |
+7 −2 | declarations/main/main.did | |
+7 −2 | declarations/main/main.did.d.ts | |
+12 −3 | declarations/main/main.did.js | |
+12 −2 | dfx.json | |
+1 −1 | frontend/components/DisburseModal.svelte | |
+1 −1 | frontend/components/DissolveModal.svelte | |
+4 −3 | frontend/components/Garden.svelte | |
+1 −1 | frontend/components/RestakeModal.svelte | |
+1 −1 | frontend/components/StakedFlower.svelte | |
+1 −1 | frontend/components/WithdrawModal.svelte | |
+1 −2 | frontend/package.json | |
+5 −1 | initArgs.ic.did | |
+7 −3 | initArgs.local.did | |
+1 −0 | package-lock.json | |
+4 −3 | package.json | |
+33 −25 | test/stake.test.ts | |
+10 −5 | test/utils.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { | ||
ActorSubclass, | ||
HttpAgentOptions, | ||
ActorConfig, | ||
Agent, | ||
} from "@dfinity/agent"; | ||
import type { Principal } from "@dfinity/principal"; | ||
import type { IDL } from "@dfinity/candid"; | ||
|
||
import { _SERVICE } from './main.did'; | ||
|
||
export declare const idlFactory: IDL.InterfaceFactory; | ||
export declare const canisterId: string; | ||
|
||
export declare interface CreateActorOptions { | ||
/** | ||
* @see {@link Agent} | ||
*/ | ||
agent?: Agent; | ||
/** | ||
* @see {@link HttpAgentOptions} | ||
*/ | ||
agentOptions?: HttpAgentOptions; | ||
/** | ||
* @see {@link ActorConfig} | ||
*/ | ||
actorOptions?: ActorConfig; | ||
} | ||
|
||
/** | ||
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. | ||
* @constructs {@link ActorSubClass} | ||
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to | ||
* @param {CreateActorOptions} options - see {@link CreateActorOptions} | ||
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions | ||
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent | ||
* @see {@link HttpAgentOptions} | ||
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor | ||
* @see {@link ActorConfig} | ||
*/ | ||
export declare const createActor: ( | ||
canisterId: string | Principal, | ||
options?: CreateActorOptions | ||
) => ActorSubclass<_SERVICE>; | ||
|
||
/** | ||
* Intialized Actor using default settings, ready to talk to a canister using its candid interface | ||
* @constructs {@link ActorSubClass} | ||
*/ | ||
export declare const main: ActorSubclass<_SERVICE>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Actor, HttpAgent } from "@dfinity/agent"; | ||
|
||
// Imports and re-exports candid interface | ||
import { idlFactory } from "./main.did.js"; | ||
export { idlFactory } from "./main.did.js"; | ||
|
||
/* CANISTER_ID is replaced by webpack based on node environment | ||
* Note: canister environment variable will be standardized as | ||
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE> | ||
* beginning in dfx 0.15.0 | ||
*/ | ||
export const canisterId = | ||
process.env.CANISTER_ID_GARDEN || | ||
process.env.GARDEN_CANISTER_ID; | ||
|
||
export const createActor = (canisterId, options = {}) => { | ||
const agent = options.agent || new HttpAgent({ ...options.agentOptions }); | ||
|
||
if (options.agent && options.agentOptions) { | ||
console.warn( | ||
"Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." | ||
); | ||
} | ||
|
||
// Fetch root key for certificate validation during development | ||
if (process.env.DFX_NETWORK !== "ic") { | ||
agent.fetchRootKey().catch((err) => { | ||
console.warn( | ||
"Unable to fetch root key. Check to ensure that your local replica is running" | ||
); | ||
console.error(err); | ||
}); | ||
} | ||
|
||
// Creates an actor with using the candid interface and the HttpAgent | ||
return Actor.createActor(idlFactory, { | ||
agent, | ||
canisterId, | ||
...options.actorOptions, | ||
}); | ||
}; | ||
|
||
/** | ||
* A ready-to-use agent for the garden canister | ||
* @type {import("@dfinity/agent").ActorSubclass<import("./main.did.js")._SERVICE>} | ||
*/ | ||
export const main = createActor(canisterId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
type anon_class_10_1 = | ||
service { | ||
claimRewards: (NeuronId, Account) -> (Result_1); | ||
disburseNeuron: (NeuronId, Account) -> (Result_1); | ||
dissolveNeuron: (NeuronId) -> (Result_1); | ||
getCallerNeurons: () -> (vec Neuron) query; | ||
getStakingAccount: (nat16) -> (Account) query; | ||
getUserVotingPower: (principal) -> (nat) query; | ||
restake: (NeuronId) -> (Result_1); | ||
stake: (nat16) -> (Result); | ||
}; | ||
type TokenIndex = nat; | ||
type Time = int; | ||
type Result_1 = | ||
variant { | ||
err: text; | ||
ok; | ||
}; | ||
type Result = | ||
variant { | ||
err: text; | ||
ok: NeuronId; | ||
}; | ||
type NeuronId = nat; | ||
type Neuron = | ||
record { | ||
createdAt: Time; | ||
dissolveState: DissolveState; | ||
flowers: vec Flower; | ||
id: nat; | ||
prevRewardTime: Time; | ||
rewards: nat; | ||
stakedAt: Time; | ||
stakingAccount: Account; | ||
totalRewards: nat; | ||
userId: principal; | ||
}; | ||
type InitArgs = | ||
record { | ||
dailyRewards: record { | ||
btcFlower: nat; | ||
ethFlower: nat; | ||
icpFlower: nat; | ||
}; | ||
rewardInterval: Duration; | ||
stakePeriod: Duration; | ||
}; | ||
type Flower = | ||
record { | ||
collection: Collection; | ||
tokenIndex: TokenIndex; | ||
}; | ||
type Duration = | ||
variant { | ||
days: nat; | ||
hours: nat; | ||
minutes: nat; | ||
nanoseconds: nat; | ||
seconds: nat; | ||
}; | ||
type DissolveState = | ||
variant { | ||
DissolveDelay: Time; | ||
DissolveTimestamp: Time; | ||
}; | ||
type Collection = | ||
variant { | ||
BTCFlower; | ||
ETHFlower; | ||
ICPFlower; | ||
}; | ||
type Account = | ||
record { | ||
owner: principal; | ||
subaccount: opt vec nat8; | ||
}; | ||
service : (principal, InitArgs) -> anon_class_10_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { Principal } from '@dfinity/principal'; | ||
import type { ActorMethod } from '@dfinity/agent'; | ||
|
||
export interface Account { | ||
'owner' : Principal, | ||
'subaccount' : [] | [Uint8Array | number[]], | ||
} | ||
export type Collection = { 'BTCFlower' : null } | | ||
{ 'ICPFlower' : null } | | ||
{ 'ETHFlower' : null }; | ||
export type DissolveState = { 'DissolveDelay' : Time } | | ||
{ 'DissolveTimestamp' : Time }; | ||
export type Duration = { 'nanoseconds' : bigint } | | ||
{ 'hours' : bigint } | | ||
{ 'days' : bigint } | | ||
{ 'minutes' : bigint } | | ||
{ 'seconds' : bigint }; | ||
export interface Flower { 'collection' : Collection, 'tokenIndex' : TokenIndex } | ||
export interface InitArgs { | ||
'rewardInterval' : Duration, | ||
'stakePeriod' : Duration, | ||
'dailyRewards' : { | ||
'btcFlower' : bigint, | ||
'icpFlower' : bigint, | ||
'ethFlower' : bigint, | ||
}, | ||
} | ||
export interface Neuron { | ||
'id' : bigint, | ||
'prevRewardTime' : Time, | ||
'stakedAt' : Time, | ||
'userId' : Principal, | ||
'createdAt' : Time, | ||
'totalRewards' : bigint, | ||
'rewards' : bigint, | ||
'dissolveState' : DissolveState, | ||
'stakingAccount' : Account, | ||
'flowers' : Array<Flower>, | ||
} | ||
export type NeuronId = bigint; | ||
export type Result = { 'ok' : NeuronId } | | ||
{ 'err' : string }; | ||
export type Result_1 = { 'ok' : null } | | ||
{ 'err' : string }; | ||
export type Time = bigint; | ||
export type TokenIndex = bigint; | ||
export interface anon_class_10_1 { | ||
'claimRewards' : ActorMethod<[NeuronId, Account], Result_1>, | ||
'disburseNeuron' : ActorMethod<[NeuronId, Account], Result_1>, | ||
'dissolveNeuron' : ActorMethod<[NeuronId], Result_1>, | ||
'getCallerNeurons' : ActorMethod<[], Array<Neuron>>, | ||
'getStakingAccount' : ActorMethod<[number], Account>, | ||
'getUserVotingPower' : ActorMethod<[Principal], bigint>, | ||
'restake' : ActorMethod<[NeuronId], Result_1>, | ||
'stake' : ActorMethod<[number], Result>, | ||
} | ||
export interface _SERVICE extends anon_class_10_1 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
export const idlFactory = ({ IDL }) => { | ||
const Duration = IDL.Variant({ | ||
'nanoseconds' : IDL.Nat, | ||
'hours' : IDL.Nat, | ||
'days' : IDL.Nat, | ||
'minutes' : IDL.Nat, | ||
'seconds' : IDL.Nat, | ||
}); | ||
const InitArgs = IDL.Record({ | ||
'rewardInterval' : Duration, | ||
'stakePeriod' : Duration, | ||
'dailyRewards' : IDL.Record({ | ||
'btcFlower' : IDL.Nat, | ||
'icpFlower' : IDL.Nat, | ||
'ethFlower' : IDL.Nat, | ||
}), | ||
}); | ||
const NeuronId = IDL.Nat; | ||
const Account = IDL.Record({ | ||
'owner' : IDL.Principal, | ||
'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), | ||
}); | ||
const Result_1 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text }); | ||
const Time = IDL.Int; | ||
const DissolveState = IDL.Variant({ | ||
'DissolveDelay' : Time, | ||
'DissolveTimestamp' : Time, | ||
}); | ||
const Collection = IDL.Variant({ | ||
'BTCFlower' : IDL.Null, | ||
'ICPFlower' : IDL.Null, | ||
'ETHFlower' : IDL.Null, | ||
}); | ||
const TokenIndex = IDL.Nat; | ||
const Flower = IDL.Record({ | ||
'collection' : Collection, | ||
'tokenIndex' : TokenIndex, | ||
}); | ||
const Neuron = IDL.Record({ | ||
'id' : IDL.Nat, | ||
'prevRewardTime' : Time, | ||
'stakedAt' : Time, | ||
'userId' : IDL.Principal, | ||
'createdAt' : Time, | ||
'totalRewards' : IDL.Nat, | ||
'rewards' : IDL.Nat, | ||
'dissolveState' : DissolveState, | ||
'stakingAccount' : Account, | ||
'flowers' : IDL.Vec(Flower), | ||
}); | ||
const Result = IDL.Variant({ 'ok' : NeuronId, 'err' : IDL.Text }); | ||
const anon_class_10_1 = IDL.Service({ | ||
'claimRewards' : IDL.Func([NeuronId, Account], [Result_1], []), | ||
'disburseNeuron' : IDL.Func([NeuronId, Account], [Result_1], []), | ||
'dissolveNeuron' : IDL.Func([NeuronId], [Result_1], []), | ||
'getCallerNeurons' : IDL.Func([], [IDL.Vec(Neuron)], ['query']), | ||
'getStakingAccount' : IDL.Func([IDL.Nat16], [Account], ['query']), | ||
'getUserVotingPower' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), | ||
'restake' : IDL.Func([NeuronId], [Result_1], []), | ||
'stake' : IDL.Func([IDL.Nat16], [Result], []), | ||
}); | ||
return anon_class_10_1; | ||
}; | ||
export const init = ({ IDL }) => { | ||
const Duration = IDL.Variant({ | ||
'nanoseconds' : IDL.Nat, | ||
'hours' : IDL.Nat, | ||
'days' : IDL.Nat, | ||
'minutes' : IDL.Nat, | ||
'seconds' : IDL.Nat, | ||
}); | ||
const InitArgs = IDL.Record({ | ||
'rewardInterval' : Duration, | ||
'stakePeriod' : Duration, | ||
'dailyRewards' : IDL.Record({ | ||
'btcFlower' : IDL.Nat, | ||
'icpFlower' : IDL.Nat, | ||
'ethFlower' : IDL.Nat, | ||
}), | ||
}); | ||
return [IDL.Principal, InitArgs]; | ||
}; |
Oops, something went wrong.