Skip to content

Commit

Permalink
feat: liquidity pool swap
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Dec 16, 2023
1 parent 2445364 commit d9f7a4e
Show file tree
Hide file tree
Showing 29 changed files with 619 additions and 99 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[workspace]
members = ["src/did", "src/dip721", "src/deferred", "src/fly", "src/icrc"]
members = [
"src/did",
"src/dip721",
"src/deferred",
"src/fly",
"src/icrc",
"src/xrc",
]
resolver = "2"

[workspace.package]
Expand All @@ -20,6 +27,7 @@ ic-cdk = "0.11"
ic-cdk-macros = "0.8"
ic-cdk-timers = "0.5"
ic-stable-structures = "0.6"
ic-xrc-types = "=1.1"
icrc-ledger-types = "0.1"
itertools = "0.12"
num-bigint = "0.4"
Expand Down
26 changes: 25 additions & 1 deletion src/declarations/deferred/deferred.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ export interface DeferredInitData {
'marketplace_canister' : Principal,
}
export type FlyError = { 'Configuration' : ConfigurationError } |
{ 'Icrc1Transfer' : TransferError } |
{ 'Pool' : PoolError } |
{ 'Allowance' : AllowanceError } |
{ 'Register' : RegisterError } |
{ 'XrcError' : null } |
{ 'StorageError' : null } |
{ 'CanisterCall' : [RejectionCode, string] } |
{ 'Balance' : BalanceError };
{ 'Balance' : BalanceError } |
{ 'Icrc2Transfer' : TransferFromError };
export type GenericValue = { 'Nat64Content' : bigint } |
{ 'Nat32Content' : number } |
{ 'BoolContent' : boolean } |
Expand Down Expand Up @@ -164,6 +167,27 @@ export interface TokenMetadata {
'minted_at' : bigint,
'minted_by' : Principal,
}
export type TransferError = {
'GenericError' : { 'message' : string, 'error_code' : bigint }
} |
{ 'TemporarilyUnavailable' : null } |
{ 'BadBurn' : { 'min_burn_amount' : bigint } } |
{ 'Duplicate' : { 'duplicate_of' : bigint } } |
{ 'BadFee' : { 'expected_fee' : bigint } } |
{ 'CreatedInFuture' : { 'ledger_time' : bigint } } |
{ 'TooOld' : null } |
{ 'InsufficientFunds' : { 'balance' : bigint } };
export type TransferFromError = {
'GenericError' : { 'message' : string, 'error_code' : bigint }
} |
{ 'TemporarilyUnavailable' : null } |
{ 'InsufficientAllowance' : { 'allowance' : bigint } } |
{ 'BadBurn' : { 'min_burn_amount' : bigint } } |
{ 'Duplicate' : { 'duplicate_of' : bigint } } |
{ 'BadFee' : { 'expected_fee' : bigint } } |
{ 'CreatedInFuture' : { 'ledger_time' : bigint } } |
{ 'TooOld' : null } |
{ 'InsufficientFunds' : { 'balance' : bigint } };
export interface TxEvent {
'time' : bigint,
'operation' : string,
Expand Down
30 changes: 30 additions & 0 deletions src/declarations/deferred/deferred.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ export const idlFactory = ({ IDL }) => {
'AdminsCantBeEmpty' : IDL.Null,
'AnonymousAdmin' : IDL.Null,
});
const TransferError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const PoolError = IDL.Variant({
'PoolNotFound' : IDL.Nat,
'NotEnoughTokens' : IDL.Null,
Expand All @@ -36,14 +49,31 @@ export const idlFactory = ({ IDL }) => {
'AccountNotFound' : IDL.Null,
'InsufficientBalance' : IDL.Null,
});
const TransferFromError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'InsufficientAllowance' : IDL.Record({ 'allowance' : IDL.Nat }),
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const FlyError = IDL.Variant({
'Configuration' : ConfigurationError,
'Icrc1Transfer' : TransferError,
'Pool' : PoolError,
'Allowance' : AllowanceError,
'Register' : RegisterError,
'XrcError' : IDL.Null,
'StorageError' : IDL.Null,
'CanisterCall' : IDL.Tuple(RejectionCode, IDL.Text),
'Balance' : BalanceError,
'Icrc2Transfer' : TransferFromError,
});
const NftError = IDL.Variant({
'UnauthorizedOperator' : IDL.Null,
Expand Down
7 changes: 6 additions & 1 deletion src/declarations/fly/fly.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ export type BalanceError = { 'AccountNotFound' : null } |
export type ConfigurationError = { 'AdminsCantBeEmpty' : null } |
{ 'AnonymousAdmin' : null };
export type FlyError = { 'Configuration' : ConfigurationError } |
{ 'Icrc1Transfer' : TransferError } |
{ 'Pool' : PoolError } |
{ 'Allowance' : AllowanceError } |
{ 'Register' : RegisterError } |
{ 'XrcError' : null } |
{ 'StorageError' : null } |
{ 'CanisterCall' : [RejectionCode, string] } |
{ 'Balance' : BalanceError };
{ 'Balance' : BalanceError } |
{ 'Icrc2Transfer' : TransferFromError };
export interface FlyInitData {
'deferred_canister' : Principal,
'initial_balances' : Array<[Account, bigint]>,
'swap_account' : Account,
'marketplace_canister' : Principal,
'admins' : Array<Principal>,
'total_supply' : bigint,
Expand Down Expand Up @@ -143,6 +147,7 @@ export interface _SERVICE {
'admin_cycles' : ActorMethod<[], bigint>,
'admin_remove_role' : ActorMethod<[Principal, Role], Result>,
'admin_set_role' : ActorMethod<[Principal, Role], undefined>,
'admin_set_swap_account' : ActorMethod<[Account], undefined>,
'get_contract_reward' : ActorMethod<[bigint, bigint], Result_1>,
'get_transaction' : ActorMethod<[bigint], Result_2>,
'icrc1_balance_of' : ActorMethod<[Account], bigint>,
Expand Down
64 changes: 35 additions & 29 deletions src/declarations/fly/fly.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ export const idlFactory = ({ IDL }) => {
const FlyInitData = IDL.Record({
'deferred_canister' : IDL.Principal,
'initial_balances' : IDL.Vec(IDL.Tuple(Account, IDL.Nat)),
'swap_account' : Account,
'marketplace_canister' : IDL.Principal,
'admins' : IDL.Vec(IDL.Principal),
'total_supply' : IDL.Nat64,
'total_supply' : IDL.Nat,
});
const ConfigurationError = IDL.Variant({
'AdminsCantBeEmpty' : IDL.Null,
'AnonymousAdmin' : IDL.Null,
});
const TransferError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const PoolError = IDL.Variant({
'PoolNotFound' : IDL.Nat,
'NotEnoughTokens' : IDL.Null,
Expand All @@ -40,14 +54,31 @@ export const idlFactory = ({ IDL }) => {
'AccountNotFound' : IDL.Null,
'InsufficientBalance' : IDL.Null,
});
const TransferFromError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'InsufficientAllowance' : IDL.Record({ 'allowance' : IDL.Nat }),
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const FlyError = IDL.Variant({
'Configuration' : ConfigurationError,
'Icrc1Transfer' : TransferError,
'Pool' : PoolError,
'Allowance' : AllowanceError,
'Register' : RegisterError,
'XrcError' : IDL.Null,
'StorageError' : IDL.Null,
'CanisterCall' : IDL.Tuple(RejectionCode, IDL.Text),
'Balance' : BalanceError,
'Icrc2Transfer' : TransferFromError,
});
const Result = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : FlyError });
const Role = IDL.Variant({
Expand Down Expand Up @@ -80,19 +111,6 @@ export const idlFactory = ({ IDL }) => {
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
});
const TransferError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const Result_3 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TransferError });
const AllowanceArgs = IDL.Record({
'account' : Account,
Expand Down Expand Up @@ -136,20 +154,6 @@ export const idlFactory = ({ IDL }) => {
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
});
const TransferFromError = IDL.Variant({
'GenericError' : IDL.Record({
'message' : IDL.Text,
'error_code' : IDL.Nat,
}),
'TemporarilyUnavailable' : IDL.Null,
'InsufficientAllowance' : IDL.Record({ 'allowance' : IDL.Nat }),
'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
'TooOld' : IDL.Null,
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
});
const Result_5 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TransferFromError });
const LiquidityPoolAccounts = IDL.Record({
'icp' : IDL.Vec(IDL.Nat8),
Expand All @@ -168,6 +172,7 @@ export const idlFactory = ({ IDL }) => {
'admin_cycles' : IDL.Func([], [IDL.Nat], ['query']),
'admin_remove_role' : IDL.Func([IDL.Principal, Role], [Result], []),
'admin_set_role' : IDL.Func([IDL.Principal, Role], [], []),
'admin_set_swap_account' : IDL.Func([Account], [], []),
'get_contract_reward' : IDL.Func([IDL.Nat, IDL.Nat64], [Result_1], []),
'get_transaction' : IDL.Func([IDL.Nat64], [Result_2], ['query']),
'icrc1_balance_of' : IDL.Func([Account], [IDL.Nat], ['query']),
Expand Down Expand Up @@ -208,9 +213,10 @@ export const init = ({ IDL }) => {
const FlyInitData = IDL.Record({
'deferred_canister' : IDL.Principal,
'initial_balances' : IDL.Vec(IDL.Tuple(Account, IDL.Nat)),
'swap_account' : Account,
'marketplace_canister' : IDL.Principal,
'admins' : IDL.Vec(IDL.Principal),
'total_supply' : IDL.Nat64,
'total_supply' : IDL.Nat,
});
return [FlyInitData];
};
24 changes: 24 additions & 0 deletions src/deferred/deferred.did
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ type DeferredInitData = record {
};
type FlyError = variant {
Configuration : ConfigurationError;
Icrc1Transfer : TransferError;
Pool : PoolError;
Allowance : AllowanceError;
Register : RegisterError;
XrcError;
StorageError;
CanisterCall : record { RejectionCode; text };
Balance : BalanceError;
Icrc2Transfer : TransferFromError;
};
type GenericValue = variant {
Nat64Content : nat64;
Expand Down Expand Up @@ -160,6 +163,27 @@ type TokenMetadata = record {
minted_at : nat64;
minted_by : principal;
};
type TransferError = variant {
GenericError : record { message : text; error_code : nat };
TemporarilyUnavailable;
BadBurn : record { min_burn_amount : nat };
Duplicate : record { duplicate_of : nat };
BadFee : record { expected_fee : nat };
CreatedInFuture : record { ledger_time : nat64 };
TooOld;
InsufficientFunds : record { balance : nat };
};
type TransferFromError = variant {
GenericError : record { message : text; error_code : nat };
TemporarilyUnavailable;
InsufficientAllowance : record { allowance : nat };
BadBurn : record { min_burn_amount : nat };
Duplicate : record { duplicate_of : nat };
BadFee : record { expected_fee : nat };
CreatedInFuture : record { ledger_time : nat64 };
TooOld;
InsufficientFunds : record { balance : nat };
};
type TxEvent = record {
time : nat64;
operation : text;
Expand Down
1 change: 1 addition & 0 deletions src/did/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ icrc = { path = "../icrc" }
num-bigint = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
xrc = { path = "../xrc" }

[dev-dependencies]
pretty_assertions = "1"
Loading

0 comments on commit d9f7a4e

Please sign in to comment.